From adc52a36593732af36d1a6f9b8dc86c6425ab427 Mon Sep 17 00:00:00 2001 From: rexy712 Date: Sun, 20 Mar 2022 14:16:18 -0700 Subject: [PATCH] Rename static_string to string_view --- include/rexy/cx/string.hpp | 8 ++-- include/rexy/static_string_hash.hpp | 2 +- include/rexy/string_base.hpp | 69 ++++++++++++++++++----------- include/rexy/string_base.tpp | 32 ++++++------- src/static_string.cpp | 8 ++-- 5 files changed, 69 insertions(+), 50 deletions(-) diff --git a/include/rexy/cx/string.hpp b/include/rexy/cx/string.hpp index 1e08b61..9a90cb4 100644 --- a/include/rexy/cx/string.hpp +++ b/include/rexy/cx/string.hpp @@ -81,7 +81,7 @@ namespace rexy::cx{ } } - constexpr string(const rexy::static_string& str)noexcept: + constexpr string(const rexy::string_view& str)noexcept: m_length(str.length()) { for(size_type i = 0;i < m_length;++i){ @@ -165,7 +165,7 @@ namespace rexy::cx{ constexpr void append(const string& s)noexcept{ append(s.get(), s.length()); } - constexpr void append(const rexy::static_string& s)noexcept{ + constexpr void append(const rexy::string_view& s)noexcept{ append(s.get(), s.length()); } }; @@ -191,11 +191,11 @@ namespace rexy::cx{ } template::value,int> = 0> constexpr auto operator+(Str1&& l, const char* r)noexcept{ - return string_cat_expr(std::forward(l), rexy::static_string(r)); + return string_cat_expr(std::forward(l), rexy::string_view(r)); } template::value,int> = 0> constexpr auto operator+(const char* l, Str1&& r)noexcept{ - return string_cat_expr(rexy::static_string(l), std::forward(r)); + return string_cat_expr(rexy::string_view(l), std::forward(r)); } } diff --git a/include/rexy/static_string_hash.hpp b/include/rexy/static_string_hash.hpp index 48e1cc4..2e1a19c 100644 --- a/include/rexy/static_string_hash.hpp +++ b/include/rexy/static_string_hash.hpp @@ -26,7 +26,7 @@ namespace rexy{ template - struct hash> : public string_hash>{}; + struct hash> : public string_hash>{}; } diff --git a/include/rexy/string_base.hpp b/include/rexy/string_base.hpp index 011ab34..c64f349 100644 --- a/include/rexy/string_base.hpp +++ b/include/rexy/string_base.hpp @@ -78,7 +78,7 @@ namespace rexy{ length(0), data{}{} }; - //union of short and long string representations. Default to long representation for static_string's use case. + //union of short and long string representations. Default to long representation for string_view's use case. union combine_data{ ldata l; sdata s; @@ -349,7 +349,7 @@ namespace rexy{ string_cat_expr(Left&&,Right&&) -> string_cat_expr; template - class static_string : public string_base + class string_view : public string_base { public: using value_type = typename string_base::value_type; @@ -363,23 +363,25 @@ namespace rexy{ using const_iterator = typename string_base::const_iterator; public: - constexpr static_string(void)noexcept; - constexpr static_string(const_pointer str, size_type len)noexcept; - constexpr static_string(const_pointer c)noexcept; - constexpr static_string(const static_string& s)noexcept; - constexpr static_string(static_string&& s)noexcept; - ~static_string(void)noexcept = default; + constexpr string_view(void)noexcept; + constexpr string_view(const_pointer str, size_type len)noexcept; + constexpr string_view(const_pointer c)noexcept; + constexpr string_view(const string_view& s)noexcept; + constexpr string_view(string_view&& s)noexcept; + ~string_view(void)noexcept = default; - constexpr static_string& operator=(const_pointer c)noexcept; - constexpr static_string& operator=(const static_string& s)noexcept; - constexpr static_string& operator=(static_string&&)noexcept; + constexpr string_view& operator=(const_pointer c)noexcept; + constexpr string_view& operator=(const string_view& s)noexcept; + constexpr string_view& operator=(string_view&&)noexcept; }; template - static_string(const T*) -> static_string; + string_view(const T*) -> string_view; template - static_string(const T*, size_t) -> static_string; + string_view(const T*, size_t) -> string_view; + template + using static_string [[deprecated]] = string_view; template struct is_string{ @@ -426,16 +428,16 @@ namespace rexy{ } template = 0> constexpr auto operator+(typename std::decay_t::const_pointer left, Right&& right) - noexcept(noexcept(::new (nullptr) string_cat_expr(rexy::static_string(left), std::forward(right)))) + noexcept(noexcept(::new (nullptr) string_cat_expr(rexy::string_view(left), std::forward(right)))) { - return string_cat_expr(rexy::static_string(left), std::forward(right)); + return string_cat_expr(rexy::string_view(left), std::forward(right)); } template = 0> constexpr auto operator+(Left&& left, typename std::decay_t::const_pointer right) - noexcept(noexcept(::new (nullptr) string_cat_expr(std::forward(left), rexy::static_string(right)))) + noexcept(noexcept(::new (nullptr) string_cat_expr(std::forward(left), rexy::string_view(right)))) { - return rexy::string_cat_expr(std::forward(left), rexy::static_string(right)); + return rexy::string_cat_expr(std::forward(left), rexy::string_view(right)); } template = 0, detail::enable_if_string = 0> @@ -455,17 +457,34 @@ namespace rexy{ #include "string_base.tpp" namespace{ - constexpr inline rexy::static_string operator"" _ss(const char* str, size_t len)noexcept{ - return rexy::static_string(str, len); + [[deprecated]] + constexpr inline rexy::string_view operator"" _ss(const char* str, size_t len)noexcept{ + return rexy::string_view(str, len); } - constexpr inline rexy::static_string operator"" _ss(const wchar_t* str, size_t len)noexcept{ - return rexy::static_string(str, len); + [[deprecated]] + constexpr inline rexy::string_view operator"" _ss(const wchar_t* str, size_t len)noexcept{ + return rexy::string_view(str, len); } - constexpr inline rexy::static_string operator"" _ss(const char16_t* str, size_t len)noexcept{ - return rexy::static_string(str, len); + [[deprecated]] + constexpr inline rexy::string_view operator"" _ss(const char16_t* str, size_t len)noexcept{ + return rexy::string_view(str, len); } - constexpr inline rexy::static_string operator"" _ss(const char32_t* str, size_t len)noexcept{ - return rexy::static_string(str, len); + [[deprecated]] + constexpr inline rexy::string_view operator"" _ss(const char32_t* str, size_t len)noexcept{ + return rexy::string_view(str, len); + } + + constexpr inline rexy::string_view operator"" _sv(const char* str, size_t len)noexcept{ + return rexy::string_view(str, len); + } + constexpr inline rexy::string_view operator"" _sv(const wchar_t* str, size_t len)noexcept{ + return rexy::string_view(str, len); + } + constexpr inline rexy::string_view operator"" _sv(const char16_t* str, size_t len)noexcept{ + return rexy::string_view(str, len); + } + constexpr inline rexy::string_view operator"" _sv(const char32_t* str, size_t len)noexcept{ + return rexy::string_view(str, len); } } diff --git a/include/rexy/string_base.tpp b/include/rexy/string_base.tpp index 86b41b6..00fa8b5 100644 --- a/include/rexy/string_base.tpp +++ b/include/rexy/string_base.tpp @@ -320,11 +320,11 @@ namespace rexy{ template - constexpr static_string::static_string(void)noexcept: - static_string(nullptr, 0){} + constexpr string_view::string_view(void)noexcept: + string_view(nullptr, 0){} template - constexpr static_string::static_string(const_pointer str, size_type len)noexcept{ + constexpr string_view::string_view(const_pointer str, size_type len)noexcept{ if(!str) this->set_long_ptr(nullptr); else @@ -333,23 +333,23 @@ namespace rexy{ this->set_long_capacity(len); } template - constexpr static_string::static_string(const static_string& s)noexcept: - static_string(s.get_long_ptr(), s.get_long_length()){} + constexpr string_view::string_view(const string_view& s)noexcept: + string_view(s.get_long_ptr(), s.get_long_length()){} template - constexpr static_string::static_string(static_string&& s)noexcept: - static_string(s.get_long_ptr(), s.get_long_length()){} + constexpr string_view::string_view(string_view&& s)noexcept: + string_view(s.get_long_ptr(), s.get_long_length()){} template - constexpr static_string& static_string::operator=(const static_string& s)noexcept{ + constexpr string_view& string_view::operator=(const string_view& s)noexcept{ this->set_long_ptr(const_cast(s.get_long_ptr())); this->set_long_length(s.get_long_length()); this->set_long_capacity(s.get_long_capacity()); return *this; } template - constexpr static_string::static_string(const_pointer c)noexcept: - static_string(c, strlen(c)){} + constexpr string_view::string_view(const_pointer c)noexcept: + string_view(c, strlen(c)){} template - constexpr static_string& static_string::operator=(const_pointer c)noexcept{ + constexpr string_view& string_view::operator=(const_pointer c)noexcept{ size_type len = strlen(c); this->set_long_ptr(const_cast(c)); this->set_long_length(len); @@ -357,17 +357,17 @@ namespace rexy{ return *this; } template - constexpr static_string& static_string::operator=(static_string&& s)noexcept{ + constexpr string_view& string_view::operator=(string_view&& s)noexcept{ this->set_long_ptr(s.get_long_ptr()); this->set_long_length(s.get_long_length()); this->set_long_capacity(s.get_long_capacity()); return *this; } - extern template class static_string; - extern template class static_string; - extern template class static_string; - extern template class static_string; + extern template class string_view; + extern template class string_view; + extern template class string_view; + extern template class string_view; } //namespace rexy diff --git a/src/static_string.cpp b/src/static_string.cpp index cbe9590..6634190 100644 --- a/src/static_string.cpp +++ b/src/static_string.cpp @@ -20,9 +20,9 @@ namespace rexy{ - template class static_string; - template class static_string; - template class static_string; - template class static_string; + template class string_view; + template class string_view; + template class string_view; + template class string_view; }