Changes for how Literal changes to normal StringView.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
773e765c83
commit
083c00f85e
|
@ -72,6 +72,8 @@ namespace ArbUt {
|
||||||
: BasicStringView(str.length(), Hash(str.data())), _str(new __ConstStringCharHolder(str)) {}
|
: BasicStringView(str.length(), Hash(str.data())), _str(new __ConstStringCharHolder(str)) {}
|
||||||
StringView(const char* str) noexcept
|
StringView(const char* str) noexcept
|
||||||
: BasicStringView(CalcLength(str), Hash(str)), _str(new __ConstStringCharHolder(str, CalcLength(str))) {}
|
: BasicStringView(CalcLength(str), Hash(str)), _str(new __ConstStringCharHolder(str, CalcLength(str))) {}
|
||||||
|
StringView(const char* str, size_t length) noexcept
|
||||||
|
: BasicStringView(length, Hash(str)), _str(new __ConstStringCharHolder(str, length)) {}
|
||||||
|
|
||||||
StringView() noexcept : BasicStringView(0, Hash("")), _str(GetEmptyString()) {
|
StringView() noexcept : BasicStringView(0, Hash("")), _str(GetEmptyString()) {
|
||||||
GetEmptyString()->AddReference();
|
GetEmptyString()->AddReference();
|
||||||
|
|
|
@ -17,7 +17,7 @@ namespace ArbUt {
|
||||||
[[nodiscard]] inline constexpr const char* c_str() const noexcept { return _str; }
|
[[nodiscard]] inline constexpr const char* c_str() const noexcept { return _str; }
|
||||||
constexpr std::string_view std_str() const noexcept { return std::string_view(_str, _length); }
|
constexpr std::string_view std_str() const noexcept { return std::string_view(_str, _length); }
|
||||||
constexpr std::size_t operator()(StringViewLiteral const& s) const noexcept { return s.GetHash(); }
|
constexpr std::size_t operator()(StringViewLiteral const& s) const noexcept { return s.GetHash(); }
|
||||||
inline operator StringView() const noexcept { return StringView(std::string_view(_str, _length)); }
|
inline operator StringView() const noexcept { return StringView(_str, _length); }
|
||||||
|
|
||||||
inline constexpr bool operator==(const std::string_view& rhs) const noexcept {
|
inline constexpr bool operator==(const std::string_view& rhs) const noexcept {
|
||||||
return _hash == Hash(rhs.data());
|
return _hash == Hash(rhs.data());
|
||||||
|
|
|
@ -41,4 +41,26 @@ TEST_CASE("Literal conststring to non literal, then use", "[Utilities]") {
|
||||||
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
|
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef WINDOWS
|
||||||
|
__attribute__((optnone))
|
||||||
|
#endif
|
||||||
|
static ArbUt::StringView
|
||||||
|
TestCreateConstString() {
|
||||||
|
char originalVal[7];
|
||||||
|
originalVal[0] = 'f';
|
||||||
|
originalVal[1] = 'o';
|
||||||
|
originalVal[2] = 'o';
|
||||||
|
originalVal[3] = 'b';
|
||||||
|
originalVal[4] = 'a';
|
||||||
|
originalVal[5] = 'r';
|
||||||
|
originalVal[6] = '\0';
|
||||||
|
return ArbUt::StringView(originalVal);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Out of scope char* doesn't lose reference", "[Utilities]") {
|
||||||
|
ArbUt::StringView val = TestCreateConstString();
|
||||||
|
INFO(val.c_str());
|
||||||
|
REQUIRE(strcmp(val.c_str(), "foobar") == 0);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue