Add some iterator manipulation to string_view. Add a push_back function to strings so that they can be used in standard library stuff more
This commit is contained in:
parent
058ebe026e
commit
fd22069562
@ -310,6 +310,9 @@ namespace rexy{
|
|||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(noexcept(this->allocate(0)) &&
|
||||||
noexcept(this->deallocate(nullptr,0)));
|
noexcept(this->deallocate(nullptr,0)));
|
||||||
|
|
||||||
|
REXY_CPP20_CONSTEXPR void push_back(value_type data)
|
||||||
|
noexcept(noexcept(this->allocate(0)) &&
|
||||||
|
noexcept(this->deallocate(nullptr,0)));
|
||||||
REXY_CPP20_CONSTEXPR void append(const_pointer data, size_type len)
|
REXY_CPP20_CONSTEXPR void append(const_pointer data, size_type len)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(noexcept(this->allocate(0)) &&
|
||||||
noexcept(this->deallocate(nullptr,0)));
|
noexcept(this->deallocate(nullptr,0)));
|
||||||
|
|||||||
@ -258,6 +258,15 @@ namespace rexy{
|
|||||||
return false;
|
return false;
|
||||||
return (*this = basic_string(this->get_pointer(), newsize));
|
return (*this = basic_string(this->get_pointer(), newsize));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
|
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::push_back(value_type data)
|
||||||
|
noexcept(noexcept(this->allocate(0)) &&
|
||||||
|
noexcept(this->deallocate(nullptr,0)))
|
||||||
|
{
|
||||||
|
append(&data, 1);
|
||||||
|
}
|
||||||
|
|
||||||
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
template<class Char, REXY_ALLOCATOR_CONCEPT Alloc>
|
||||||
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::append(const_pointer data, size_type len)
|
REXY_CPP20_CONSTEXPR void basic_string<Char,Alloc>::append(const_pointer data, size_type len)
|
||||||
noexcept(noexcept(this->allocate(0)) &&
|
noexcept(noexcept(this->allocate(0)) &&
|
||||||
|
|||||||
@ -46,6 +46,8 @@ namespace rexy{
|
|||||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||||
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
|
||||||
|
|
||||||
|
static constexpr size_type npos = size_type{-1};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const_pointer m_data = nullptr;
|
const_pointer m_data = nullptr;
|
||||||
size_type m_length = 0;
|
size_type m_length = 0;
|
||||||
@ -95,6 +97,16 @@ namespace rexy{
|
|||||||
constexpr const_reverse_iterator rend(void)const{return const_reverse_iterator(m_data-1);}
|
constexpr const_reverse_iterator rend(void)const{return const_reverse_iterator(m_data-1);}
|
||||||
constexpr const_reverse_iterator crbegin(void)const{return rbegin();}
|
constexpr const_reverse_iterator crbegin(void)const{return rbegin();}
|
||||||
constexpr const_reverse_iterator crend(void)const{return rend();}
|
constexpr const_reverse_iterator crend(void)const{return rend();}
|
||||||
|
|
||||||
|
constexpr void remove_prefix(size_type i);
|
||||||
|
constexpr void remove_suffix(size_type i);
|
||||||
|
|
||||||
|
constexpr size_type find_first_of(value_type v, size_type start = 0)const;
|
||||||
|
constexpr size_type find_first_of(const_pointer c, size_type pos = 0)const;
|
||||||
|
constexpr size_type find_first_of(const_pointer c, size_type pos, size_type size)const;
|
||||||
|
constexpr size_type find_last_of(value_type v, size_type start = 0)const;
|
||||||
|
constexpr size_type find_last_of(const_pointer c, size_type pos = 0)const;
|
||||||
|
constexpr size_type find_last_of(const_pointer c, size_type pos, size_type size)const;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
|
|||||||
@ -68,6 +68,112 @@ namespace rexy{
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<class Char>
|
||||||
|
constexpr auto basic_string_view<Char>::search(const basic_string_view& s)const -> const_iterator{
|
||||||
|
return two_way_search(cbegin(), cend(), s.cbegin(), s.cend());
|
||||||
|
}
|
||||||
|
template<class Char>
|
||||||
|
constexpr auto basic_string_view<Char>::search(const_pointer c)const -> const_iterator{
|
||||||
|
basic_string_view tmp(c);
|
||||||
|
return search(tmp);
|
||||||
|
}
|
||||||
|
template<class Char>
|
||||||
|
template<class Searcher>
|
||||||
|
constexpr auto basic_string_view<Char>::search(const basic_string_view& s, const Searcher& searcher)const -> const_iterator{
|
||||||
|
return searcher(cbegin(), cend(), s.cbegin(), s.cend());
|
||||||
|
}
|
||||||
|
template<class Char>
|
||||||
|
template<class Searcher>
|
||||||
|
constexpr auto basic_string_view<Char>::search(const_pointer c, const Searcher& searcher)const -> const_iterator{
|
||||||
|
basic_string_view tmp(c);
|
||||||
|
return search(tmp, searcher);
|
||||||
|
}
|
||||||
|
template<class Char>
|
||||||
|
constexpr void basic_string_view<Char>::remove_prefix(size_type i){
|
||||||
|
if(i > m_length){
|
||||||
|
m_data = end();
|
||||||
|
m_length = 0;
|
||||||
|
}else{
|
||||||
|
m_data = begin() + i;
|
||||||
|
m_length -= i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<class Char>
|
||||||
|
constexpr void basic_string_view<Char>::remove_suffix(size_type i){
|
||||||
|
if(i > m_length){
|
||||||
|
m_length = 0;
|
||||||
|
}else{
|
||||||
|
m_length -= i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
template<class Char>
|
||||||
|
constexpr auto basic_string_view<Char>::find_first_of(value_type v, size_type start)const -> size_type{
|
||||||
|
if(start >= m_length){
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
for(auto it = begin() + start;it != end();++it){
|
||||||
|
if(*it == v){
|
||||||
|
return it - begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
template<class Char>
|
||||||
|
constexpr auto basic_string_view<Char>::find_first_of(const_pointer c, size_type start)const -> size_type{
|
||||||
|
return find_first_of(c, start, ::rexy::strlen(c));
|
||||||
|
}
|
||||||
|
template<class Char>
|
||||||
|
constexpr auto basic_string_view<Char>::find_first_of(const_pointer c, size_type start, size_type size)const -> size_type{
|
||||||
|
if(start > m_length){
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
for(auto it = begin() + start;it != end();++it){
|
||||||
|
for(size_type i = 0;i < size;++i){
|
||||||
|
if(*it == c[i]){
|
||||||
|
return it - begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
template<class Char>
|
||||||
|
constexpr auto basic_string_view<Char>::find_last_of(value_type v, size_type start)const -> size_type{
|
||||||
|
if(start >= m_length){
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
const auto b = end() - 1;
|
||||||
|
const auto e = begin() - 1 - start;
|
||||||
|
|
||||||
|
for(auto it = b;it != e;--it){
|
||||||
|
if(*it == v){
|
||||||
|
return it - begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
template<class Char>
|
||||||
|
constexpr auto basic_string_view<Char>::find_last_of(const_pointer c, size_type start)const -> size_type{
|
||||||
|
return find_last_of(c, start, ::rexy::strlen(c));
|
||||||
|
}
|
||||||
|
template<class Char>
|
||||||
|
constexpr auto basic_string_view<Char>::find_last_of(const_pointer c, size_type start, size_type size)const -> size_type{
|
||||||
|
if(start > m_length){
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto b = end() - 1;
|
||||||
|
const auto e = begin() - 1 - start;
|
||||||
|
|
||||||
|
for(auto it = b;it != e;--it){
|
||||||
|
for(size_type i = 0;i < size;++i){
|
||||||
|
if(*it == c[i]){
|
||||||
|
return it - begin();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user