Advertisement
Guest User

Untitled

a guest
Apr 10th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. auto GUI::XHTMLDisplayer::parseValue(const std::string& value)
  2.     -> CSSValue
  3. {  
  4.     // this regex should match any individual value
  5.     static const std::regex regexIndivValue("^(.+?(\\(.*?\\)|\\\".*?\\\")*)(\\s+|,|$)");        // TODO: not perfect, eg. doesn't take into account nested parentheses
  6.  
  7.     // building the value
  8.     CSSValue retValue;
  9.     retValue.important = false;
  10.     retValue.specificity[0] = retValue.specificity[1] = retValue.specificity[2] = retValue.specificity[3] = 0;
  11.     retValue.values.resize(1);
  12.  
  13.     // iterating through the string, jumping from regex match to regex match
  14.     std::smatch matchResults;
  15.     for (auto i = value.begin(); i != value.end() && std::regex_search(i, value.end(), matchResults, regexIndivValue); i = matchResults[0].second) {
  16.         if (matchResults[3].matched && matchResults[3].first != value.end() && *matchResults[3].first == ',')
  17.             retValue.values.resize(retValue.values.size() + 1);
  18.         try { retValue.values.back().push_back(parseIndividualValue(matchResults[1].str())); } catch(...) {}        // TODO: remove try-catch
  19.     }
  20.  
  21.     // we finished, returning
  22.     assert(retValue.values.size() >= 1 || value.empty());
  23.     return retValue;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement