Add strutils::iequals helper
Replaces another boost method
This commit is contained in:
@@ -623,6 +623,22 @@ namespace simgear {
|
||||
*p = tolower(*p);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool iequals(const std::string& a, const std::string& b)
|
||||
{
|
||||
const auto lenA = a.length();
|
||||
const auto lenB = b.length();
|
||||
if (lenA != lenB) return false;
|
||||
|
||||
const char* aPtr = a.data();
|
||||
const char* bPtr = b.data();
|
||||
for (size_t i = 0; i < lenA; ++i) {
|
||||
if (tolower(*aPtr++) != tolower(*bPtr++)) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(SG_WINDOWS)
|
||||
static std::wstring convertMultiByteToWString(DWORD encoding, const std::string& a)
|
||||
|
||||
@@ -264,6 +264,11 @@ namespace simgear {
|
||||
*/
|
||||
void lowercase(std::string &s);
|
||||
|
||||
/**
|
||||
* case-insensitive string comparisom
|
||||
*/
|
||||
bool iequals(const std::string& a, const std::string& b);
|
||||
|
||||
/**
|
||||
* convert a string in the local Windows 8-bit encoding to UTF-8
|
||||
* (no-op on other platforms)
|
||||
|
||||
@@ -99,6 +99,16 @@ void test_to_int()
|
||||
SG_CHECK_EQUAL(strutils::to_int("-10000"), -10000);
|
||||
}
|
||||
|
||||
void test_iequals()
|
||||
{
|
||||
SG_VERIFY(strutils::iequals("abcdef", "AbCDeF"));
|
||||
SG_VERIFY(strutils::iequals("", ""));
|
||||
SG_VERIFY(!strutils::iequals("abcdE", "ABCD"));
|
||||
SG_VERIFY(strutils::iequals("%$abcdef12", "%$AbCDeF12"));
|
||||
SG_VERIFY(strutils::iequals("VOR-DME", "vor-dme"));
|
||||
SG_VERIFY(!strutils::iequals("VOR-DME", "vor_dme"));
|
||||
}
|
||||
|
||||
// Auxiliary function for test_readNonNegativeInt()
|
||||
void aux_readNonNegativeInt_setUpOStringStream(std::ostringstream& oss, int base)
|
||||
{
|
||||
@@ -737,6 +747,7 @@ int main(int argc, char* argv[])
|
||||
test_utf8Convert();
|
||||
test_parseGeod();
|
||||
test_formatGeod();
|
||||
test_iequals();
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user