[Bf-blender-cvs] [f59ea9a10f0] functions: support not-equal operator for StringRef

Jacques Lucke noreply at git.blender.org
Thu Sep 5 19:11:48 CEST 2019


Commit: f59ea9a10f05387409a4a16c791ae1cbaa7f7234
Author: Jacques Lucke
Date:   Thu Sep 5 12:35:27 2019 +0200
Branches: functions
https://developer.blender.org/rBf59ea9a10f05387409a4a16c791ae1cbaa7f7234

support not-equal operator for StringRef

===================================================================

M	source/blender/blenlib/BLI_string_ref.hpp
M	tests/gtests/blenlib/BLI_string_ref_test.cc

===================================================================

diff --git a/source/blender/blenlib/BLI_string_ref.hpp b/source/blender/blenlib/BLI_string_ref.hpp
index 678dccd9178..6605fa35043 100644
--- a/source/blender/blenlib/BLI_string_ref.hpp
+++ b/source/blender/blenlib/BLI_string_ref.hpp
@@ -204,6 +204,11 @@ inline bool operator==(StringRef a, StringRef b)
   return STREQLEN(a.data(), b.data(), a.size());
 }
 
+inline bool operator!=(StringRef a, StringRef b)
+{
+  return !(a == b);
+}
+
 inline bool StringRefBase::startswith(StringRef prefix) const
 {
   if (m_size < prefix.m_size) {
diff --git a/tests/gtests/blenlib/BLI_string_ref_test.cc b/tests/gtests/blenlib/BLI_string_ref_test.cc
index 2a35483fa20..62afb6b8ecf 100644
--- a/tests/gtests/blenlib/BLI_string_ref_test.cc
+++ b/tests/gtests/blenlib/BLI_string_ref_test.cc
@@ -132,6 +132,8 @@ TEST(string_ref, CompareEqual)
   StringRef ref3("other");
   EXPECT_TRUE(ref1 == ref2);
   EXPECT_FALSE(ref1 == ref3);
+  EXPECT_TRUE(ref1 != ref3);
+  EXPECT_FALSE(ref1 != ref2);
 }
 
 TEST(string_ref, CompareEqualCharPtr1)
@@ -139,6 +141,8 @@ TEST(string_ref, CompareEqualCharPtr1)
   StringRef ref("test");
   EXPECT_TRUE(ref == "test");
   EXPECT_FALSE(ref == "other");
+  EXPECT_TRUE(ref != "other");
+  EXPECT_FALSE(ref != "test");
 }
 
 TEST(string_ref, CompareEqualCharPtr2)
@@ -146,6 +150,8 @@ TEST(string_ref, CompareEqualCharPtr2)
   StringRef ref("test");
   EXPECT_TRUE("test" == ref);
   EXPECT_FALSE("other" == ref);
+  EXPECT_TRUE(ref != "other");
+  EXPECT_FALSE(ref != "test");
 }
 
 TEST(string_ref, CompareEqualString1)
@@ -153,6 +159,8 @@ TEST(string_ref, CompareEqualString1)
   StringRef ref("test");
   EXPECT_TRUE(ref == std::string("test"));
   EXPECT_FALSE(ref == std::string("other"));
+  EXPECT_TRUE(ref != std::string("other"));
+  EXPECT_FALSE(ref != std::string("test"));
 }
 
 TEST(string_ref, CompareEqualString2)
@@ -160,6 +168,8 @@ TEST(string_ref, CompareEqualString2)
   StringRef ref("test");
   EXPECT_TRUE(std::string("test") == ref);
   EXPECT_FALSE(std::string("other") == ref);
+  EXPECT_TRUE(std::string("other") != ref);
+  EXPECT_FALSE(std::string("test") != ref);
 }
 
 TEST(string_ref, Iterate)



More information about the Bf-blender-cvs mailing list