Skip to content

Commit

Permalink
Merge branch 'feature/#962-Request--allow-(overload)-string-append-a-…
Browse files Browse the repository at this point in the history
…string_view' into development

# Conflicts:
#	include/etl/basic_string.h
  • Loading branch information
jwellbelove committed Nov 30, 2024
2 parents fb13326 + d53ff4f commit f2099b5
Show file tree
Hide file tree
Showing 20 changed files with 12,423 additions and 3,696 deletions.
495 changes: 258 additions & 237 deletions include/etl/basic_string.h

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions include/etl/multi_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,15 @@ namespace etl
//*************************************************************************
pointer operator ->()
{
return &operator*();
return p_value;
}

//*************************************************************************
/// -> operator
//*************************************************************************
const_pointer operator ->() const
{
return &operator*();
return p_value;
}

//*************************************************************************
Expand Down
41 changes: 30 additions & 11 deletions include/etl/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ namespace etl
return *this;
}

//*************************************************************************
/// Assignment operator.
//*************************************************************************
string& operator = (const etl::string_view& view)
{
this->assign(view);

return *this;
}

//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
Expand Down Expand Up @@ -362,6 +372,16 @@ namespace etl
this->resize(count, c);
}

//*************************************************************************
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit string_ext(const etl::string_view& view, value_type* buffer, size_type buffer_size)
: istring(buffer, buffer_size - 1U)
{
this->assign(view.begin(), view.end());
}

//*************************************************************************
/// Constructor, from an iterator range.
///\tparam TIterator The iterator type.
Expand All @@ -386,16 +406,6 @@ namespace etl
}
#endif

//*************************************************************************
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit string_ext(const etl::string_view& view, value_type* buffer, size_type buffer_size)
: istring(buffer, buffer_size - 1U)
{
this->assign(view.begin(), view.end());
}

//*************************************************************************
/// Assignment operator.
//*************************************************************************
Expand All @@ -409,7 +419,6 @@ namespace etl
return *this;
}


//*************************************************************************
/// Assignment operator.
//*************************************************************************
Expand All @@ -433,6 +442,16 @@ namespace etl
return *this;
}

//*************************************************************************
/// Assignment operator.
//*************************************************************************
string_ext& operator = (const etl::string_view& view)
{
this->assign(view);

return *this;
}

//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
Expand Down
46 changes: 43 additions & 3 deletions include/etl/string_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ SOFTWARE.
#include "algorithm.h"
#include "private/minmax_push.h"

#if ETL_USING_STL && ETL_USING_CPP17
#include <string_view>
#endif

#include <stdint.h>

namespace etl
Expand Down Expand Up @@ -96,9 +100,9 @@ namespace etl
{
public:

typedef T value_type;
typedef TTraits traits_type;
typedef size_t size_type;
typedef T value_type;
typedef TTraits traits_type;
typedef size_t size_type;
typedef const T& const_reference;
typedef const T* const_pointer;
typedef const T* const_iterator;
Expand Down Expand Up @@ -163,6 +167,18 @@ namespace etl
{
}

#if ETL_USING_STL && ETL_USING_CPP17
//*************************************************************************
/// Constructor from std::basic string_view
//*************************************************************************
template <typename TStdTraits>
explicit ETL_CONSTEXPR basic_string_view(const std::basic_string_view<T, TStdTraits>& other) ETL_NOEXCEPT
: mbegin(other.data())
, mend(other.data() + other.size())
{
}
#endif

//*************************************************************************
/// Returns a const reference to the first element.
//*************************************************************************
Expand Down Expand Up @@ -747,6 +763,30 @@ namespace etl
return find_last_not_of(etl::basic_string_view<T, TTraits>(text), position);
}

//*********************************************************************
/// Checks that the view is within this string
//*********************************************************************
bool contains(const etl::basic_string_view<T, TTraits>& view) const
{
return find(view) != npos;
}

//*********************************************************************
/// Checks that text is within this string
//*********************************************************************
bool contains(const_pointer s) const
{
return find(s) != npos;
}

//*********************************************************************
/// Checks that character is within this string
//*********************************************************************
bool contains(value_type c) const
{
return find(c) != npos;
}

//*************************************************************************
/// Equality for string_view.
//*************************************************************************
Expand Down
25 changes: 22 additions & 3 deletions include/etl/u16string.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ namespace etl
return *this;
}

//*************************************************************************
/// Assignment operator.
//*************************************************************************
u16string& operator = (const etl::u16string_view& view)
{
this->assign(view);

return *this;
}

//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
Expand Down Expand Up @@ -366,8 +376,8 @@ namespace etl
#endif

//*************************************************************************
/// From u16string_view.
///\param view The u16string_view.
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit u16string_ext(const etl::u16string_view& view, value_type* buffer, size_type buffer_size)
: iu16string(buffer, buffer_size - 1U)
Expand All @@ -388,7 +398,6 @@ namespace etl
return *this;
}


//*************************************************************************
/// Assignment operator.
//*************************************************************************
Expand All @@ -412,6 +421,16 @@ namespace etl
return *this;
}

//*************************************************************************
/// Assignment operator.
//*************************************************************************
u16string_ext& operator = (const etl::u16string_view& view)
{
this->assign(view);

return *this;
}

//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
Expand Down
25 changes: 22 additions & 3 deletions include/etl/u32string.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ namespace etl
return *this;
}

//*************************************************************************
/// Assignment operator.
//*************************************************************************
u32string& operator = (const etl::u32string_view& view)
{
this->assign(view);

return *this;
}

//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
Expand Down Expand Up @@ -366,8 +376,8 @@ namespace etl
#endif

//*************************************************************************
/// From u32string_view.
///\param view The u32string_view.
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit u32string_ext(const etl::u32string_view& view, value_type* buffer, size_type buffer_size)
: iu32string(buffer, buffer_size - 1U)
Expand All @@ -388,7 +398,6 @@ namespace etl
return *this;
}


//*************************************************************************
/// Assignment operator.
//*************************************************************************
Expand All @@ -412,6 +421,16 @@ namespace etl
return *this;
}

//*************************************************************************
/// Assignment operator.
//*************************************************************************
u32string_ext& operator = (const etl::u32string_view& view)
{
this->assign(view);

return *this;
}

//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
Expand Down
21 changes: 20 additions & 1 deletion include/etl/u8string.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ namespace etl
return *this;
}

//*************************************************************************
/// Assignment operator.
//*************************************************************************
u8string& operator = (const etl::u8string_view& view)
{
this->assign(view);

return *this;
}

//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
Expand Down Expand Up @@ -409,7 +419,6 @@ namespace etl
return *this;
}


//*************************************************************************
/// Assignment operator.
//*************************************************************************
Expand All @@ -433,6 +442,16 @@ namespace etl
return *this;
}

//*************************************************************************
/// Assignment operator.
//*************************************************************************
u8string_ext& operator = (const etl::u8string_view& view)
{
this->assign(view);

return *this;
}

//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
Expand Down
25 changes: 22 additions & 3 deletions include/etl/wstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ namespace etl
return *this;
}

//*************************************************************************
/// Assignment operator.
//*************************************************************************
wstring& operator = (const etl::wstring_view& view)
{
this->assign(view);

return *this;
}

//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
Expand Down Expand Up @@ -366,8 +376,8 @@ namespace etl
#endif

//*************************************************************************
/// From wstring_view.
///\param view The wstring_view.
/// From string_view.
///\param view The string_view.
//*************************************************************************
explicit wstring_ext(const etl::wstring_view& view, value_type* buffer, size_type buffer_size)
: iwstring(buffer, buffer_size - 1U)
Expand All @@ -388,7 +398,6 @@ namespace etl
return *this;
}


//*************************************************************************
/// Assignment operator.
//*************************************************************************
Expand All @@ -412,6 +421,16 @@ namespace etl
return *this;
}

//*************************************************************************
/// Assignment operator.
//*************************************************************************
wstring_ext& operator = (const etl::wstring_view& view)
{
this->assign(view);

return *this;
}

//*************************************************************************
/// Fix the internal pointers after a low level memory copy.
//*************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions test/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ fi
# Set the sanitizer enable. Default OFF
#******************************************************************************
if [ "$4" = "S" ]; then
sanitize="ON"
sanitize="On"
else
sanitize="OFF"
sanitize="Off"
fi

#******************************************************************************
Expand Down
Loading

0 comments on commit f2099b5

Please sign in to comment.