Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auto GUI::XHTMLDisplayer::parseValue(const std::string& value)
- -> CSSValue
- {
- // this regex should match any individual value
- static const std::regex regexIndivValue("^(.+?(\\(.*?\\)|\\\".*?\\\")*)(\\s+|,|$)"); // TODO: not perfect, eg. doesn't take into account nested parentheses
- // building the value
- CSSValue retValue;
- retValue.important = false;
- retValue.specificity[0] = retValue.specificity[1] = retValue.specificity[2] = retValue.specificity[3] = 0;
- retValue.values.resize(1);
- // iterating through the string, jumping from regex match to regex match
- std::smatch matchResults;
- for (auto i = value.begin(); i != value.end() && std::regex_search(i, value.end(), matchResults, regexIndivValue); i = matchResults[0].second) {
- if (matchResults[3].matched && matchResults[3].first != value.end() && *matchResults[3].first == ',')
- retValue.values.resize(retValue.values.size() + 1);
- try { retValue.values.back().push_back(parseIndividualValue(matchResults[1].str())); } catch(...) {} // TODO: remove try-catch
- }
- // we finished, returning
- assert(retValue.values.size() >= 1 || value.empty());
- return retValue;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement