| 386 | } |
| 387 | |
| 388 | std::pair<std::string, int> decomposeAtomicUnitString(const std::string& s) { |
| 389 | |
| 390 | if (!isAtomicUnit(s)) { |
| 391 | LOG_FREE_AND_THROW("openstudio.QuantityRegex", "Cannot decompose " << s << " into a base unit and exponent because it is not an atomic unit."); |
| 392 | } |
| 393 | |
| 394 | std::pair<std::string, int> result; |
| 395 | boost::smatch match; |
| 396 | |
| 397 | boost::regex_search(s, match, regexBaseUnit()); |
| 398 | |
| 399 | // First is the baseUnit (match[0].first is the start of sequence that matched, match[0].second is the end of sequence) |
| 400 | result.first = std::string(match[0].first, match[0].second); |
| 401 | // Match an exponent and put that in result.second |
| 402 | if (boost::regex_search(s, match, regexExponent())) { |
| 403 | // We want the submatch (capturing group) |
| 404 | std::istringstream iss(match[1]); |
| 405 | iss >> result.second; |
| 406 | } else { |
| 407 | result.second = 1; |
| 408 | } |
| 409 | |
| 410 | return result; |
| 411 | } |
| 412 | |
| 413 | } // namespace openstudio |