Rename static_string to string_view

This commit is contained in:
rexy712 2022-03-20 14:16:18 -07:00
parent a838f1a25a
commit adc52a3659
5 changed files with 69 additions and 50 deletions

View File

@ -81,7 +81,7 @@ namespace rexy::cx{
} }
} }
constexpr string(const rexy::static_string<value_type>& str)noexcept: constexpr string(const rexy::string_view<value_type>& str)noexcept:
m_length(str.length()) m_length(str.length())
{ {
for(size_type i = 0;i < m_length;++i){ for(size_type i = 0;i < m_length;++i){
@ -165,7 +165,7 @@ namespace rexy::cx{
constexpr void append(const string& s)noexcept{ constexpr void append(const string& s)noexcept{
append(s.get(), s.length()); append(s.get(), s.length());
} }
constexpr void append(const rexy::static_string<value_type>& s)noexcept{ constexpr void append(const rexy::string_view<value_type>& s)noexcept{
append(s.get(), s.length()); append(s.get(), s.length());
} }
}; };
@ -191,11 +191,11 @@ namespace rexy::cx{
} }
template<class Str1, std::enable_if_t<detail::is_cx_string<Str1>::value,int> = 0> template<class Str1, std::enable_if_t<detail::is_cx_string<Str1>::value,int> = 0>
constexpr auto operator+(Str1&& l, const char* r)noexcept{ constexpr auto operator+(Str1&& l, const char* r)noexcept{
return string_cat_expr(std::forward<Str1>(l), rexy::static_string<char>(r)); return string_cat_expr(std::forward<Str1>(l), rexy::string_view<char>(r));
} }
template<class Str1, std::enable_if_t<detail::is_cx_string<Str1>::value,int> = 0> template<class Str1, std::enable_if_t<detail::is_cx_string<Str1>::value,int> = 0>
constexpr auto operator+(const char* l, Str1&& r)noexcept{ constexpr auto operator+(const char* l, Str1&& r)noexcept{
return string_cat_expr(rexy::static_string<char>(l), std::forward<Str1>(r)); return string_cat_expr(rexy::string_view<char>(l), std::forward<Str1>(r));
} }
} }

View File

@ -26,7 +26,7 @@
namespace rexy{ namespace rexy{
template<class Char> template<class Char>
struct hash<rexy::static_string<Char>> : public string_hash<rexy::static_string<Char>>{}; struct hash<rexy::string_view<Char>> : public string_hash<rexy::string_view<Char>>{};
} }

View File

@ -78,7 +78,7 @@ namespace rexy{
length(0), length(0),
data{}{} 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{ union combine_data{
ldata l; ldata l;
sdata s; sdata s;
@ -349,7 +349,7 @@ namespace rexy{
string_cat_expr(Left&&,Right&&) -> string_cat_expr<Left&&,Right&&>; string_cat_expr(Left&&,Right&&) -> string_cat_expr<Left&&,Right&&>;
template<class Char> template<class Char>
class static_string : public string_base<Char> class string_view : public string_base<Char>
{ {
public: public:
using value_type = typename string_base<Char>::value_type; using value_type = typename string_base<Char>::value_type;
@ -363,23 +363,25 @@ namespace rexy{
using const_iterator = typename string_base<Char>::const_iterator; using const_iterator = typename string_base<Char>::const_iterator;
public: public:
constexpr static_string(void)noexcept; constexpr string_view(void)noexcept;
constexpr static_string(const_pointer str, size_type len)noexcept; constexpr string_view(const_pointer str, size_type len)noexcept;
constexpr static_string(const_pointer c)noexcept; constexpr string_view(const_pointer c)noexcept;
constexpr static_string(const static_string& s)noexcept; constexpr string_view(const string_view& s)noexcept;
constexpr static_string(static_string&& s)noexcept; constexpr string_view(string_view&& s)noexcept;
~static_string(void)noexcept = default; ~string_view(void)noexcept = default;
constexpr static_string& operator=(const_pointer c)noexcept; constexpr string_view& operator=(const_pointer c)noexcept;
constexpr static_string& operator=(const static_string& s)noexcept; constexpr string_view& operator=(const string_view& s)noexcept;
constexpr static_string& operator=(static_string&&)noexcept; constexpr string_view& operator=(string_view&&)noexcept;
}; };
template<class T> template<class T>
static_string(const T*) -> static_string<T>; string_view(const T*) -> string_view<T>;
template<class T> template<class T>
static_string(const T*, size_t) -> static_string<T>; string_view(const T*, size_t) -> string_view<T>;
template<class T>
using static_string [[deprecated]] = string_view<T>;
template<class T> template<class T>
struct is_string{ struct is_string{
@ -426,16 +428,16 @@ namespace rexy{
} }
template<class Right, detail::enable_if_string<Right> = 0> template<class Right, detail::enable_if_string<Right> = 0>
constexpr auto operator+(typename std::decay_t<Right>::const_pointer left, Right&& right) constexpr auto operator+(typename std::decay_t<Right>::const_pointer left, Right&& right)
noexcept(noexcept(::new (nullptr) string_cat_expr(rexy::static_string(left), std::forward<Right>(right)))) noexcept(noexcept(::new (nullptr) string_cat_expr(rexy::string_view(left), std::forward<Right>(right))))
{ {
return string_cat_expr(rexy::static_string(left), std::forward<Right>(right)); return string_cat_expr(rexy::string_view(left), std::forward<Right>(right));
} }
template<class Left, detail::enable_if_string<Left> = 0> template<class Left, detail::enable_if_string<Left> = 0>
constexpr auto operator+(Left&& left, typename std::decay_t<Left>::const_pointer right) constexpr auto operator+(Left&& left, typename std::decay_t<Left>::const_pointer right)
noexcept(noexcept(::new (nullptr) string_cat_expr(std::forward<Left>(left), rexy::static_string(right)))) noexcept(noexcept(::new (nullptr) string_cat_expr(std::forward<Left>(left), rexy::string_view(right))))
{ {
return rexy::string_cat_expr(std::forward<Left>(left), rexy::static_string(right)); return rexy::string_cat_expr(std::forward<Left>(left), rexy::string_view(right));
} }
template<class Left, class Right, detail::enable_if_concrete_string<Left> = 0, detail::enable_if_string<Right> = 0> template<class Left, class Right, detail::enable_if_concrete_string<Left> = 0, detail::enable_if_string<Right> = 0>
@ -455,17 +457,34 @@ namespace rexy{
#include "string_base.tpp" #include "string_base.tpp"
namespace{ namespace{
constexpr inline rexy::static_string<char> operator"" _ss(const char* str, size_t len)noexcept{ [[deprecated]]
return rexy::static_string(str, len); constexpr inline rexy::string_view<char> operator"" _ss(const char* str, size_t len)noexcept{
return rexy::string_view(str, len);
} }
constexpr inline rexy::static_string<wchar_t> operator"" _ss(const wchar_t* str, size_t len)noexcept{ [[deprecated]]
return rexy::static_string(str, len); constexpr inline rexy::string_view<wchar_t> operator"" _ss(const wchar_t* str, size_t len)noexcept{
return rexy::string_view(str, len);
} }
constexpr inline rexy::static_string<char16_t> operator"" _ss(const char16_t* str, size_t len)noexcept{ [[deprecated]]
return rexy::static_string(str, len); constexpr inline rexy::string_view<char16_t> operator"" _ss(const char16_t* str, size_t len)noexcept{
return rexy::string_view(str, len);
} }
constexpr inline rexy::static_string<char32_t> operator"" _ss(const char32_t* str, size_t len)noexcept{ [[deprecated]]
return rexy::static_string(str, len); constexpr inline rexy::string_view<char32_t> operator"" _ss(const char32_t* str, size_t len)noexcept{
return rexy::string_view(str, len);
}
constexpr inline rexy::string_view<char> operator"" _sv(const char* str, size_t len)noexcept{
return rexy::string_view(str, len);
}
constexpr inline rexy::string_view<wchar_t> operator"" _sv(const wchar_t* str, size_t len)noexcept{
return rexy::string_view(str, len);
}
constexpr inline rexy::string_view<char16_t> operator"" _sv(const char16_t* str, size_t len)noexcept{
return rexy::string_view(str, len);
}
constexpr inline rexy::string_view<char32_t> operator"" _sv(const char32_t* str, size_t len)noexcept{
return rexy::string_view(str, len);
} }
} }

View File

@ -320,11 +320,11 @@ namespace rexy{
template<class Char> template<class Char>
constexpr static_string<Char>::static_string(void)noexcept: constexpr string_view<Char>::string_view(void)noexcept:
static_string(nullptr, 0){} string_view(nullptr, 0){}
template<class Char> template<class Char>
constexpr static_string<Char>::static_string(const_pointer str, size_type len)noexcept{ constexpr string_view<Char>::string_view(const_pointer str, size_type len)noexcept{
if(!str) if(!str)
this->set_long_ptr(nullptr); this->set_long_ptr(nullptr);
else else
@ -333,23 +333,23 @@ namespace rexy{
this->set_long_capacity(len); this->set_long_capacity(len);
} }
template<class Char> template<class Char>
constexpr static_string<Char>::static_string(const static_string& s)noexcept: constexpr string_view<Char>::string_view(const string_view& s)noexcept:
static_string(s.get_long_ptr(), s.get_long_length()){} string_view(s.get_long_ptr(), s.get_long_length()){}
template<class Char> template<class Char>
constexpr static_string<Char>::static_string(static_string&& s)noexcept: constexpr string_view<Char>::string_view(string_view&& s)noexcept:
static_string(s.get_long_ptr(), s.get_long_length()){} string_view(s.get_long_ptr(), s.get_long_length()){}
template<class Char> template<class Char>
constexpr static_string<Char>& static_string<Char>::operator=(const static_string& s)noexcept{ constexpr string_view<Char>& string_view<Char>::operator=(const string_view& s)noexcept{
this->set_long_ptr(const_cast<pointer>(s.get_long_ptr())); this->set_long_ptr(const_cast<pointer>(s.get_long_ptr()));
this->set_long_length(s.get_long_length()); this->set_long_length(s.get_long_length());
this->set_long_capacity(s.get_long_capacity()); this->set_long_capacity(s.get_long_capacity());
return *this; return *this;
} }
template<class Char> template<class Char>
constexpr static_string<Char>::static_string(const_pointer c)noexcept: constexpr string_view<Char>::string_view(const_pointer c)noexcept:
static_string(c, strlen(c)){} string_view(c, strlen(c)){}
template<class Char> template<class Char>
constexpr static_string<Char>& static_string<Char>::operator=(const_pointer c)noexcept{ constexpr string_view<Char>& string_view<Char>::operator=(const_pointer c)noexcept{
size_type len = strlen(c); size_type len = strlen(c);
this->set_long_ptr(const_cast<pointer>(c)); this->set_long_ptr(const_cast<pointer>(c));
this->set_long_length(len); this->set_long_length(len);
@ -357,17 +357,17 @@ namespace rexy{
return *this; return *this;
} }
template<class Char> template<class Char>
constexpr static_string<Char>& static_string<Char>::operator=(static_string&& s)noexcept{ constexpr string_view<Char>& string_view<Char>::operator=(string_view&& s)noexcept{
this->set_long_ptr(s.get_long_ptr()); this->set_long_ptr(s.get_long_ptr());
this->set_long_length(s.get_long_length()); this->set_long_length(s.get_long_length());
this->set_long_capacity(s.get_long_capacity()); this->set_long_capacity(s.get_long_capacity());
return *this; return *this;
} }
extern template class static_string<char>; extern template class string_view<char>;
extern template class static_string<wchar_t>; extern template class string_view<wchar_t>;
extern template class static_string<char16_t>; extern template class string_view<char16_t>;
extern template class static_string<char32_t>; extern template class string_view<char32_t>;
} //namespace rexy } //namespace rexy

View File

@ -20,9 +20,9 @@
namespace rexy{ namespace rexy{
template class static_string<char>; template class string_view<char>;
template class static_string<wchar_t>; template class string_view<wchar_t>;
template class static_string<char16_t>; template class string_view<char16_t>;
template class static_string<char32_t>; template class string_view<char32_t>;
} }