| 3 | import :internals; |
| 4 | |
| 5 | unsigned int from_roman(std::string_view roman) |
| 6 | { |
| 7 | unsigned int result{}; |
| 8 | for (size_t i{}, n{ roman.length() }; i < n; ++i) |
| 9 | { |
| 10 | const auto j{ from_roman(roman[i]) }; // Integer value of the i'th roman digit |
| 11 | // Look at the next digit (if there is one) to know whether to add or subtract j |
| 12 | if (i + 1 == n || j >= from_roman(roman[i + 1])) result += j; else result -= j; |
| 13 | } |
| 14 | return result; |
| 15 | } |