| 17 | } |
| 18 | |
| 19 | litehtml::media_query::ptr litehtml::media_query::create_from_string(const tstring& str, const std::shared_ptr<document>& doc) |
| 20 | { |
| 21 | media_query::ptr query = std::make_shared<media_query>(); |
| 22 | |
| 23 | string_vector tokens; |
| 24 | split_string(str, tokens, _t(" \t\r\n"), _t(""), _t("(")); |
| 25 | |
| 26 | for(string_vector::iterator tok = tokens.begin(); tok != tokens.end(); tok++) |
| 27 | { |
| 28 | if((*tok) == _t("not")) |
| 29 | { |
| 30 | query->m_not = true; |
| 31 | } else if(tok->at(0) == _t('(')) |
| 32 | { |
| 33 | tok->erase(0, 1); |
| 34 | if(tok->at(tok->length() - 1) == _t(')')) |
| 35 | { |
| 36 | tok->erase(tok->length() - 1, 1); |
| 37 | } |
| 38 | media_query_expression expr; |
| 39 | string_vector expr_tokens; |
| 40 | split_string((*tok), expr_tokens, _t(":")); |
| 41 | if(!expr_tokens.empty()) |
| 42 | { |
| 43 | trim(expr_tokens[0]); |
| 44 | expr.feature = (media_feature) value_index(expr_tokens[0], media_feature_strings, media_feature_none); |
| 45 | if(expr.feature != media_feature_none) |
| 46 | { |
| 47 | if(expr_tokens.size() == 1) |
| 48 | { |
| 49 | expr.check_as_bool = true; |
| 50 | } else |
| 51 | { |
| 52 | trim(expr_tokens[1]); |
| 53 | expr.check_as_bool = false; |
| 54 | if(expr.feature == media_feature_orientation) |
| 55 | { |
| 56 | expr.val = value_index(expr_tokens[1], media_orientation_strings, media_orientation_landscape); |
| 57 | } else |
| 58 | { |
| 59 | tstring::size_type slash_pos = expr_tokens[1].find(_t('/')); |
| 60 | if( slash_pos != tstring::npos ) |
| 61 | { |
| 62 | tstring val1 = expr_tokens[1].substr(0, slash_pos); |
| 63 | tstring val2 = expr_tokens[1].substr(slash_pos + 1); |
| 64 | trim(val1); |
| 65 | trim(val2); |
| 66 | expr.val = t_atoi(val1.c_str()); |
| 67 | expr.val2 = t_atoi(val2.c_str()); |
| 68 | } else |
| 69 | { |
| 70 | css_length length; |
| 71 | length.fromString(expr_tokens[1]); |
| 72 | if(length.units() == css_units_dpcm) |
| 73 | { |
| 74 | expr.val = (int) (length.val() * 2.54); |
| 75 | } else if(length.units() == css_units_dpi) |
| 76 | { |
nothing calls this directly
no test coverage detected