Update cx::string to be more level with string_view
This commit is contained in:
@@ -21,50 +21,13 @@
|
||||
|
||||
#include "../../string_base.hpp"
|
||||
|
||||
#include <concepts> //convertible_to
|
||||
#include <utility> //forward, as_const
|
||||
#include <utility> //forward
|
||||
#include <type_traits> //decay, is_nothrow_assignable
|
||||
|
||||
#include "../../concepts/string.hpp"
|
||||
|
||||
namespace rexy{
|
||||
|
||||
template<class T>
|
||||
concept BasicString = requires(const T& a){
|
||||
{std::as_const(a).length()} -> std::convertible_to<typename std::decay_t<T>::size_type>;
|
||||
{std::as_const(a).c_str()} -> std::convertible_to<typename std::decay_t<T>::const_pointer>;
|
||||
{std::as_const(a)[0]} -> std::convertible_to<typename std::decay_t<T>::const_reference>;
|
||||
{std::as_const(a).begin()} -> std::convertible_to<typename std::decay_t<T>::const_iterator>;
|
||||
{std::as_const(a).end()} -> std::convertible_to<typename std::decay_t<T>::const_iterator>;
|
||||
};
|
||||
template<class T>
|
||||
concept StringExpr = rexy::is_template_type<T,string_cat_expr>::value;
|
||||
template<class T>
|
||||
concept String = BasicString<T> || StringExpr<T>;
|
||||
|
||||
template<class T>
|
||||
struct is_string{
|
||||
static constexpr bool value = BasicString<T>;
|
||||
};
|
||||
template<class T>
|
||||
static constexpr bool is_string_v = is_string<T>::value;
|
||||
template<class... Ts>
|
||||
struct are_strings{
|
||||
static constexpr bool value = (BasicString<Ts> && ...);
|
||||
};
|
||||
template<class... Ts>
|
||||
static constexpr bool are_strings_v = are_strings<Ts...>::value;
|
||||
template<class T>
|
||||
struct is_string_expr{
|
||||
static constexpr bool value = StringExpr<T>;
|
||||
};
|
||||
template<class T>
|
||||
static constexpr bool is_string_expr_v = is_string_expr<T>::value;
|
||||
template<class... Ts>
|
||||
struct are_string_expr{
|
||||
static constexpr bool value = (StringExpr<Ts> && ...);
|
||||
};
|
||||
template<class... Ts>
|
||||
static constexpr bool are_string_expr_v = are_string_expr<Ts...>::value;
|
||||
|
||||
//Compare
|
||||
template<BasicString Str1, BasicString Str2>
|
||||
constexpr bool operator==(Str1&& left, Str2&& right){
|
||||
@@ -145,6 +108,40 @@ namespace rexy{
|
||||
return l = (l + r);
|
||||
}
|
||||
|
||||
template<BasicString T, class Char>
|
||||
constexpr std::size_t find_first_of(T&& t, const Char* c, std::size_t start, std::size_t size){
|
||||
if(start > t.length()){
|
||||
return rexy::npos;
|
||||
}
|
||||
for(auto it = t.cbegin() + start;it != t.cend();++it){
|
||||
for(std::size_t i = 0;i < size;++i){
|
||||
if(*it == c[i]){
|
||||
return it - t.cbegin();
|
||||
}
|
||||
}
|
||||
}
|
||||
return rexy::npos;
|
||||
}
|
||||
|
||||
template<BasicString T, class Char>
|
||||
constexpr std::size_t find_last_of(T&& t, const Char* c, std::size_t start, std::size_t size){
|
||||
if(start > t.length()){
|
||||
return rexy::npos;
|
||||
}
|
||||
|
||||
const auto b = t.cend() - 1;
|
||||
const auto e = t.cbegin() - 1 - start;
|
||||
|
||||
for(auto it = b;it != e;--it){
|
||||
for(std::size_t i = 0;i < size;++i){
|
||||
if(*it == c[i]){
|
||||
return it - t.cbegin();
|
||||
}
|
||||
}
|
||||
}
|
||||
return rexy::npos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user