[Bf-blender-cvs] [3913b81f9e3] functions: construct StringRefNull from pointer and length
Jacques Lucke
noreply at git.blender.org
Tue May 28 12:13:24 CEST 2019
Commit: 3913b81f9e3d5a2bd60d8299dbf6a83e8da98e04
Author: Jacques Lucke
Date: Tue May 28 11:15:50 2019 +0200
Branches: functions
https://developer.blender.org/rB3913b81f9e3d5a2bd60d8299dbf6a83e8da98e04
construct StringRefNull from pointer and length
===================================================================
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 03b2afa64d2..d13218cc3f5 100644
--- a/source/blender/blenlib/BLI_string_ref.hpp
+++ b/source/blender/blenlib/BLI_string_ref.hpp
@@ -91,6 +91,11 @@ class StringRefNull : public StringRefBase {
BLI_assert(m_data[m_size] == '\0');
}
+ StringRefNull(const char *str, size_type size) : StringRefBase(str, size)
+ {
+ BLI_assert(str[size] == '\0');
+ }
+
StringRefNull(const std::string &str) : StringRefNull(str.data())
{
}
diff --git a/tests/gtests/blenlib/BLI_string_ref_test.cc b/tests/gtests/blenlib/BLI_string_ref_test.cc
index fe994553a5c..5aa0aadaf09 100644
--- a/tests/gtests/blenlib/BLI_string_ref_test.cc
+++ b/tests/gtests/blenlib/BLI_string_ref_test.cc
@@ -19,6 +19,14 @@ TEST(string_ref_null, CStringConstructor)
EXPECT_EQ(ref.data(), str);
}
+TEST(string_ref_null, CStringLengthConstructor)
+{
+ const char *str = "Hello";
+ StringRefNull ref(str, 5);
+ EXPECT_EQ(ref.size(), 5);
+ EXPECT_EQ(ref.data(), str);
+}
+
TEST(string_ref, DefaultConstructor)
{
StringRef ref;
More information about the Bf-blender-cvs
mailing list