diff options
author | Michael Drake <Michael Drake tlsa@netsurf-browser.org> | 2019-05-05 18:06:05 +0100 |
---|---|---|
committer | Michael Drake <Michael Drake tlsa@netsurf-browser.org> | 2019-05-05 18:06:05 +0100 |
commit | 229f2a85386784fc3ebcab31ee6bd660d0954462 (patch) | |
tree | 90e304fe20ec6fab533a083d9c34d70a802ee198 | |
parent | 6a8cdf2e4b0fcd7dd72028cafe701dffd6dd0f7e (diff) | |
download | libcss-229f2a85386784fc3ebcab31ee6bd660d0954462.tar.gz libcss-229f2a85386784fc3ebcab31ee6bd660d0954462.tar.bz2 |
Media queries: Parse: Convert level 3 style ranges to level 4.
This will make the selection code's life easier.
-rw-r--r-- | src/parse/mq.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/parse/mq.c b/src/parse/mq.c index 7f8646c..76d00f9 100644 --- a/src/parse/mq.c +++ b/src/parse/mq.c @@ -212,6 +212,57 @@ static css_error mq_parse_op(const css_token *token, return CSS_OK; } + +/** + * Convert level 3 ranged descriptors into level 4 style. + * + * Helper for \ref mq_parse_range(). + * + * \param[in] feature Range feature to convert. + * \return CSS_OK, or error code. + * + * This detects the min- and max- prefixes, strips them, and converts + * the operator. + */ +static css_error mq_parse_range__convert_to_level_4( + css_mq_feature *feature) +{ + lwc_string *new_name; + const char *name = lwc_string_data(feature->name); + + if (feature->op != CSS_MQ_FEATURE_OP_EQ || + lwc_string_length(feature->name) <= 4) { + return CSS_OK; + } + + if (name[0] == 'm' && name[3] == '-') { + if (name[1] == 'i' && name[2] == 'n') { + if (lwc_intern_substring(feature->name, + 4, lwc_string_length(feature->name) - 4, + &new_name) != lwc_error_ok) { + return CSS_NOMEM; + } + lwc_string_unref(feature->name); + feature->name = new_name; + + feature->op = CSS_MQ_FEATURE_OP_GTE; + + } else if (name[1] == 'a' && name[2] == 'x') { + if (lwc_intern_substring(feature->name, + 4, lwc_string_length(feature->name) - 4, + &new_name) != lwc_error_ok) { + return CSS_NOMEM; + } + lwc_string_unref(feature->name); + feature->name = new_name; + + feature->op = CSS_MQ_FEATURE_OP_LTE; + } + } + + return CSS_OK; +} + static css_error mq_parse_range(lwc_string **strings, const parserutils_vector *vector, int *ctx, const css_token *name_or_value, @@ -390,6 +441,12 @@ static css_error mq_parse_range(lwc_string **strings, } } + error = mq_parse_range__convert_to_level_4(result); + if (error != CSS_OK) { + css__mq_feature_destroy(result); + return error; + } + *feature = result; return CSS_OK; |