mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 14:27:35 +00:00
AKString: add missing comparison operators
And some trivial tests.
This commit is contained in:
parent
26956db5ac
commit
c3ecf753b2
2 changed files with 31 additions and 0 deletions
22
AK/AKString.h
Normal file → Executable file
22
AK/AKString.h
Normal file → Executable file
|
@ -131,11 +131,17 @@ public:
|
||||||
|
|
||||||
bool operator==(const String&) const;
|
bool operator==(const String&) const;
|
||||||
bool operator!=(const String& other) const { return !(*this == other); }
|
bool operator!=(const String& other) const { return !(*this == other); }
|
||||||
|
|
||||||
bool operator<(const String&) const;
|
bool operator<(const String&) const;
|
||||||
bool operator<(const char*) const;
|
bool operator<(const char*) const;
|
||||||
bool operator>=(const String& other) const { return !(*this < other); }
|
bool operator>=(const String& other) const { return !(*this < other); }
|
||||||
bool operator>=(const char* other) const { return !(*this < other); }
|
bool operator>=(const char* other) const { return !(*this < other); }
|
||||||
|
|
||||||
|
bool operator>(const String&) const;
|
||||||
|
bool operator>(const char*) const;
|
||||||
|
bool operator<=(const String& other) const { return !(*this > other); }
|
||||||
|
bool operator<=(const char* other) const { return !(*this > other); }
|
||||||
|
|
||||||
bool operator==(const char* cstring) const
|
bool operator==(const char* cstring) const
|
||||||
{
|
{
|
||||||
if (is_null())
|
if (is_null())
|
||||||
|
@ -229,6 +235,22 @@ inline bool operator>=(const char* characters, const String& string)
|
||||||
return !(characters < string);
|
return !(characters < string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline bool operator>(const char* characters, const String& string)
|
||||||
|
{
|
||||||
|
if (!characters)
|
||||||
|
return !string.is_null();
|
||||||
|
|
||||||
|
if (string.is_null())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return strcmp(characters, string.characters()) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool operator<=(const char* characters, const String& string)
|
||||||
|
{
|
||||||
|
return !(characters > string);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
using AK::String;
|
using AK::String;
|
||||||
|
|
9
AK/Tests/TestString.cpp
Normal file → Executable file
9
AK/Tests/TestString.cpp
Normal file → Executable file
|
@ -25,6 +25,15 @@ int main()
|
||||||
EXPECT(test_string != "ABCDE");
|
EXPECT(test_string != "ABCDE");
|
||||||
EXPECT(test_string != "ABCDEFG");
|
EXPECT(test_string != "ABCDEFG");
|
||||||
|
|
||||||
|
EXPECT("a" < String("b"));
|
||||||
|
EXPECT(!("a" > String("b")));
|
||||||
|
EXPECT("b" > String("a"));
|
||||||
|
EXPECT(!("b" < String("b")));
|
||||||
|
EXPECT("a" >= String("a"));
|
||||||
|
EXPECT(!("a" >= String("b")));
|
||||||
|
EXPECT("a" <= String("a"));
|
||||||
|
EXPECT(!("b" <= String("a")));
|
||||||
|
|
||||||
EXPECT_EQ(test_string[0], 'A');
|
EXPECT_EQ(test_string[0], 'A');
|
||||||
EXPECT_EQ(test_string[1], 'B');
|
EXPECT_EQ(test_string[1], 'B');
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue