MCPcopy Create free account
hub / github.com/NatLabRockies/OpenStudio / decomposeAtomicUnitString

Function decomposeAtomicUnitString

src/utilities/units/QuantityRegex.cpp:388–411  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386}
387
388std::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

Callers 3

createUnitMethod · 0.85
parseUnitStringFunction · 0.85
TEST_FFunction · 0.85

Calls 1

isAtomicUnitFunction · 0.85

Tested by 1

TEST_FFunction · 0.68