| 308 | } |
| 309 | |
| 310 | std::pair<std::string, std::string> decomposeScaledUnitString(const std::string& s) { |
| 311 | if (!isScaledUnit(s)) { |
| 312 | LOG_FREE_AND_THROW("openstudio.QuantityRegex", "Cannot decompose " << s << " into a scale and a compound unit because it is not a scaled unit."); |
| 313 | } |
| 314 | |
| 315 | std::pair<std::string, std::string> result; |
| 316 | boost::match_results<std::string::const_iterator> match; |
| 317 | boost::regex scaleRegex("(\\\\?[\\l\\u]{1,5})\\("); |
| 318 | // pull out scale |
| 319 | if (!boost::regex_search(s, match, scaleRegex, boost::match_continuous)) { |
| 320 | LOG_FREE_AND_THROW("openstudio.QuantityRegex", "Could not extract a scale from the scaled unit " << s << "."); |
| 321 | } |
| 322 | result.first = std::string(match[1].first, match[1].second); |
| 323 | |
| 324 | // pull out compound unit |
| 325 | if (!boost::regex_search(s, match, regexEmbeddedCompoundUnit())) { |
| 326 | LOG_FREE_AND_THROW("openstudio.QuantityRegex", "Could not extract a compound unit from " << s << "."); |
| 327 | } |
| 328 | int i = 1; |
| 329 | while (!match[i].matched) { |
| 330 | ++i; |
| 331 | } |
| 332 | result.second = std::string(match[1].first, match[1].second); |
| 333 | |
| 334 | return result; |
| 335 | } |
| 336 | |
| 337 | std::pair<std::vector<std::string>, std::vector<std::string>> decomposeCompoundUnitString(const std::string& s) { |
| 338 | |