Loading libutils/binder/String8_test.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -176,3 +176,11 @@ TEST_F(String8Test, comparisons) { EXPECT_TRUE(pair1 < pair2); EXPECT_FALSE(pair1 > pair2); } TEST_F(String8Test, SvCtor) { const char* expected = "abc"; std::string s{expected}; EXPECT_STREQ(String8{s}.c_str(), expected); EXPECT_STREQ(String8{std::string_view{s}}.c_str(), expected); EXPECT_STREQ(String8{expected}.c_str(), expected); } libutils/binder/include/utils/String8.h +6 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,9 @@ public: String8(const String8& o); explicit String8(const char* o); explicit String8(const char* o, size_t numChars); #ifdef HAS_STRING_VIEW explicit String8(std::string_view o); #endif explicit String8(const String16& o); explicit String8(const char16_t* o); Loading Loading @@ -374,6 +377,9 @@ inline String8::operator const char*() const } #ifdef HAS_STRING_VIEW inline String8::String8(std::string_view o) : String8(o.data(), o.length()) { } inline String8::operator std::string_view() const { return {mString, length()}; Loading Loading
libutils/binder/String8_test.cpp +8 −0 Original line number Diff line number Diff line Loading @@ -176,3 +176,11 @@ TEST_F(String8Test, comparisons) { EXPECT_TRUE(pair1 < pair2); EXPECT_FALSE(pair1 > pair2); } TEST_F(String8Test, SvCtor) { const char* expected = "abc"; std::string s{expected}; EXPECT_STREQ(String8{s}.c_str(), expected); EXPECT_STREQ(String8{std::string_view{s}}.c_str(), expected); EXPECT_STREQ(String8{expected}.c_str(), expected); }
libutils/binder/include/utils/String8.h +6 −0 Original line number Diff line number Diff line Loading @@ -57,6 +57,9 @@ public: String8(const String8& o); explicit String8(const char* o); explicit String8(const char* o, size_t numChars); #ifdef HAS_STRING_VIEW explicit String8(std::string_view o); #endif explicit String8(const String16& o); explicit String8(const char16_t* o); Loading Loading @@ -374,6 +377,9 @@ inline String8::operator const char*() const } #ifdef HAS_STRING_VIEW inline String8::String8(std::string_view o) : String8(o.data(), o.length()) { } inline String8::operator std::string_view() const { return {mString, length()}; Loading