| 638 | } |
| 639 | |
| 640 | std::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 | |
| 680 | std::string convertToStandardForm(const std::string& unitString) { |
| 681 | std::string result(unitString); |