MCPcopy Create free account
hub / github.com/OpenLoco/OpenLoco / parseNextNumber

Function parseNextNumber

src/Utility/src/String.cpp:26–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24 }
25
26 static std::pair<int32_t, std::string_view> parseNextNumber(std::string_view s)
27 {
28 int32_t num = 0;
29 while (!s.empty())
30 {
31 if (s[0] != '.' && s[0] != ',')
32 {
33 if (!isdigit(s[0]))
34 {
35 break;
36 }
37
38 auto newResult = num * 10;
39 if (newResult / 10 != num)
40 {
41 return { std::numeric_limits<int32_t>::max(), skipDigits(s) };
42 }
43 num = newResult + (s[0] - '0');
44 if (num < newResult)
45 {
46 return { std::numeric_limits<int32_t>::max(), skipDigits(s) };
47 }
48 }
49 s = s.substr(1);
50 }
51 return { num, s };
52 }
53
54 // Case-insensitive logical string comparison function
55 int32_t strlogicalcmp(std::string_view s1, std::string_view s2)

Callers 1

strlogicalcmpFunction · 0.85

Calls 2

skipDigitsFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected