Removed std::string_view interface

Added contains member functions
This commit is contained in:
John Wellbelove 2024-11-23 10:47:41 +00:00
parent bc44bf7a46
commit a3b40b667a
16 changed files with 1270 additions and 8502 deletions

View File

@ -52,10 +52,6 @@ SOFTWARE.
#include <stdint.h>
#include <string.h>
#if ETL_USING_STL && ETL_USING_CPP17
#include <string_view>
#endif
#include "private/minmax_push.h"
//*****************************************************************************
@ -711,17 +707,6 @@ namespace etl
assign(view.begin(), view.end());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Assigns values to the string from a view.
//*********************************************************************
template <typename TTraits>
void assign(const std::basic_string_view<T, TTraits>& view)
{
assign(view.begin(), view.end());
}
#endif
//*********************************************************************
/// Assigns values to the string.
/// Truncates if the string does not have enough free space.
@ -883,19 +868,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Appends to the string.
///\param view A std::string_view.
//*********************************************************************
template <typename TTraits>
ibasic_string& append(const std::basic_string_view<T, TTraits>& view)
{
insert(end(), view.begin(), view.end());
return *this;
}
#endif
//*********************************************************************
/// Inserts a value to the string.
///\param position The position to insert before.
@ -1138,20 +1110,6 @@ namespace etl
return insert(position, view.begin(), view.end());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Inserts a view to the string.
/// If asserts or exceptions are enabled, emits string_full if the string does not have enough free space.
///\param position The position to insert before.
///\param view The view element to add.
//*********************************************************************
template <typename TTraits>
iterator insert(const_iterator position, const std::basic_string_view<T, TTraits>& view)
{
return insert(position, view.begin(), view.end());
}
#endif
//*********************************************************************
/// Inserts a string at the specified position.
///\param position The position to insert before.
@ -1192,23 +1150,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Inserts a string at the specified position.
///\param position The position to insert before.
///\param view The view to insert.
//*********************************************************************
template <typename TTraits>
etl::ibasic_string<T>& insert(size_type position, const std::basic_string_view<T, TTraits>& view)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
insert(begin() + position, view.cbegin(), view.cend());
return *this;
}
#endif
//*********************************************************************
/// Inserts a string at the specified position from subposition for sublength.
///\param position The position to insert before.
@ -1265,31 +1206,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Inserts a view at the specified position from subposition for sublength.
///\param position The position to insert before.
///\param view The view to insert.
///\param subposition The subposition to start from.
///\param sublength The number of characters to insert.
//*********************************************************************
template <typename TTraits>
etl::ibasic_string<T>& insert(size_type position, const std::basic_string_view<T, TTraits>& view, size_type subposition, size_type sublength)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds));
if ((sublength == npos) || (subposition + sublength > view.size()))
{
sublength = view.size() - subposition;
}
insert(begin() + position, view.cbegin() + subposition, view.cbegin() + subposition + sublength);
return *this;
}
#endif
//*********************************************************************
/// Inserts a string at the specified position from pointer.
///\param position The position to insert before.
@ -1461,19 +1377,6 @@ namespace etl
return find_impl(view.begin(), view.end(), view.size(), pos);
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Find content within the string
///\param view The content to find
///\param pos The position to start searching from.
//*********************************************************************
template <typename TTraits>
size_type find(const std::basic_string_view<T, TTraits>& view, size_type pos = 0) const
{
return find_impl(view.begin(), view.end(), view.size(), pos);
}
#endif
//*********************************************************************
/// Find content within the string
///\param s Pointer to the content to find
@ -1539,19 +1442,6 @@ namespace etl
return rfind_impl(view.rbegin(), view.rend(), view.size(), pos);
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Find content within the string
///\param view The content to find
///\param pos The position to start searching from.
//*********************************************************************
template <typename TTraits>
size_type rfind(const std::basic_string_view<T, TTraits>& view, size_type pos = 0) const
{
return rfind_impl(view.rbegin(), view.rend(), view.size(), pos);
}
#endif
//*********************************************************************
/// Find content within the string
///\param str The content to find
@ -1606,6 +1496,39 @@ namespace etl
}
}
//*********************************************************************
/// Checks that the string is within the string
//*********************************************************************
bool contains(const etl::ibasic_string<T>& str) const
{
return find(str) != npos;
}
//*********************************************************************
/// Checks that the view is within the string
//*********************************************************************
template <typename TTraits>
bool contains(const etl::basic_string_view<T, TTraits>& view) const
{
return find(view) != npos;
}
//*********************************************************************
/// Checks that text is within the string
//*********************************************************************
bool contains(const_pointer s) const
{
return find(s) != npos;
}
//*********************************************************************
/// Checks that character is within the string
//*********************************************************************
bool contains(value_type c) const
{
return find(c) != npos;
}
//*********************************************************************
/// Replace 'length' characters from 'position' with 'str'.
///\param position The position to start from.
@ -1651,31 +1574,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Replace 'length' characters from 'position' with 'view'.
///\param position The position to start from.
///\param length The number of characters to replace.
///\param view The string to replace it with.
//*********************************************************************
template <typename TTraits>
ibasic_string& replace(size_type position, size_type length_, const std::basic_string_view<T, TTraits>& view)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
// Limit the length.
length_ = etl::min(length_, size() - position);
// Erase the bit we want to replace.
erase(position, length_);
// Insert the new stuff.
insert(position, view);
return *this;
}
#endif
//*********************************************************************
/// Replace characters from 'first' to one before 'last' with 'str'.
///\param first The position to start from.
@ -1730,30 +1628,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Replace characters from 'first' to one before 'last' with 'view'.
///\param first The position to start from.
///\param last The one after the position to end at.
///\param view The string view to replace it with.
//*********************************************************************
template <typename TTraits>
ibasic_string& replace(const_iterator first, const_iterator last, const std::basic_string_view<T, TTraits>& view)
{
// Quick hack, as iterators are pointers.
iterator first_ = to_iterator(first);
iterator last_ = to_iterator(last);
// Erase the bit we want to replace.
erase(first_, last_);
// Insert the new stuff.
insert(first_, view.begin(), view.end());
return *this;
}
#endif
//*********************************************************************
/// Replace characters from 'position' of 'length' with 'str' from 'subposition' of 'sublength'.
//*********************************************************************
@ -1808,30 +1682,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Replace characters from 'position' of 'length' with 'view' from 'subposition' of 'sublength'.
//*********************************************************************
template <typename TTraits>
ibasic_string& replace(size_type position, size_type length_, const std::basic_string_view<T, TTraits>& view, size_type subposition, size_type sublength)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds));
// Limit the lengths.
length_ = etl::min(length_, size() - position);
sublength = etl::min(sublength, view.size() - subposition);
// Erase the bit we want to replace.
erase(position, length_);
// Insert the new stuff.
insert(position, view, subposition, sublength);
return *this;
}
#endif
//*********************************************************************
/// Replace characters from 'position' of 'length' with pointed to string.
//*********************************************************************
@ -1985,20 +1835,6 @@ namespace etl
view.data() + view.size());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Compare with std::basic_string_view.
//*************************************************************************
template <typename TTraits>
int compare(const std::basic_string_view<T, TTraits>& view) const
{
return compare(p_buffer,
p_buffer + size(),
view.data(),
view.data() + view.size());
}
#endif
//*************************************************************************
/// Compare position / length with string.
//*************************************************************************
@ -2027,20 +1863,6 @@ namespace etl
view.data() + view.size());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Compare position / length with std::basic_string_view.
//*************************************************************************
template <typename TTraits>
int compare(size_type position, size_type length_, const std::basic_string_view<T, TTraits>& view) const
{
return compare(p_buffer + position,
p_buffer + position + length_,
view.data(),
view.data() + view.size());
}
#endif
//*************************************************************************
/// Compare position / length with string / subposition / sublength.
//*************************************************************************
@ -2078,27 +1900,6 @@ namespace etl
view.data() + subposition + sublength);
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Compare position / length with std::basic_string_view. / subposition / sublength.
//*************************************************************************
template <typename TTraits>
int compare(size_type position, size_type length_, const std::basic_string_view<T, TTraits>& view, size_type subposition, size_type sublength) const
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds));
// Limit the lengths.
length_ = etl::min(length_, size() - position);
sublength = etl::min(sublength, view.size() - subposition);
return compare(p_buffer + position,
p_buffer + position + length_,
view.data() + subposition,
view.data() + subposition + sublength);
}
#endif
//*************************************************************************
/// Compare with C string
//*************************************************************************
@ -2163,19 +1964,6 @@ namespace etl
return find_first_of(view.data(), position, view.size());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Find first of any of content within the string
///\param view The content to find
///\param pos The position to start searching from.
//*********************************************************************
template <typename TTraits>
size_type find_first_of(const std::basic_string_view<T, TTraits>& view, size_type position = 0) const
{
return find_first_of(view.data(), position, view.size());
}
#endif
//*********************************************************************
/// Find first of any of content within the string
///\param s Pointer to the content to find
@ -2253,19 +2041,6 @@ namespace etl
return find_last_of(view.data(), position, view.size());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Find last of any of content within the string
///\param view The content to find
///\param pos The position to start searching from.
//*********************************************************************
template <typename TTraits>
size_type find_last_of(const std::basic_string_view<T, TTraits>& view, size_type position = npos) const
{
return find_last_of(view.data(), position, view.size());
}
#endif
//*********************************************************************
/// Find last of any of content within the string
///\param s Pointer to the content to find
@ -2361,19 +2136,6 @@ namespace etl
return find_first_not_of(view.data(), position, view.size());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Find first not of any of content within the string
///\param view The content to find
///\param pos The position to start searching from.
//*********************************************************************
template <typename TTraits>
size_type find_first_not_of(const std::basic_string_view<T, TTraits>& view, size_type position = 0) const
{
return find_first_not_of(view.data(), position, view.size());
}
#endif
//*********************************************************************
/// Find first not of any of content within the string
///\param s Pointer to the content to not find
@ -2458,19 +2220,6 @@ namespace etl
return find_last_not_of(view.data(), position, view.size());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*********************************************************************
/// Find last not of any of content within the string
///\param view The content to find
///\param pos The position to start searching from.
//*********************************************************************
template <typename TTraits>
size_type find_last_not_of(const std::basic_string_view<T, TTraits>& view, size_type position = npos) const
{
return find_last_not_of(view.data(), position, view.size());
}
#endif
//*********************************************************************
/// Find last not of any of content within the string
///\param s The pointer to the content to find
@ -2574,19 +2323,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Assignment operator.
//*************************************************************************
template <typename TTraits>
ibasic_string& operator = (const std::basic_string_view<T, TTraits>& view)
{
assign(view);
return *this;
}
#endif
//*************************************************************************
/// += operator.
//*************************************************************************
@ -2608,19 +2344,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// += operator.
//*************************************************************************
template <typename TTraits>
ibasic_string& operator += (const std::basic_string_view<T, TTraits>& rhs)
{
append(rhs);
return *this;
}
#endif
//*************************************************************************
/// += operator.
//*************************************************************************

View File

@ -186,18 +186,6 @@ namespace etl
this->assign(view.begin(), view.end());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit string(const std::string_view& view)
: istring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->assign(view.begin(), view.end());
}
#endif
//*************************************************************************
/// Returns a sub-string.
///\param position The position of the first character. Default = 0.
@ -266,18 +254,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Assignment operator.
//*************************************************************************
string& operator = (const std::string_view& view)
{
this->assign(view);
return *this;
}
#endif
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
@ -406,18 +382,6 @@ namespace etl
this->assign(view.begin(), view.end());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit string_ext(const std::string_view& view, value_type* buffer, size_type buffer_size)
: istring(buffer, buffer_size - 1U)
{
this->assign(view.begin(), view.end());
}
#endif
//*************************************************************************
/// Constructor, from an iterator range.
///\tparam TIterator The iterator type.
@ -488,18 +452,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Assignment operator.
//*************************************************************************
string_ext& operator = (const std::string_view& view)
{
this->assign(view);
return *this;
}
#endif
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************

View File

@ -183,18 +183,6 @@ namespace etl
this->assign(view.begin(), view.end());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit u16string(const std::u16string_view& view)
: iu16string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->assign(view.begin(), view.end());
}
#endif
//*************************************************************************
/// Returns a sub-string.
///\param position The position of the first character. Default = 0.
@ -249,18 +237,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Assignment operator.
//*************************************************************************
u16string& operator = (const std::u16string_view& view)
{
this->assign(view);
return *this;
}
#endif
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
@ -409,18 +385,6 @@ namespace etl
this->assign(view.begin(), view.end());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit u16string_ext(const std::u16string_view& view, value_type* buffer, size_type buffer_size)
: iu16string(buffer, buffer_size - 1U)
{
this->assign(view.begin(), view.end());
}
#endif
//*************************************************************************
/// Assignment operator.
//*************************************************************************
@ -467,18 +431,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Assignment operator.
//*************************************************************************
u16string_ext& operator = (const std::u16string_view& view)
{
this->assign(view);
return *this;
}
#endif
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************

View File

@ -183,18 +183,6 @@ namespace etl
this->assign(view.begin(), view.end());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit u32string(const std::u32string_view& view)
: iu32string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->assign(view.begin(), view.end());
}
#endif
//*************************************************************************
/// Returns a sub-string.
///\param position The position of the first character. Default = 0.
@ -249,18 +237,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Assignment operator.
//*************************************************************************
u32string& operator = (const std::u32string_view& view)
{
this->assign(view);
return *this;
}
#endif
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
@ -409,18 +385,6 @@ namespace etl
this->assign(view.begin(), view.end());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit u32string_ext(const std::u32string_view& view, value_type* buffer, size_type buffer_size)
: iu32string(buffer, buffer_size - 1U)
{
this->assign(view.begin(), view.end());
}
#endif
//*************************************************************************
/// Assignment operator.
//*************************************************************************
@ -467,18 +431,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Assignment operator.
//*************************************************************************
u32string_ext& operator = (const std::u32string_view& view)
{
this->assign(view);
return *this;
}
#endif
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************

View File

@ -488,18 +488,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP20
//*************************************************************************
/// Assignment operator.
//*************************************************************************
u8string_ext& operator = (const std::u8string_view& view)
{
this->assign(view);
return *this;
}
#endif
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************

View File

@ -183,18 +183,6 @@ namespace etl
this->assign(view.begin(), view.end());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit wstring(const std::wstring_view& view)
: iwstring(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
{
this->assign(view.begin(), view.end());
}
#endif
//*************************************************************************
/// Returns a sub-string.
///\param position The position of the first character. Default = 0.
@ -249,18 +237,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Assignment operator.
//*************************************************************************
wstring& operator = (const std::wstring_view& view)
{
this->assign(view);
return *this;
}
#endif
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
@ -409,18 +385,6 @@ namespace etl
this->assign(view.begin(), view.end());
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit wstring_ext(const std::wstring_view& view, value_type* buffer, size_type buffer_size)
: iwstring(buffer, buffer_size - 1U)
{
this->assign(view.begin(), view.end());
}
#endif
//*************************************************************************
/// Assignment operator.
//*************************************************************************
@ -467,18 +431,6 @@ namespace etl
return *this;
}
#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Assignment operator.
//*************************************************************************
wstring_ext& operator = (const std::wstring_view& view)
{
this->assign(view);
return *this;
}
#endif
//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff