diff --git a/src/String/StringView.cpp b/src/String/StringView.cpp index 9f1dbd2..8a132a3 100644 --- a/src/String/StringView.cpp +++ b/src/String/StringView.cpp @@ -4,4 +4,7 @@ namespace ArbUt { std::shared_ptr<__ConstStringCharHolder> StringView::__emptyString = std::make_shared<__ConstStringCharHolder>("", 0); + + static StringView __empty; + const StringView& StringView::Empty() { return __empty; } } diff --git a/src/String/StringView.hpp b/src/String/StringView.hpp index 91facb7..88f16cb 100644 --- a/src/String/StringView.hpp +++ b/src/String/StringView.hpp @@ -86,6 +86,8 @@ namespace ArbUt { CalculateHash(const std::string_view& val) noexcept { return Hash(val.data()); } + + static const StringView& Empty(); }; } diff --git a/tests/StringViewTests.cpp b/tests/StringViewTests.cpp index d79018d..d341930 100644 --- a/tests/StringViewTests.cpp +++ b/tests/StringViewTests.cpp @@ -76,4 +76,9 @@ TEST_CASE("Out of scope char* doesn't lose reference", "[Utilities]") { REQUIRE(strcmp(val.c_str(), "foobar") == 0); } +TEST_CASE("Get Empty String", "[Utilities]") { + REQUIRE(ArbUt::StringView::Empty() == ""_cnc); +} + + #endif \ No newline at end of file