Commit 886cc3c4 authored by Edward Catmur's avatar Edward Catmur

Related: when constructing StringPtr from String, ensure that content does not end up null. Test.

parent dbc088d1
......@@ -54,6 +54,12 @@ TEST(String, Str) {
EXPECT_EQ("foo", str(mv(f)));
}
TEST(String, Nullptr) {
EXPECT_EQ(String(nullptr), "");
EXPECT_EQ(StringPtr(String(nullptr)).size(), 0u);
EXPECT_EQ(StringPtr(String(nullptr))[0], '\0');
}
TEST(String, StartsEndsWith) {
EXPECT_TRUE(StringPtr("foobar").startsWith("foo"));
EXPECT_FALSE(StringPtr("foobar").startsWith("bar"));
......
......@@ -445,7 +445,7 @@ inline String Stringifier::operator*(const Array<T>& arr) const {
// =======================================================================================
// Inline implementation details.
inline StringPtr::StringPtr(const String& value): content(value.begin(), value.size() + 1) {}
inline StringPtr::StringPtr(const String& value): content(value.cStr(), value.size() + 1) {}
inline constexpr StringPtr::operator ArrayPtr<const char>() const {
return ArrayPtr<const char>(content.begin(), content.size() - 1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment