Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5632c8ba authored by Atneya Nair's avatar Atneya Nair Committed by Gerrit Code Review
Browse files

Merge "[String8] Add string_view ctor" into main

parents a7fb895d 940f0755
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -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);
}
+6 −0
Original line number Diff line number Diff line
@@ -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);
@@ -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()};