Fix string operators taking const char* instead of relevant const_pointer. Add deduction guides to static_string. Add compare function to string_base
This commit is contained in:
parent
8703d0089f
commit
a3b1d2baa7
@ -216,6 +216,11 @@ namespace rexy{
|
||||
constexpr reference operator[](size_type i)noexcept{return get_pointer()[i];}
|
||||
constexpr const_reference operator[](size_type i)const noexcept{return get_pointer()[i];}
|
||||
|
||||
//constexpr bool search(const string_base& s)const;
|
||||
//constexpr bool search(const_pointer c)const;
|
||||
constexpr bool compare(const string_base& s)const{return *this == s;}
|
||||
constexpr bool compare(const_pointer c)const{return *this == c;}
|
||||
|
||||
static constexpr bool uses_sso(void){return true;}
|
||||
static constexpr size_type short_string_size(void){return MAX_SHORT_LEN;}
|
||||
};
|
||||
@ -355,6 +360,11 @@ namespace rexy{
|
||||
constexpr static_string& operator=(static_string&&)noexcept;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
static_string(const T*) -> static_string<T>;
|
||||
template<class T>
|
||||
static_string(const T*, size_t) -> static_string<T>;
|
||||
|
||||
|
||||
template<class T>
|
||||
struct is_string{
|
||||
@ -379,10 +389,18 @@ namespace rexy{
|
||||
constexpr bool operator==(Str1&& left, Str2&& right)noexcept{
|
||||
return left.valid() && right.valid() && left.length() == right.length() && !cx::strcmp(left.get(), right.get());
|
||||
}
|
||||
template<class Str, detail::enable_if_concrete_string<Str> = 0>
|
||||
constexpr bool operator==(Str&& left, typename std::decay_t<Str>::const_pointer right)noexcept{
|
||||
return left.valid() && right && !cx::strcmp(left.get(), right);
|
||||
}
|
||||
template<class Str1, class Str2, detail::enable_if_concrete_string<Str1,Str2> = 0>
|
||||
constexpr bool operator!=(Str1&& left, Str2&& right)noexcept{
|
||||
return !(left == right);
|
||||
}
|
||||
template<class Str, detail::enable_if_concrete_string<Str> = 0>
|
||||
constexpr bool operator!=(Str&& left, typename std::decay_t<Str>::const_pointer right)noexcept{
|
||||
return !(left == right);
|
||||
}
|
||||
|
||||
template<class Left, class Right, detail::enable_if_string<Left,Right> = 0>
|
||||
constexpr auto operator+(Left&& l, Right&& r)
|
||||
@ -392,17 +410,17 @@ namespace rexy{
|
||||
return string_cat_expr(std::forward<Left>(l), std::forward<Right>(r));
|
||||
}
|
||||
template<class Right, detail::enable_if_string<Right> = 0>
|
||||
constexpr auto operator+(const char* left, Right&& right)
|
||||
noexcept(noexcept(::new (nullptr) string_cat_expr(rexy::static_string<char>(left), std::forward<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))))
|
||||
{
|
||||
return string_cat_expr(rexy::static_string<char>(left), std::forward<Right>(right));
|
||||
return string_cat_expr(rexy::static_string(left), std::forward<Right>(right));
|
||||
}
|
||||
|
||||
template<class Left, detail::enable_if_string<Left> = 0>
|
||||
constexpr auto operator+(Left&& left, const char* right)
|
||||
noexcept(noexcept(::new (nullptr) string_cat_expr(std::forward<Left>(left), rexy::static_string<char>(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))))
|
||||
{
|
||||
return rexy::string_cat_expr(std::forward<Left>(left), rexy::static_string<char>(right));
|
||||
return rexy::string_cat_expr(std::forward<Left>(left), rexy::static_string(right));
|
||||
}
|
||||
|
||||
template<class Left, class Right, detail::enable_if_concrete_string<Left> = 0, detail::enable_if_string<Right> = 0>
|
||||
@ -412,7 +430,7 @@ namespace rexy{
|
||||
return l = (l + std::forward<Right>(r));
|
||||
}
|
||||
template<class Left, detail::enable_if_concrete_string<Left> = 0>
|
||||
decltype(auto) operator+=(Left& l, const char* r)
|
||||
decltype(auto) operator+=(Left& l, typename std::decay_t<Left>::const_pointer r)
|
||||
noexcept(noexcept(l + r) && std::is_nothrow_assignable<Left, decltype(l + r)>::value)
|
||||
{
|
||||
return l = (l + r);
|
||||
@ -423,16 +441,16 @@ namespace rexy{
|
||||
|
||||
namespace{
|
||||
constexpr inline rexy::static_string<char> operator"" _ss(const char* str, size_t len)noexcept{
|
||||
return rexy::static_string<char>(str, len);
|
||||
return rexy::static_string(str, len);
|
||||
}
|
||||
constexpr inline rexy::static_string<wchar_t> operator"" _ss(const wchar_t* str, size_t len)noexcept{
|
||||
return rexy::static_string<wchar_t>(str, len);
|
||||
return rexy::static_string(str, len);
|
||||
}
|
||||
constexpr inline rexy::static_string<char16_t> operator"" _ss(const char16_t* str, size_t len)noexcept{
|
||||
return rexy::static_string<char16_t>(str, len);
|
||||
return rexy::static_string(str, len);
|
||||
}
|
||||
constexpr inline rexy::static_string<char32_t> operator"" _ss(const char32_t* str, size_t len)noexcept{
|
||||
return rexy::static_string<char32_t>(str, len);
|
||||
return rexy::static_string(str, len);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user