MCPcopy Create free account
hub / github.com/Apress/beginning-cpp20 / from_roman

Function from_roman

Examples/Modules/Chapter 11/Ex11_05/from_roman.cpp:5–15  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3import :internals;
4
5unsigned 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}

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected