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

Function decomposeScaledUnitString

src/utilities/units/QuantityRegex.cpp:310–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

308}
309
310std::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
337std::pair<std::vector<std::string>, std::vector<std::string>> decomposeCompoundUnitString(const std::string& s) {
338

Callers 3

createUnitMethod · 0.85
parseUnitStringFunction · 0.85
TEST_FFunction · 0.85

Calls 1

isScaledUnitFunction · 0.85

Tested by 1

TEST_FFunction · 0.68