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

Function strlogicalcmp

src/Utility/src/String.cpp:55–96  ·  view source on GitHub ↗

Case-insensitive logical string comparison function

Source from the content-addressed store, hash-verified

53
54 // Case-insensitive logical string comparison function
55 int32_t strlogicalcmp(std::string_view s1, std::string_view s2)
56 {
57 for (;;)
58 {
59 if (s2.empty())
60 {
61 return !s1.empty();
62 }
63 else if (s1.empty())
64 {
65 return -1;
66 }
67 else if (!(isdigit(s1[0]) && isdigit(s2[0])))
68 {
69 if (toupper(s1[0]) != toupper(s2[0]))
70 {
71 return toupper(s1[0]) - toupper(s2[0]);
72 }
73 else
74 {
75 s1 = s1.substr(1);
76 s2 = s2.substr(1);
77 }
78 }
79 else
80 {
81 // TODO: Replace with std::from_chars when all compilers support std::from_chars
82 auto [n1, s1n] = parseNextNumber(s1);
83 auto [n2, s2n] = parseNextNumber(s2);
84 if (n1 > n2)
85 {
86 return 1;
87 }
88 else if (n1 < n2)
89 {
90 return -1;
91 }
92 s1 = s1n;
93 s2 = s2n;
94 }
95 }
96 }
97
98 std::string toUtf8(const std::wstring_view& src)
99 {

Callers 2

orderByNameFunction · 0.85
orderByNameFunction · 0.85

Calls 2

parseNextNumberFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected