diff --git a/Source/Engine/Core/Types/StringView.h b/Source/Engine/Core/Types/StringView.h
index 74f8e398e..81d1adb0b 100644
--- a/Source/Engine/Core/Types/StringView.h
+++ b/Source/Engine/Core/Types/StringView.h
@@ -277,7 +277,7 @@ public:
/// True if this string is lexicographically equivalent to the other, otherwise false.
FORCE_INLINE bool operator==(const StringView& other) const
{
- return this->Compare(other) == 0;
+ return _length == other._length && (_length == 0 || StringUtils::Compare(_data, other._data, _length) == 0);
}
///
@@ -287,7 +287,7 @@ public:
/// True if this string is lexicographically is not equivalent to the other, otherwise false.
FORCE_INLINE bool operator!=(const StringView& other) const
{
- return this->Compare(other) != 0;
+ return !(*this == other);
}
///
@@ -297,7 +297,7 @@ public:
/// True if this string is lexicographically equivalent to the other, otherwise false.
FORCE_INLINE bool operator==(const Char* other) const
{
- return this->Compare(StringView(other)) == 0;
+ return *this == StringView(other);
}
///
@@ -307,7 +307,7 @@ public:
/// True if this string is lexicographically is not equivalent to the other, otherwise false.
FORCE_INLINE bool operator!=(const Char* other) const
{
- return this->Compare(StringView(other)) != 0;
+ return !(*this == StringView(other));
}
///
@@ -466,7 +466,7 @@ public:
/// True if this string is lexicographically equivalent to the other, otherwise false.
FORCE_INLINE bool operator==(const StringAnsiView& other) const
{
- return this->Compare(other) == 0;
+ return _length == other._length && (_length == 0 || StringUtils::Compare(_data, other._data, _length) == 0);
}
///
@@ -476,7 +476,7 @@ public:
/// True if this string is lexicographically is not equivalent to the other, otherwise false.
FORCE_INLINE bool operator!=(const StringAnsiView& other) const
{
- return this->Compare(other) != 0;
+ return !(*this == other);
}
///
@@ -486,7 +486,7 @@ public:
/// True if this string is lexicographically equivalent to the other, otherwise false.
FORCE_INLINE bool operator==(const char* other) const
{
- return this->Compare(StringAnsiView(other)) == 0;
+ return *this == StringAnsiView(other);
}
///
@@ -496,7 +496,7 @@ public:
/// True if this string is lexicographically is not equivalent to the other, otherwise false.
FORCE_INLINE bool operator!=(const char* other) const
{
- return this->Compare(StringAnsiView(other)) != 0;
+ return !(*this == StringAnsiView(other));
}
///
diff --git a/Source/Engine/Tests/TestString.cpp b/Source/Engine/Tests/TestString.cpp
index 69028ddb6..aadbacf98 100644
--- a/Source/Engine/Tests/TestString.cpp
+++ b/Source/Engine/Tests/TestString.cpp
@@ -224,6 +224,14 @@ TEST_CASE("String Compare works") {
// Case differences
CHECK(String("a").Compare(String(TEXT("A")), StringSearchCase::CaseSensitive) > 0);
CHECK(String("A").Compare(String(TEXT("a")), StringSearchCase::CaseSensitive) < 0);
+
+ // Operators
+ CHECK(String(TEXT("")) == String(TEXT("")));
+ CHECK(String(TEXT("xx")) != String(TEXT("")));
+ CHECK(!(String(TEXT("abcx")) == String(TEXT("xxx"))));
+ CHECK(String(TEXT("abcx")) != String(TEXT("xxx")));
+ CHECK(String(TEXT("xxx")) == String(TEXT("xxx")));
+ CHECK(!(String(TEXT("xxx")) != String(TEXT("xxx"))));
}
SECTION("ignore case") {
@@ -291,6 +299,14 @@ TEST_CASE("String Compare works") {
// Case differences
CHECK(StringView(TEXT("a")).Compare(StringView(TEXT("A")), StringSearchCase::CaseSensitive) > 0);
CHECK(StringView(TEXT("A")).Compare(StringView(TEXT("a")), StringSearchCase::CaseSensitive) < 0);
+
+ // Operators
+ CHECK(StringView(TEXT("")) == StringView(TEXT("")));
+ CHECK(StringView(TEXT("xx")) != StringView(TEXT("")));
+ CHECK(!(StringView(TEXT("abcx")) == StringView(TEXT("xxx"))));
+ CHECK(StringView(TEXT("abcx")) != StringView(TEXT("xxx")));
+ CHECK(StringView(TEXT("xxx")) == StringView(TEXT("xxx")));
+ CHECK(!(StringView(TEXT("xxx")) != StringView(TEXT("xxx"))));
}
SECTION("ignore case") {