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

Function extractUnitString

src/utilities/units/UnitFactory.cpp:640–678  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

638}
639
640std::string extractUnitString(const std::string& text) {
641 boost::smatch m;
642 std::string wtext(text);
643 std::string result;
644
645 // first handle people/100 m^2
646 if (boost::regex_search(wtext, m, regexEmbeddedDirectScaledUnit())) {
647 // main match at 1, 5, 9, or 13
648 for (unsigned i = 1; i < 14; i += 4) {
649 result = std::string(m[i].first, m[i].second);
650 if (!result.empty()) {
651 return result;
652 }
653 }
654 }
655
656 std::string::const_iterator wbegin = wtext.begin();
657 std::string::const_iterator wend = wtext.end();
658
659 while (boost::regex_search(wbegin, wend, m, regexEmbeddedUnit())) {
660 unsigned i = 1;
661 result = std::string(m[i].first, m[i].second);
662 while (result.empty()) {
663 ++i;
664 if (i < m.size()) {
665 result = std::string(m[i].first, m[i].second);
666 } else {
667 break;
668 }
669 }
670 if (containsRegisteredBaseUnit(result)) {
671 break;
672 }
673 result.clear();
674 wbegin = m[0].second;
675 }
676
677 return result;
678}
679
680std::string convertToStandardForm(const std::string& unitString) {
681 std::string result(unitString);

Callers 2

replaceUnitStringFunction · 0.85
TEST_FFunction · 0.85

Calls 6

beginMethod · 0.80
emptyMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45
clearMethod · 0.45

Tested by 1

TEST_FFunction · 0.68