diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index c35869c7..4bd24993 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -190,7 +190,7 @@ namespace etl /// Gets the current size of the string. ///\return The current size of the string. //************************************************************************* - ETL_CONSTEXPR14 size_type size() const + size_type size() const { return current_size; } @@ -199,7 +199,7 @@ namespace etl /// Gets the current size of the string. ///\return The current size of the string. //************************************************************************* - ETL_CONSTEXPR14 size_type length() const + size_type length() const { return current_size; } @@ -208,7 +208,7 @@ namespace etl /// Checks the 'empty' state of the string. ///\return true if empty. //************************************************************************* - ETL_CONSTEXPR14 bool empty() const + bool empty() const { return (current_size == 0); } @@ -217,7 +217,7 @@ namespace etl /// Checks the 'full' state of the string. ///\return true if full. //************************************************************************* - ETL_CONSTEXPR14 bool full() const + bool full() const { return current_size == CAPACITY; } @@ -226,7 +226,7 @@ namespace etl /// Returns the capacity of the string. ///\return The capacity of the string. //************************************************************************* - ETL_CONSTEXPR14 size_type capacity() const + size_type capacity() const { return CAPACITY; } @@ -235,7 +235,7 @@ namespace etl /// Returns the maximum possible size of the string. ///\return The maximum size of the string. //************************************************************************* - ETL_CONSTEXPR14 size_type max_size() const + size_type max_size() const { return CAPACITY; } @@ -244,7 +244,7 @@ namespace etl /// Returns the remaining capacity. ///\return The remaining capacity. //************************************************************************* - ETL_CONSTEXPR14 size_type available() const + size_type available() const { return max_size() - size(); } @@ -253,7 +253,7 @@ namespace etl /// Returns whether the string was truncated by the last operation. ///\return Whether the string was truncated by the last operation. //************************************************************************* - ETL_CONSTEXPR14 bool is_truncated() const + bool is_truncated() const { #if ETL_HAS_STRING_TRUNCATION_CHECKS return flags.test(); @@ -268,7 +268,7 @@ namespace etl ///\return Whether the string was truncated by the last operation. //************************************************************************* ETL_DEPRECATED - ETL_CONSTEXPR14 bool truncated() const + bool truncated() const { return is_truncated(); } @@ -296,7 +296,7 @@ namespace etl //************************************************************************* /// Gets the 'secure' state flag. //************************************************************************* - ETL_CONSTEXPR14 bool is_secure() const + bool is_secure() const { #if ETL_HAS_STRING_CLEAR_AFTER_USE return flags.test(); @@ -310,7 +310,7 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - ETL_CONSTEXPR14 string_base(size_type max_size_) + string_base(size_type max_size_) : current_size(0) , CAPACITY(max_size_) { @@ -329,7 +329,7 @@ namespace etl //************************************************************************* /// Destructor. //************************************************************************* - ETL_CONSTEXPR14 ~string_base() + ETL_CONSTEXPR20 ~string_base() { } @@ -378,7 +378,7 @@ namespace etl /// Returns a const_iterator to the beginning of the string. ///\return A const iterator to the beginning of the string. //********************************************************************* - ETL_CONSTEXPR14 const_iterator begin() const + const_iterator begin() const { return &p_buffer[0]; } @@ -396,7 +396,7 @@ namespace etl /// Returns a const_iterator to the end of the string. ///\return A const iterator to the end of the string. //********************************************************************* - ETL_CONSTEXPR14 const_iterator end() const + const_iterator end() const { return &p_buffer[current_size]; } @@ -405,7 +405,7 @@ namespace etl /// Returns a const_iterator to the beginning of the string. ///\return A const iterator to the beginning of the string. //********************************************************************* - ETL_CONSTEXPR14 const_iterator cbegin() const + const_iterator cbegin() const { return &p_buffer[0]; } @@ -414,7 +414,7 @@ namespace etl /// Returns a const_iterator to the end of the string. ///\return A const iterator to the end of the string. //********************************************************************* - ETL_CONSTEXPR14 const_iterator cend() const + const_iterator cend() const { return &p_buffer[current_size]; } @@ -432,7 +432,7 @@ namespace etl /// Returns a const reverse iterator to the reverse beginning of the string. ///\return Const iterator to the reverse beginning of the string. //********************************************************************* - ETL_CONSTEXPR14 const_reverse_iterator rbegin() const + const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); } @@ -441,7 +441,7 @@ namespace etl /// Returns a reverse iterator to the end + 1 of the string. ///\return Reverse iterator to the end + 1 of the string. //********************************************************************* - ETL_CONSTEXPR14 reverse_iterator rend() + reverse_iterator rend() { return reverse_iterator(begin()); } @@ -450,7 +450,7 @@ namespace etl /// Returns a const reverse iterator to the end + 1 of the string. ///\return Const reverse iterator to the end + 1 of the string. //********************************************************************* - ETL_CONSTEXPR14 const_reverse_iterator rend() const + const_reverse_iterator rend() const { return const_reverse_iterator(begin()); } @@ -459,7 +459,7 @@ namespace etl /// Returns a const reverse iterator to the reverse beginning of the string. ///\return Const reverse iterator to the reverse beginning of the string. //********************************************************************* - ETL_CONSTEXPR14 const_reverse_iterator crbegin() const + const_reverse_iterator crbegin() const { return const_reverse_iterator(cend()); } @@ -468,7 +468,7 @@ namespace etl /// Returns a const reverse iterator to the end + 1 of the string. ///\return Const reverse iterator to the end + 1 of the string. //********************************************************************* - ETL_CONSTEXPR14 const_reverse_iterator crend() const + const_reverse_iterator crend() const { return const_reverse_iterator(cbegin()); } @@ -568,7 +568,7 @@ namespace etl ///\param i The index. ///\return A const reference to the value at index 'i' //********************************************************************* - ETL_CONSTEXPR14 const_reference operator [](size_type i) const + const_reference operator [](size_type i) const { return p_buffer[i]; } @@ -591,7 +591,7 @@ namespace etl ///\param i The index. ///\return A const reference to the value at index 'i' //********************************************************************* - ETL_CONSTEXPR14 const_reference at(size_type i) const + const_reference at(size_type i) const { ETL_ASSERT(i < size(), ETL_ERROR(string_out_of_bounds)); return p_buffer[i]; @@ -610,7 +610,7 @@ namespace etl /// Returns a const reference to the first element. ///\return A const reference to the first element. //********************************************************************* - ETL_CONSTEXPR14 const_reference front() const + const_reference front() const { return p_buffer[0]; } @@ -628,7 +628,7 @@ namespace etl /// Returns a const reference to the last element. ///\return A const reference to the last element. //********************************************************************* - ETL_CONSTEXPR14 const_reference back() const + const_reference back() const { return p_buffer[current_size - 1]; } @@ -664,7 +664,7 @@ namespace etl /// Returns a const pointer to the beginning of the string data. ///\return A const pointer to the beginning of the string data. //********************************************************************* - ETL_CONSTEXPR14 const_pointer data_end() const + const_pointer data_end() const { return p_buffer + current_size; } @@ -1371,7 +1371,7 @@ namespace etl //********************************************************************* /// Return a pointer to a C string. //********************************************************************* - ETL_CONSTEXPR14 const_pointer c_str() const + const_pointer c_str() const { return p_buffer; } @@ -1382,7 +1382,7 @@ namespace etl ///\param count The number of characters to copy. ///\param pos The position to start copying from. //********************************************************************* - ETL_CONSTEXPR14 size_type copy(pointer dest, size_type count, size_type pos = 0) const + size_type copy(pointer dest, size_type count, size_type pos = 0) const { if (pos < size()) { @@ -1410,7 +1410,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find(const ibasic_string& str, size_type pos = 0) const + size_type find(const ibasic_string& str, size_type pos = 0) const { return find_impl(str.begin(), str.end(), str.size(), pos); } @@ -1421,7 +1421,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - ETL_CONSTEXPR14 size_type find(const etl::basic_string_view& view, size_type pos = 0) const + size_type find(const etl::basic_string_view& view, size_type pos = 0) const { return find_impl(view.begin(), view.end(), view.size(), pos); } @@ -1431,7 +1431,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find(const_pointer s, size_type pos = 0) const + size_type find(const_pointer s, size_type pos = 0) const { size_t sz = etl::strlen(s); @@ -1444,7 +1444,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - ETL_CONSTEXPR14 size_type find(const_pointer s, size_type pos, size_type n) const + size_type find(const_pointer s, size_type pos, size_type n) const { size_t sz = etl::strlen(s); @@ -1456,7 +1456,7 @@ namespace etl ///\param c The character to find. ///\param position The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find(T c, size_type position = 0) const + size_type find(T c, size_type position = 0) const { const_iterator i = etl::find(begin() + position, end(), c); @@ -1475,7 +1475,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type rfind(const ibasic_string& str, size_type position = npos) const + size_type rfind(const ibasic_string& str, size_type position = npos) const { return rfind_impl(str.rbegin(), str.rend(), str.size(), position); } @@ -1486,7 +1486,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - ETL_CONSTEXPR14 size_type rfind(const etl::basic_string_view& view, size_type pos = npos) const + size_type rfind(const etl::basic_string_view& view, size_type pos = npos) const { return rfind_impl(view.rbegin(), view.rend(), view.size(), pos); } @@ -1496,7 +1496,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type rfind(const_pointer s, size_type position = npos) const + size_type rfind(const_pointer s, size_type position = npos) const { size_type len = etl::strlen(s); @@ -1511,7 +1511,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type rfind(const_pointer s, size_type position, size_type length_) const + size_type rfind(const_pointer s, size_type position, size_type length_) const { const_reverse_iterator srbegin(s + length_); const_reverse_iterator srend(s); @@ -1524,7 +1524,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type rfind(T c, size_type position = npos) const + size_type rfind(T c, size_type position = npos) const { if (position >= size()) { @@ -1548,7 +1548,7 @@ namespace etl //********************************************************************* /// Checks that the string is within this string //********************************************************************* - ETL_CONSTEXPR14 bool contains(const etl::ibasic_string& str) const + bool contains(const etl::ibasic_string& str) const { return find(str) != npos; } @@ -1557,7 +1557,7 @@ namespace etl /// Checks that the view is within this string //********************************************************************* template - ETL_CONSTEXPR14 bool contains(const etl::basic_string_view& view) const + bool contains(const etl::basic_string_view& view) const { return find(view) != npos; } @@ -1565,7 +1565,7 @@ namespace etl //********************************************************************* /// Checks that text is within this string //********************************************************************* - ETL_CONSTEXPR14 bool contains(const_pointer s) const + bool contains(const_pointer s) const { return find(s) != npos; } @@ -1573,7 +1573,7 @@ namespace etl //********************************************************************* /// Checks that character is within this string //********************************************************************* - ETL_CONSTEXPR14 bool contains(value_type c) const + bool contains(value_type c) const { return find(c) != npos; } @@ -1581,7 +1581,7 @@ namespace etl //********************************************************************* /// Checks that the string is the start of this string //********************************************************************* - ETL_CONSTEXPR14 bool starts_with(const etl::ibasic_string& str) const + bool starts_with(const etl::ibasic_string& str) const { return compare(0, str.size(), str) == 0; } @@ -1590,7 +1590,7 @@ namespace etl /// Checks that the view is the start of this string //********************************************************************* template - ETL_CONSTEXPR14 bool starts_with(const etl::basic_string_view& view) const + bool starts_with(const etl::basic_string_view& view) const { return compare(0, view.size(), view) == 0; } @@ -1598,7 +1598,7 @@ namespace etl //********************************************************************* /// Checks that the string is the start of this string //********************************************************************* - ETL_CONSTEXPR14 bool starts_with(const_pointer s) const + bool starts_with(const_pointer s) const { size_t len = etl::strlen(s); @@ -1608,7 +1608,7 @@ namespace etl //********************************************************************* /// Checks that the character is the start of this string //********************************************************************* - ETL_CONSTEXPR14 bool starts_with(value_type c) const + bool starts_with(value_type c) const { return !empty() && (front() == c); } @@ -1616,7 +1616,7 @@ namespace etl //********************************************************************* /// Checks that the string is the end of this string //********************************************************************* - ETL_CONSTEXPR14 bool ends_with(const etl::ibasic_string& str) const + bool ends_with(const etl::ibasic_string& str) const { if (str.size() > size()) { @@ -1630,7 +1630,7 @@ namespace etl /// Checks that the view is the end of this string //********************************************************************* template - ETL_CONSTEXPR14 bool ends_with(const etl::basic_string_view& view) const + bool ends_with(const etl::basic_string_view& view) const { if (view.size() > size()) { @@ -1643,7 +1643,7 @@ namespace etl //********************************************************************* /// Checks that the string is the end of this string //********************************************************************* - ETL_CONSTEXPR14 bool ends_with(const_pointer s) const + bool ends_with(const_pointer s) const { size_t len = etl::strlen(s); @@ -1658,7 +1658,7 @@ namespace etl //********************************************************************* /// Checks that the character is the end of this string //********************************************************************* - ETL_CONSTEXPR14 bool ends_with(value_type c) const + bool ends_with(value_type c) const { return !empty() && (back() == c); } @@ -1949,7 +1949,7 @@ namespace etl //************************************************************************* /// Compare with string. //************************************************************************* - ETL_CONSTEXPR14 int compare(const ibasic_string& str) const + int compare(const ibasic_string& str) const { return compare(p_buffer, p_buffer + size(), @@ -1961,7 +1961,7 @@ namespace etl /// Compare with etl::basic_string_view. //************************************************************************* template - ETL_CONSTEXPR14 int compare(const etl::basic_string_view& view) const + int compare(const etl::basic_string_view& view) const { return compare(p_buffer, p_buffer + size(), @@ -1972,7 +1972,7 @@ namespace etl //************************************************************************* /// Compare position / length with string. //************************************************************************* - ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const ibasic_string& str) const + int compare(size_type position, size_type length_, const ibasic_string& str) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1989,7 +1989,7 @@ namespace etl /// Compare position / length with etl::basic_string_view. //************************************************************************* template - ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const etl::basic_string_view& view) const + int compare(size_type position, size_type length_, const etl::basic_string_view& view) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -2000,7 +2000,7 @@ namespace etl //************************************************************************* /// Compare position / length with string / subposition / sublength. //************************************************************************* - ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const ibasic_string& str, size_type subposition, size_type sublength) const + int compare(size_type position, size_type length_, const ibasic_string& str, size_type subposition, size_type sublength) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); @@ -2019,7 +2019,7 @@ namespace etl /// Compare position / length with etl::basic_string_view. / subposition / sublength. //************************************************************************* template - ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) const + int compare(size_type position, size_type length_, const etl::basic_string_view& 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)); @@ -2037,7 +2037,7 @@ namespace etl //************************************************************************* /// Compare with C string //************************************************************************* - ETL_CONSTEXPR14 int compare(const value_type* s) const + int compare(const value_type* s) const { return compare(p_buffer, p_buffer + size(), @@ -2048,7 +2048,7 @@ namespace etl //************************************************************************* /// Compare position / length with C string. //************************************************************************* - ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const_pointer s) const + int compare(size_type position, size_type length_, const_pointer s) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -2059,7 +2059,7 @@ namespace etl //************************************************************************* /// Compare position / length with C string / n. //************************************************************************* - ETL_CONSTEXPR14 int compare(size_type position, size_type length_, const_pointer s, size_type n) const + int compare(size_type position, size_type length_, const_pointer s, size_type n) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -2072,7 +2072,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_of(const ibasic_string& str, size_type position = 0) const + size_type find_first_of(const ibasic_string& str, size_type position = 0) const { return find_first_of(str.c_str(), position, str.size()); } @@ -2082,7 +2082,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_of(const_pointer s, size_type position = 0) const + size_type find_first_of(const_pointer s, size_type position = 0) const { return find_first_of(s, position, etl::strlen(s)); } @@ -2093,7 +2093,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - ETL_CONSTEXPR14 size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const + size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const { return find_first_of(view.data(), position, view.size()); } @@ -2104,7 +2104,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_of(const_pointer s, size_type position, size_type n) const + size_type find_first_of(const_pointer s, size_type position, size_type n) const { if (position < size()) { @@ -2128,7 +2128,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_of(value_type c, size_type position = 0) const + size_type find_first_of(value_type c, size_type position = 0) const { if (position < size()) { @@ -2149,7 +2149,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_of(const ibasic_string& str, size_type position = npos) const + size_type find_last_of(const ibasic_string& str, size_type position = npos) const { return find_last_of(str.c_str(), position, str.size()); } @@ -2159,7 +2159,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_of(const_pointer s, size_type position = npos) const + size_type find_last_of(const_pointer s, size_type position = npos) const { return find_last_of(s, position, etl::strlen(s)); } @@ -2170,7 +2170,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - ETL_CONSTEXPR14 size_type find_last_of(const etl::basic_string_view& view, size_type position = npos) const + size_type find_last_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_of(view.data(), position, view.size()); } @@ -2181,7 +2181,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_of(const_pointer s, size_type position, size_type n) const + size_type find_last_of(const_pointer s, size_type position, size_type n) const { if (empty()) { @@ -2214,7 +2214,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_of(value_type c, size_type position = npos) const + size_type find_last_of(value_type c, size_type position = npos) const { if (empty()) { @@ -2244,7 +2244,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_not_of(const ibasic_string& str, size_type position = 0) const + size_type find_first_not_of(const ibasic_string& str, size_type position = 0) const { return find_first_not_of(str.c_str(), position, str.size()); } @@ -2254,7 +2254,7 @@ namespace etl ///\param s Pointer to the content to not find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_not_of(const_pointer s, size_type position = 0) const + size_type find_first_not_of(const_pointer s, size_type position = 0) const { return find_first_not_of(s, position, etl::strlen(s)); } @@ -2265,7 +2265,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - ETL_CONSTEXPR14 size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const + size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const { return find_first_not_of(view.data(), position, view.size()); } @@ -2276,7 +2276,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_not_of(const_pointer s, size_type position, size_type n) const + size_type find_first_not_of(const_pointer s, size_type position, size_type n) const { if (position < size()) { @@ -2307,7 +2307,7 @@ namespace etl ///\param c The character to not find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_first_not_of(value_type c, size_type position = 0) const + size_type find_first_not_of(value_type c, size_type position = 0) const { if (position < size()) { @@ -2328,7 +2328,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_not_of(const ibasic_string& str, size_type position = npos) const + size_type find_last_not_of(const ibasic_string& str, size_type position = npos) const { return find_last_not_of(str.c_str(), position, str.size()); } @@ -2338,7 +2338,7 @@ namespace etl ///\param s The pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_not_of(const_pointer s, size_type position = npos) const + size_type find_last_not_of(const_pointer s, size_type position = npos) const { return find_last_not_of(s, position, etl::strlen(s)); } @@ -2349,7 +2349,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - ETL_CONSTEXPR14 size_type find_last_not_of(const etl::basic_string_view& view, size_type position = npos) const + size_type find_last_not_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_not_of(view.data(), position, view.size()); } @@ -2360,7 +2360,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to use. //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_not_of(const_pointer s, size_type position, size_type n) const + size_type find_last_not_of(const_pointer s, size_type position, size_type n) const { if (empty()) { @@ -2398,7 +2398,7 @@ namespace etl //********************************************************************* // //********************************************************************* - ETL_CONSTEXPR14 size_type find_last_not_of(value_type c, size_type position = npos) const + size_type find_last_not_of(value_type c, size_type position = npos) const { if (empty()) { @@ -2536,7 +2536,7 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - ETL_CONSTEXPR14 ibasic_string(T* p_buffer_, size_type MAX_SIZE_) + ibasic_string(T* p_buffer_, size_type MAX_SIZE_) : string_base(MAX_SIZE_), p_buffer(p_buffer_) { @@ -2545,7 +2545,7 @@ namespace etl //********************************************************************* /// Initialise the string. //********************************************************************* - ETL_CONSTEXPR14 void initialise() + void initialise() { current_size = 0U; p_buffer[0] = 0; @@ -2567,7 +2567,7 @@ namespace etl //************************************************************************* /// Compare helper function //************************************************************************* - ETL_CONSTEXPR14 static int compare(const_pointer first1, const_pointer last1, + static int compare(const_pointer first1, const_pointer last1, const_pointer first2, const_pointer last2) { typedef typename etl::make_unsigned::type type; @@ -2644,7 +2644,7 @@ namespace etl #else protected: #endif - ETL_CONSTEXPR14 ~ibasic_string() + ETL_CONSTEXPR20 ~ibasic_string() { #if ETL_HAS_STRING_CLEAR_AFTER_USE if (is_secure()) @@ -2659,7 +2659,7 @@ namespace etl //************************************************************************* /// Convert from const_iterator to iterator //************************************************************************* - ETL_CONSTEXPR14 iterator to_iterator(const_iterator itr) const + iterator to_iterator(const_iterator itr) const { return const_cast(itr); } @@ -2782,7 +2782,7 @@ namespace etl /// Common implementation for 'find'. //************************************************************************* template - ETL_CONSTEXPR14 size_type find_impl(TIterator first, TIterator last, size_type sz, size_type pos = 0) const + size_type find_impl(TIterator first, TIterator last, size_type sz, size_type pos = 0) const { if ((pos + sz) > size()) { @@ -2805,7 +2805,7 @@ namespace etl /// Common implementation for 'rfind'. //************************************************************************* template - ETL_CONSTEXPR14 size_type rfind_impl(TIterator rfirst, TIterator rlast, size_type sz, size_type pos = 0) const + size_type rfind_impl(TIterator rfirst, TIterator rlast, size_type sz, size_type pos = 0) const { if (sz > size()) { diff --git a/include/etl/const_basic_string.h b/include/etl/const_basic_string.h new file mode 100644 index 00000000..142933c0 --- /dev/null +++ b/include/etl/const_basic_string.h @@ -0,0 +1,313 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CONST_BASIC_STRING_INCLUDED +#define ETL_CONST_BASIC_STRING_INCLUDED + +#include "platform.h" +#include "iterator.h" +#include "char_traits.h" + +#if ETL_USING_CPP14 + +namespace etl +{ + //*************************************************************************** + /// A string implementation that uses a fixed size external const buffer. + ///\ingroup string + //*************************************************************************** + template + class const_basic_string + { + public: + + using value_type = T; + using size_type = size_t; + using const_pointer = const value_type*; + using const_reference = const value_type&; + using const_iterator = const value_type*; + + using const_reverse_iterator = etl::reverse_iterator; + + //************************************************************************* + /// Gets the size of the string. + //************************************************************************* + ETL_NODISCARD + constexpr size_t size() const noexcept + { + return buffer_size; + } + + //************************************************************************* + /// Gets the size of the string. + //************************************************************************* + ETL_NODISCARD + constexpr size_t length() const noexcept + { + return buffer_size; + } + + //************************************************************************* + /// Gets the capacity of the string. + //************************************************************************* + ETL_NODISCARD + constexpr size_t capacity() const noexcept + { + return buffer_size; + } + + //************************************************************************* + /// Gets the maximum size of the string. + //************************************************************************* + ETL_NODISCARD + constexpr size_t max_size() const noexcept + { + return buffer_size; + } + + //************************************************************************* + /// Gets the amount of free space in the string. + //************************************************************************* + ETL_NODISCARD + constexpr size_t available() const noexcept + { + return 0U; + } + + //************************************************************************* + /// Gets the start of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_iterator begin() const noexcept + { + return p_buffer; + } + + //************************************************************************* + /// Gets the start of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_iterator cbegin() const noexcept + { + return p_buffer; + } + + //************************************************************************* + /// Gets the reverse start of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_reverse_iterator rbegin() const noexcept + { + return const_reverse_iterator(end()); + } + + //************************************************************************* + /// Gets the reverse start of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_reverse_iterator crbegin() const noexcept + { + return const_reverse_iterator(end()); + } + + //************************************************************************* + /// Gets the end of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_iterator end() const noexcept + { + return p_buffer + buffer_size; + } + + //************************************************************************* + /// Gets the end of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_iterator cend() const noexcept + { + return p_buffer + buffer_size; + } + + //************************************************************************* + /// Gets the reverse end of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_reverse_iterator rend() const noexcept + { + return const_reverse_iterator(begin()); + } + + //************************************************************************* + /// Gets the reverse end of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_reverse_iterator crend() const noexcept + { + return const_reverse_iterator(begin()); + } + + //************************************************************************* + /// Gets the start of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_pointer data() const noexcept + { + return p_buffer; + } + + //************************************************************************* + /// Gets the end of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_pointer data_end() const noexcept + { + return p_buffer + buffer_size; + } + + //********************************************************************* + /// Return a pointer to a C string. + //********************************************************************* + ETL_NODISCARD + constexpr const_pointer c_str() const + { + return p_buffer; + } + + //************************************************************************* + /// Is the string empty? + //************************************************************************* + ETL_NODISCARD + constexpr bool empty() const noexcept + { + return buffer_size == 0U; + } + + //************************************************************************* + /// Is the string full? + //************************************************************************* + ETL_NODISCARD + constexpr bool full() const noexcept + { + return true; + } + + //************************************************************************* + /// Is the string truncated? + //************************************************************************* + ETL_NODISCARD + constexpr bool is_truncated() const noexcept + { + return truncated_state; + } + + //************************************************************************* + /// Is the string secure? + //************************************************************************* + ETL_NODISCARD + constexpr bool is_secure() const noexcept + { + return false; + } + + //************************************************************************* + /// Returns a const reference to the value at the index. + //************************************************************************* + ETL_NODISCARD + constexpr const_reference operator [](int i) const noexcept + { + return p_buffer[i]; + } + + //************************************************************************* + /// Returns a const reference to the value at the index. + //************************************************************************* + ETL_NODISCARD + constexpr const_reference at(int i) const noexcept + { + return p_buffer[i]; + } + + //************************************************************************* + /// Returns a const reference to the value at the front of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_reference front() const noexcept + { + return p_buffer[0]; + } + + //************************************************************************* + /// Returns a const reference to the value at the front of the string. + //************************************************************************* + ETL_NODISCARD + constexpr const_reference back() const noexcept + { + return p_buffer[buffer_size - 1U]; + } + + protected: + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_basic_string(const value_type* buffer, size_t buff_size, bool is_truncated) + : p_buffer(buffer) + , buffer_size(buff_size) + , truncated_state(is_truncated) + { + } + + private: + + const value_type* p_buffer; + const size_t buffer_size; + const bool truncated_state; + }; + + //*************************************************************************** + /// Operator overload to write to std basic_ostream + ///\param os Reference to the output stream. + ///\param str Reference to the string to write. + ///\return Reference to the output stream, for chaining write operations. + ///\ingroup string + //*************************************************************************** +#if ETL_USING_STL + template + std::basic_ostream > &operator<<(std::basic_ostream > &os, + const etl::const_basic_string& str) + { + os.write(str.data(), str.size()); + return os; + } +#endif +} + +#endif +#endif diff --git a/include/etl/const_string.h b/include/etl/const_string.h index 9ce057fe..123164b6 100644 --- a/include/etl/const_string.h +++ b/include/etl/const_string.h @@ -32,111 +32,63 @@ SOFTWARE. #define ETL_CONST_STRING_INCLUDED #include "platform.h" -#include "string.h" -#include "hash.h" +#include "iterator.h" +#include "char_traits.h" +#include "const_basic_string.h" -#include - -#include "private/minmax_push.h" +#if ETL_USING_CPP14 namespace etl { //*************************************************************************** - /// A string implementation that uses a fixed size external buffer. + /// A string implementation that uses a fixed size external const buffer. ///\ingroup string //*************************************************************************** - class const_string : public istring + class const_string : public etl::const_basic_string { public: - typedef istring base_type; - typedef istring interface_type; + using value_type = const_basic_string::value_type; + using size_type = const_basic_string::size_type; + using const_pointer = const_basic_string::const_pointer; + using const_reference = const_basic_string::const_reference; + using const_iterator = const_basic_string::const_iterator; - typedef istring::value_type value_type; - typedef istring::size_type size_type; + using const_reverse_iterator = const_basic_string::const_reverse_iterator; //************************************************************************* /// Constructor. //************************************************************************* - constexpr const_string(const value_type* buffer) - : istring(const_cast(buffer), etl::strlen(buffer)) - { - this->current_size = etl::strlen(buffer); + constexpr const_string(const value_type* buffer, bool is_truncated = false) + : const_basic_string(buffer, etl::strlen(buffer), is_truncated) + { } //************************************************************************* /// Constructor. //************************************************************************* - constexpr const_string(const value_type* buffer, size_t length) - : istring(const_cast(buffer), length) + constexpr const_string(const value_type* buffer, size_t length, bool is_truncated = false) + : const_basic_string(buffer, length, is_truncated) { - this->current_size = length; } //************************************************************************* /// Constructor. //************************************************************************* - constexpr const_string(const value_type* buffer, const value_type* buffer_end) - : istring(const_cast(buffer), buffer_end - buffer) + constexpr const_string(const value_type* buffer, const value_type* buffer_end, bool is_truncated = false) + : const_basic_string(buffer, buffer_end - buffer, is_truncated) { - this->current_size = buffer_end - buffer; - } - - //************************************************************************* - /// Constructor. - //************************************************************************* - constexpr const_string(const etl::string_view& view) - : istring(const_cast(view.data()), view.size()) - { - this->current_size = view.size(); } //************************************************************************* /// Copy constructor. //************************************************************************* constexpr const_string(const etl::const_string& other) - : istring(const_cast(other.data()), other.size()) - { - this->current_size = other.size(); - } - - //************************************************************************* - /// Returns a sub-string. - ///\param position The position of the first character. Default = 0. - ///\param length The number of characters. Default = npos. - //************************************************************************* - constexpr etl::const_string substr(size_type position = 0, size_type length_ = npos) const - { - if (position < this->size()) - { - length_ = etl::min(length_, this->size() - position); - - return etl::const_string(data() + position, length_); - } - - return etl::const_string(""); - } - - //************************************************************************* - /// Fix the internal pointers after a low level memory copy. - //************************************************************************* -#if ETL_HAS_ISTRING_REPAIR - constexpr virtual void repair() ETL_OVERRIDE -#else - constexpr void repair() -#endif + : const_basic_string(other.data(), other.size(), other.is_truncated()) { } - - private: - - //************************************************************************* - /// Deleted. - //************************************************************************* - //const_string(const const_string& other) ETL_DELETE; }; } -#include "private/minmax_pop.h" - +#endif #endif diff --git a/include/etl/const_u16string.h b/include/etl/const_u16string.h new file mode 100644 index 00000000..ce98322a --- /dev/null +++ b/include/etl/const_u16string.h @@ -0,0 +1,92 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CONST_U16STRING_INCLUDED +#define ETL_CONST_U16STRING_INCLUDED + +#include "platform.h" +#include "const_basic_string.h" + +#if ETL_USING_CPP14 + +namespace etl +{ + //*************************************************************************** + /// A string implementation that uses a fixed size external const buffer. + ///\ingroup string + //*************************************************************************** + class const_u16string : public etl::const_basic_string + { + public: + + using value_type = const_basic_string::value_type; + using size_type = const_basic_string::size_type; + using const_pointer = const_basic_string::const_pointer; + using const_reference = const_basic_string::const_reference; + using const_iterator = const_basic_string::const_iterator; + + using const_reverse_iterator = const_basic_string::const_reverse_iterator; + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u16string(const value_type* buffer, bool is_truncated = false) + : const_basic_string(buffer, etl::strlen(buffer), is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u16string(const value_type* buffer, size_t length, bool is_truncated = false) + : const_basic_string(buffer, length, is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u16string(const value_type* buffer, const value_type* buffer_end, bool is_truncated = false) + : const_basic_string(buffer, buffer_end - buffer, is_truncated) + { + } + + //************************************************************************* + /// Copy constructor. + //************************************************************************* + constexpr const_u16string(const etl::const_u16string& other) + : const_basic_string(other.data(), other.size(), other.is_truncated()) + { + } + }; +} + +#endif +#endif diff --git a/include/etl/const_u32string.h b/include/etl/const_u32string.h new file mode 100644 index 00000000..53b32dc0 --- /dev/null +++ b/include/etl/const_u32string.h @@ -0,0 +1,92 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CONST_U32STRING_INCLUDED +#define ETL_CONST_U32STRING_INCLUDED + +#include "platform.h" +#include "const_basic_string.h" + +#if ETL_USING_CPP14 + +namespace etl +{ + //*************************************************************************** + /// A string implementation that uses a fixed size external const buffer. + ///\ingroup string + //*************************************************************************** + class const_u32string : public etl::const_basic_string + { + public: + + using value_type = const_basic_string::value_type; + using size_type = const_basic_string::size_type; + using const_pointer = const_basic_string::const_pointer; + using const_reference = const_basic_string::const_reference; + using const_iterator = const_basic_string::const_iterator; + + using const_reverse_iterator = const_basic_string::const_reverse_iterator; + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u32string(const value_type* buffer, bool is_truncated = false) + : const_basic_string(buffer, etl::strlen(buffer), is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u32string(const value_type* buffer, size_t length, bool is_truncated = false) + : const_basic_string(buffer, length, is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u32string(const value_type* buffer, const value_type* buffer_end, bool is_truncated = false) + : const_basic_string(buffer, buffer_end - buffer, is_truncated) + { + } + + //************************************************************************* + /// Copy constructor. + //************************************************************************* + constexpr const_u32string(const etl::const_u32string& other) + : const_basic_string(other.data(), other.size(), other.is_truncated()) + { + } + }; +} + +#endif +#endif diff --git a/include/etl/const_u8string.h b/include/etl/const_u8string.h new file mode 100644 index 00000000..08d01581 --- /dev/null +++ b/include/etl/const_u8string.h @@ -0,0 +1,94 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CONST_U8STRING_INCLUDED +#define ETL_CONST_U8STRING_INCLUDED + +#include "platform.h" +#include "const_basic_string.h" + +#if ETL_USING_CPP14 + +#if ETL_HAS_CHAR8_T +namespace etl +{ + //*************************************************************************** + /// A string implementation that uses a fixed size external const buffer. + ///\ingroup string + //*************************************************************************** + class const_u8string : public etl::const_basic_string + { + public: + + using value_type = const_basic_string::value_type; + using size_type = const_basic_string::size_type; + using const_pointer = const_basic_string::const_pointer; + using const_reference = const_basic_string::const_reference; + using const_iterator = const_basic_string::const_iterator; + + using const_reverse_iterator = const_basic_string::const_reverse_iterator; + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u8string(const value_type* buffer, bool is_truncated = false) + : const_basic_string(buffer, etl::strlen(buffer), is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u8string(const value_type* buffer, size_t length, bool is_truncated = false) + : const_basic_string(buffer, length, is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_u8string(const value_type* buffer, const value_type* buffer_end, bool is_truncated = false) + : const_basic_string(buffer, buffer_end - buffer, is_truncated) + { + } + + //************************************************************************* + /// Copy constructor. + //************************************************************************* + constexpr const_u8string(const etl::const_u8string& other) + : const_basic_string(other.data(), other.size(), other.is_truncated()) + { + } + }; +} + +#endif +#endif +#endif diff --git a/include/etl/const_wstring.h b/include/etl/const_wstring.h new file mode 100644 index 00000000..b1d866b3 --- /dev/null +++ b/include/etl/const_wstring.h @@ -0,0 +1,92 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_CONST_WSTRING_INCLUDED +#define ETL_CONST_WSTRING_INCLUDED + +#include "platform.h" +#include "const_basic_string.h" + +#if ETL_USING_CPP14 + +namespace etl +{ + //*************************************************************************** + /// A string implementation that uses a fixed size external const buffer. + ///\ingroup string + //*************************************************************************** + class const_wstring : public etl::const_basic_string + { + public: + + using value_type = const_basic_string::value_type; + using size_type = const_basic_string::size_type; + using const_pointer = const_basic_string::const_pointer; + using const_reference = const_basic_string::const_reference; + using const_iterator = const_basic_string::const_iterator; + + using const_reverse_iterator = const_basic_string::const_reverse_iterator; + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_wstring(const value_type* buffer, bool is_truncated = false) + : const_basic_string(buffer, etl::strlen(buffer), is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_wstring(const value_type* buffer, size_t length, bool is_truncated = false) + : const_basic_string(buffer, length, is_truncated) + { + } + + //************************************************************************* + /// Constructor. + //************************************************************************* + constexpr const_wstring(const value_type* buffer, const value_type* buffer_end, bool is_truncated = false) + : const_basic_string(buffer, buffer_end - buffer, is_truncated) + { + } + + //************************************************************************* + /// Copy constructor. + //************************************************************************* + constexpr const_wstring(const etl::const_wstring& other) + : const_basic_string(other.data(), other.size(), other.is_truncated()) + { + } + }; +} + +#endif +#endif diff --git a/include/etl/string_view.h b/include/etl/string_view.h index b285de94..f35bbac4 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -40,6 +40,7 @@ SOFTWARE. #include "integral_limits.h" #include "hash.h" #include "basic_string.h" +#include "const_basic_string.h" #include "algorithm.h" #include "private/minmax_push.h" @@ -138,6 +139,17 @@ namespace etl { } +#if ETL_USING_CPP14 + //************************************************************************* + /// Construct from const_string. + //************************************************************************* + ETL_CONSTEXPR basic_string_view(const etl::const_basic_string& str) + : mbegin(str.begin()) + , mend(str.end()) + { + } +#endif + //************************************************************************* /// Construct from T*. //************************************************************************* diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 61c01e47..a41727fd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,6 +61,11 @@ add_executable(etl_tests test_const_map_constexpr.cpp test_const_multimap.cpp test_const_multimap_constexpr.cpp + test_const_string_char.cpp + test_const_string_u16.cpp + test_const_string_u32.cpp + test_const_string_u8.cpp + test_const_string_wchar_t.cpp test_char_traits.cpp test_checksum.cpp test_chrono_clocks.cpp diff --git a/test/test_const_string_char.cpp b/test/test_const_string_char.cpp index 6cdecc68..84417677 100644 --- a/test/test_const_string_char.cpp +++ b/test/test_const_string_char.cpp @@ -36,67 +36,36 @@ SOFTWARE. #include "etl/const_string.h" #include "etl/string_view.h" +#if ETL_USING_CPP14 + #undef STR #define STR(x) x namespace { - bool compares_agree(int result1, int result2) + SUITE(test_const_string_char) { - return ((result1 < 0) && (result2 < 0)) || - ((result1 == 0) && (result2 == 0)) || - ((result1 > 0) && (result2 > 0)); - } + using Text = etl::const_string; + using View = etl::string_view; - SUITE(test_string_char) - { - using Text = etl::const_string; - using IText = etl::istring; using TextSTD = std::string; - using View = etl::string_view; - constexpr const char* text_pointer = STR("Hello World"); - - static constexpr const char* ccp_hello = STR("Hello"); - static constexpr const char* ccp_world = STR("World"); - static constexpr const char* ccp_worls = STR("Worls"); - - static constexpr Text text_he(STR("He")); - static constexpr Text text_llo_world(STR("llo World")); - static constexpr Text text_hello(STR("Hello")); - static constexpr Text text_word(STR("Word")); - static constexpr Text text_rd(STR("rd")); - - static constexpr Text text(STR("Hello World")); - static constexpr Text text_same(STR("Hello World")); - static constexpr Text text_less(STR("Hello Wnrld")); - static constexpr Text text_greater(STR("Hello Wprld")); - static constexpr Text text_less_length(STR("Hello Worl")); - static constexpr Text text_greater_length(STR("Hello World!")); - - static constexpr size_t length = etl::strlen(STR("Hello World")); - - static constexpr Text text_xxx(STR("xxxHello Worldxxx")); - static constexpr Text text_same_xxx(STR("xxxHello World")); - static constexpr Text text_less_xxx(STR("xxxHello Wnrldxxx")); - static constexpr Text text_greater_xxx(STR("xxxHello Wprldxxx")); - static constexpr Text text_less_length_xxx(STR("xxxHello Worlxxx")); - static constexpr Text text_greater_length_xxx(STR("xxxHello World!xxx")); - - static constexpr const IText& itext = text; + static constexpr Text::const_pointer text_pointer = STR("Hello World"); + static constexpr Text text(STR("Hello World")); + static constexpr size_t Length = etl::strlen(STR("Hello World")); //************************************************************************* template - bool Equal(const T1& compare_text, const T2& text) + bool Equal(const T1& compare_text, const T2& test_text) { - return (compare_text.size() == text.size()) && std::equal(text.begin(), text.end(), compare_text.begin()); + return (compare_text.size() == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text.begin()); } //************************************************************************* template - bool Equal(const T1* compare_text, const T2& text) + bool Equal(const T1* compare_text, const T2& test_text) { - return (etl::strlen(compare_text) == text.size()) && std::equal(text.begin(), text.end(), compare_text); + return (etl::strlen(compare_text) == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text); } //************************************************************************* @@ -144,16 +113,16 @@ namespace CHECK_TRUE(text_full); static constexpr auto text_capacity = text_from_pointer.capacity(); - CHECK_EQUAL(length, text_capacity); + CHECK_EQUAL(Length, text_capacity); static constexpr auto text_max_size = text_from_pointer.max_size(); - CHECK_EQUAL(length, text_max_size); + CHECK_EQUAL(Length, text_max_size); static constexpr auto text_size = text_from_pointer.size(); - CHECK_EQUAL(length, text_size); + CHECK_EQUAL(Length, text_size); static constexpr auto text_length = text_from_pointer.length(); - CHECK_EQUAL(length, text_length); + CHECK_EQUAL(Length, text_length); static constexpr auto text_available = text_from_pointer.available(); CHECK_EQUAL(0, text_available); @@ -164,11 +133,11 @@ namespace static constexpr auto text_is_secure = text_from_pointer.is_secure(); CHECK_FALSE(text_is_secure); - static constexpr const char* text_data = text_from_pointer.data(); + static constexpr Text::const_pointer text_data = text_from_pointer.data(); CHECK_EQUAL(&text_pointer[0], text_data); - static constexpr const char* text_data_end = text_from_pointer.data_end(); - CHECK_EQUAL(&text_pointer[length], text_data_end); + static constexpr Text::const_pointer text_data_end = text_from_pointer.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); static constexpr auto text_begin = text_from_pointer.begin(); CHECK_EQUAL(&text_pointer[0], text_begin); @@ -177,16 +146,16 @@ namespace CHECK_EQUAL(&text_pointer[0], text_cbegin); static constexpr auto text_rbegin = text_from_pointer.rbegin(); - CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_rbegin)); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); static constexpr auto text_crbegin = text_from_pointer.crbegin(); - CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_crbegin)); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); static constexpr auto text_end = text_from_pointer.end(); - CHECK_EQUAL(&text_pointer[length], text_end); + CHECK_EQUAL(&text_pointer[Length], text_end); static constexpr auto text_cend = text_from_pointer.cend(); - CHECK_EQUAL(&text_pointer[length], text_cend); + CHECK_EQUAL(&text_pointer[Length], text_cend); static constexpr auto text_rend = text_from_pointer.rend(); CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); @@ -210,16 +179,16 @@ namespace CHECK_TRUE(text_full); static constexpr auto text_capacity = text_from_literal.capacity(); - CHECK_EQUAL(length, text_capacity); + CHECK_EQUAL(Length, text_capacity); static constexpr auto text_max_size = text_from_literal.max_size(); - CHECK_EQUAL(length, text_max_size); + CHECK_EQUAL(Length, text_max_size); static constexpr auto text_size = text_from_literal.size(); - CHECK_EQUAL(length, text_size); + CHECK_EQUAL(Length, text_size); static constexpr auto text_length = text_from_literal.length(); - CHECK_EQUAL(length, text_length); + CHECK_EQUAL(Length, text_length); static constexpr auto text_available = text_from_literal.available(); CHECK_EQUAL(0, text_available); @@ -230,11 +199,11 @@ namespace static constexpr auto text_is_secure = text_from_literal.is_secure(); CHECK_FALSE(text_is_secure); - static constexpr const char* text_data = text_from_literal.data(); + static constexpr Text::const_pointer text_data = text_from_literal.data(); CHECK_EQUAL(&text_pointer[0], text_data); - static constexpr const char* text_data_end = text_from_literal.data_end(); - CHECK_EQUAL(&text_pointer[length], text_data_end); + static constexpr Text::const_pointer text_data_end = text_from_literal.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); static constexpr auto text_begin = text_from_literal.begin(); CHECK_EQUAL(&text_pointer[0], text_begin); @@ -243,16 +212,16 @@ namespace CHECK_EQUAL(&text_pointer[0], text_cbegin); static constexpr auto text_rbegin = text_from_literal.rbegin(); - CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_rbegin)); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); static constexpr auto text_crbegin = text_from_literal.crbegin(); - CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_crbegin)); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); static constexpr auto text_end = text_from_literal.end(); - CHECK_EQUAL(&text_pointer[length], text_end); + CHECK_EQUAL(&text_pointer[Length], text_end); static constexpr auto text_cend = text_from_literal.cend(); - CHECK_EQUAL(&text_pointer[length], text_cend); + CHECK_EQUAL(&text_pointer[Length], text_cend); static constexpr auto text_rend = text_from_literal.rend(); CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); @@ -265,65 +234,145 @@ namespace } //************************************************************************* - TEST(test_constructor_from_etl_string_view) + TEST(test_constructor_truncated) { - static constexpr Text text_from_view(View(STR("Hello World"))); + static constexpr Text text_from_pointer(text_pointer, true); + static constexpr Text text_from_literal(STR("Hello World"), true); - static constexpr auto text_empty = text_from_view.empty(); + static constexpr auto text_from_pointer_is_truncated = text_from_pointer.is_truncated(); + CHECK_TRUE(text_from_pointer_is_truncated); + + static constexpr auto text_from_literal_is_truncated = text_from_literal.is_truncated(); + CHECK_TRUE(text_from_literal_is_truncated); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + static constexpr Text text_copy(text); + + static constexpr auto text_empty = text_copy.empty(); CHECK_FALSE(text_empty); - static constexpr auto text_full = text_from_view.full(); + static constexpr auto text_full = text_copy.full(); CHECK_TRUE(text_full); - static constexpr auto text_capacity = text_from_view.capacity(); - CHECK_EQUAL(length, text_capacity); + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); - static constexpr auto text_max_size = text_from_view.max_size(); - CHECK_EQUAL(length, text_max_size); + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); - static constexpr auto text_size = text_from_view.size(); - CHECK_EQUAL(length, text_size); + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); - static constexpr auto text_length = text_from_view.length(); - CHECK_EQUAL(length, text_length); + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); - static constexpr auto text_available = text_from_view.available(); + static constexpr auto text_available = text_copy.available(); CHECK_EQUAL(0, text_available); - static constexpr auto text_is_truncated = text_from_view.is_truncated(); + static constexpr auto text_is_truncated = text_copy.is_truncated(); CHECK_FALSE(text_is_truncated); - static constexpr auto text_is_secure = text_from_view.is_secure(); + static constexpr auto text_is_secure = text_copy.is_secure(); CHECK_FALSE(text_is_secure); - static constexpr const char* text_data = text_from_view.data(); + static constexpr Text::const_pointer text_data = text_copy.data(); CHECK_EQUAL(&text_pointer[0], text_data); - static constexpr const char* text_data_end = text_from_view.data_end(); - CHECK_EQUAL(&text_pointer[length], text_data_end); + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); - static constexpr auto text_begin = text_from_view.begin(); + static constexpr auto text_begin = text_copy.begin(); CHECK_EQUAL(&text_pointer[0], text_begin); - static constexpr auto text_cbegin = text_from_view.cbegin(); + static constexpr auto text_cbegin = text_copy.cbegin(); CHECK_EQUAL(&text_pointer[0], text_cbegin); - static constexpr auto text_rbegin = text_from_view.rbegin(); - CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_rbegin)); + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); - static constexpr auto text_crbegin = text_from_view.crbegin(); - CHECK_EQUAL(&text_pointer[length - 1], etl::addressof(*text_crbegin)); + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); - static constexpr auto text_end = text_from_view.end(); - CHECK_EQUAL(&text_pointer[length], text_end); + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); - static constexpr auto text_cend = text_from_view.cend(); - CHECK_EQUAL(&text_pointer[length], text_cend); + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); - static constexpr auto text_rend = text_from_view.rend(); + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_copy_constructor_from_truncated) + { + static constexpr Text text_original(STR("Hello World"), true); + static constexpr Text text_copy(text_original); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_TRUE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); - static constexpr auto text_crend = text_from_view.crend(); + static constexpr auto text_crend = text_copy.crend(); CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); bool is_equal = Equal(std::string(text_pointer), text); @@ -336,30 +385,10 @@ namespace static constexpr Text::const_iterator p_begin = text.begin(); static constexpr Text::const_iterator p_cbegin = text.cbegin(); - CHECK_EQUAL(&text[0], p_begin); - CHECK_EQUAL(&text[0], p_cbegin); + CHECK_EQUAL(&text_pointer[0], p_begin); + CHECK_EQUAL(&text_pointer[0], p_cbegin); } - - //************************************************************************* - TEST(test_end) - { - static constexpr Text::const_iterator p_end = text.end(); - static constexpr Text::const_iterator p_cend = text.cend(); - - CHECK_EQUAL(&text[length], p_end); - CHECK_EQUAL(&text[length], p_cend); - } - - //************************************************************************* - TEST(test_empty_full) - { - static constexpr bool text_empty = text.empty(); - static constexpr bool text_full = text.full(); - - CHECK_FALSE(text_empty); - CHECK_TRUE(text_full); - } - + //************************************************************************* TEST(test_index) { @@ -427,7 +456,7 @@ namespace //************************************************************************* TEST(test_back) { - CHECK_TRUE(text_pointer[length - 1] == text.back()); + CHECK_TRUE(text_pointer[Length - 1] == text.back()); } //************************************************************************* @@ -438,12 +467,32 @@ namespace CHECK_EQUAL(&text[0], p_data); } + //************************************************************************* + TEST(test_data_end) + { + static constexpr Text::const_pointer p_data = text.data_end(); + + CHECK_EQUAL(&text[Length], p_data); + } + + //************************************************************************* + TEST(test_c_str) + { + static constexpr Text::const_pointer p_data = text.c_str(); + + CHECK_EQUAL(&text[0], p_data); + CHECK_EQUAL(Length, etl::strlen(p_data)); + } + //************************************************************************* TEST(test_const_iterator) { static constexpr Text::const_iterator itr = text.begin(); - bool is_equal = std::equal(text_pointer, text_pointer + length, itr); + Text::const_iterator begin = text.begin(); + Text::const_iterator end = text.end(); + + bool is_equal = std::equal(begin, end, itr); CHECK_TRUE(is_equal); } @@ -452,1560 +501,43 @@ namespace { static constexpr Text::const_reverse_iterator ritr = text.rbegin(); - etl::reverse_iterator rbegin(text_pointer + length); - etl::reverse_iterator rend(text_pointer); + etl::reverse_iterator rbegin(text_pointer + Length); + etl::reverse_iterator rend(text_pointer); bool is_equal = std::equal(rbegin, rend, ritr); CHECK_TRUE(is_equal); } //************************************************************************* - TEST(test_equal) + TEST(test_to_view) { - static constexpr bool text_compare_with_same = (text == text_same); - CHECK_TRUE(text_compare_with_same); + static constexpr View view(text); - static constexpr bool text_compare_with_less = (text == text_less); - CHECK_FALSE(text_compare_with_less); + CHECK_TRUE(text.begin() == view.begin()); + CHECK_TRUE(text.end() == view.end()); - static constexpr bool text_compare_with_greater = (text == text_greater); - CHECK_FALSE(text_compare_with_greater); - - static constexpr bool text_compare_with_less_length = (text == text_less_length); - CHECK_FALSE(text_compare_with_less_length); - - static constexpr bool text_compare_with_greater_length = (text == text_greater_length); - CHECK_FALSE(text_compare_with_greater_length); + bool is_equal = std::equal(text.begin(), text.end(), view.begin()); + CHECK_TRUE(is_equal); } //************************************************************************* - TEST(test_not_equal) +#if ETL_USING_STL + TEST(test_write_string_to_std_basic_ostream) { - static constexpr bool text_compare_with_same = (text != text_same); - CHECK_FALSE(text_compare_with_same); + static constexpr Text text1 = STR("Hello World"); - static constexpr bool text_compare_with_less = (text != text_less); - CHECK_TRUE(text_compare_with_less); + std::stringstream sstream; - static constexpr bool text_compare_with_greater = (text != text_greater); - CHECK_TRUE(text_compare_with_greater); + sstream << text1; - static constexpr bool text_compare_with_less_length = (text != text_less_length); - CHECK_TRUE(text_compare_with_less_length); + TextSTD sstream_string = sstream.str(); - static constexpr bool text_compare_with_greater_length = (text != text_greater_length); - CHECK_TRUE(text_compare_with_greater_length); + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); } - - //************************************************************************* - TEST(test_less_than) - { - static constexpr bool text_compare_with_same = (text < text_same); - CHECK_FALSE(text_compare_with_same); - - static constexpr bool text_compare_with_less = (text < text_less); - CHECK_FALSE(text_compare_with_less); - - static constexpr bool text_compare_with_greater = (text < text_greater); - CHECK_TRUE(text_compare_with_greater); - - static constexpr bool text_compare_with_less_length = (text < text_less_length); - CHECK_FALSE(text_compare_with_less_length); - - static constexpr bool text_compare_with_greater_length = (text < text_greater_length); - CHECK_TRUE(text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_less_than_or_equal) - { - static constexpr bool text_compare_with_same = (text <= text_same); - CHECK_TRUE(text_compare_with_same); - - static constexpr bool text_compare_with_less = (text <= text_less); - CHECK_FALSE(text_compare_with_less); - - static constexpr bool text_compare_with_greater = (text <= text_greater); - CHECK_TRUE(text_compare_with_greater); - - static constexpr bool text_compare_with_less_length = (text <= text_less_length); - CHECK_FALSE(text_compare_with_less_length); - - static constexpr bool text_compare_with_greater_length = (text <= text_greater_length); - CHECK_TRUE(text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_greater_than) - { - static constexpr bool text_compare_with_same = (text > text_same); - CHECK_FALSE(text_compare_with_same); - - static constexpr bool text_compare_with_less = (text > text_less); - CHECK_TRUE(text_compare_with_less); - - static constexpr bool text_compare_with_greater = (text > text_greater); - CHECK_FALSE(text_compare_with_greater); - - static constexpr bool text_compare_with_less_length = (text > text_less_length); - CHECK_TRUE(text_compare_with_less_length); - - static constexpr bool text_compare_with_greater_length = (text > text_greater_length); - CHECK_FALSE(text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_greater_than_or_equal) - { - static constexpr bool text_compare_with_same = (text >= text_same); - CHECK_TRUE(text_compare_with_same); - - static constexpr bool text_compare_with_less = (text >= text_less); - CHECK_TRUE(text_compare_with_less); - - static constexpr bool text_compare_with_greater = (text >= text_greater); - CHECK_FALSE(text_compare_with_greater); - - static constexpr bool text_compare_with_less_length = (text >= text_less_length); - CHECK_TRUE(text_compare_with_less_length); - - static constexpr bool text_compare_with_greater_length = (text >= text_greater_length); - CHECK_FALSE(text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_find_string) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text needle(STR("needle")); - static constexpr Text pin(STR("pin")); - - static constexpr size_t position_needle = haystack.find(needle); - CHECK_EQUAL(18, position_needle); - - static constexpr size_t position_pin = haystack.find(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_string_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text needle(STR("needle")); - static constexpr Text pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.find(needle, 0ULL); - CHECK_EQUAL(18, position_needle1); - - static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1); - CHECK_EQUAL(37, position_needle2); - - static constexpr size_t position_pin = haystack.find(pin, 0ULL); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_view) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr View needle(STR("needle")); - static constexpr View pin(STR("pin")); - - static constexpr size_t position_needle = haystack.find(needle); - CHECK_EQUAL(18, position_needle); - - static constexpr size_t position_pin = haystack.find(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_view_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr View needle(STR("needle")); - static constexpr View pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.find(needle, 0ULL); - CHECK_EQUAL(18, position_needle1); - - static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1); - CHECK_EQUAL(37, position_needle2); - - static constexpr size_t position_pin = haystack.find(pin, 0ULL); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_pointer) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer needle(STR("needle")); - static constexpr Text::const_pointer pin(STR("pin")); - - static constexpr size_t position_needle = haystack.find(needle); - CHECK_EQUAL(18, position_needle); - - static constexpr size_t position_pin = haystack.find(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_pointer_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer needle(STR("needle")); - static constexpr Text::const_pointer pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.find(needle, 0ULL); - CHECK_EQUAL(18, position_needle1); - - static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1); - CHECK_EQUAL(37, position_needle2); - - static constexpr size_t position_pin = haystack.find(pin, 0ULL); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_pointer_position_n) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer needle(STR("needle")); - static constexpr Text::const_pointer pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.find(needle, 0ULL, 4); - CHECK_EQUAL(18, position_needle1); - - static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1, 4); - CHECK_EQUAL(37, position_needle2); - - static constexpr size_t position_pin = haystack.find(pin, 0ULL); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_character) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type needle(STR('n')); - static constexpr Text::value_type pin(STR('p')); - - static constexpr size_t position_needle = haystack.find(needle); - CHECK_EQUAL(18, position_needle); - - static constexpr size_t position_pin = haystack.find(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_find_character_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type needle(STR('n')); - static constexpr Text::value_type pin(STR('p')); - - static constexpr size_t position_needle1 = haystack.find(needle, 0ULL); - CHECK_EQUAL(18, position_needle1); - - static constexpr size_t position_needle2 = haystack.find(needle, position_needle1 + 1); - CHECK_EQUAL(26, position_needle2); - - static constexpr size_t position_pin = haystack.find(pin, 0ULL); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_contains_string) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text needle(STR("needle")); - static constexpr Text pin(STR("pin" )); - static constexpr Text excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_needle = haystack.contains(needle); - static constexpr bool constains_pin = haystack.contains(pin); - static constexpr bool contains_excess = haystack.contains(excess); - - CHECK_TRUE(contains_needle); - CHECK_FALSE(constains_pin); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_contains_view) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr View needle(STR("needle")); - static constexpr View pin(STR("pin" )); - static constexpr View excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_needle = haystack.contains(needle); - static constexpr bool constains_pin = haystack.contains(pin); - static constexpr bool contains_excess = haystack.contains(excess); - - CHECK_TRUE(contains_needle); - CHECK_FALSE(constains_pin); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_contains_pointer) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer needle(STR("needle")); - static constexpr Text::const_pointer pin(STR("pin" )); - static constexpr Text::const_pointer excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_needle = haystack.contains(needle); - static constexpr bool constains_pin = haystack.contains(pin); - static constexpr bool contains_excess = haystack.contains(excess); - - CHECK_TRUE(contains_needle); - CHECK_FALSE(constains_pin); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_contains_char) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type needle(STR('n')); - static constexpr Text::value_type pin(STR('p' )); - - static constexpr bool contains_needle = haystack.contains(needle); - static constexpr bool constains_pin = haystack.contains(pin); - - CHECK_TRUE(contains_needle); - CHECK_FALSE(constains_pin); - } - - //************************************************************************* - TEST(test_starts_with_string) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text start_text(STR("A haystack")); - static constexpr Text not_start_text(STR("nothing else")); - static constexpr Text excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_start_text = haystack.starts_with(start_text); - static constexpr bool constains_not_start_text = haystack.starts_with(not_start_text); - static constexpr bool contains_excess = haystack.starts_with(excess); - - CHECK_TRUE(contains_start_text); - CHECK_FALSE(constains_not_start_text); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_starts_with_view) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr View start_text(STR("A haystack")); - static constexpr View not_start_text(STR("nothing else")); - static constexpr View excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_start_text = haystack.starts_with(start_text); - static constexpr bool constains_not_start_text = haystack.starts_with(not_start_text); - - CHECK_TRUE(contains_start_text); - CHECK_FALSE(constains_not_start_text); - } - - //************************************************************************* - TEST(test_starts_with_pointer) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer start_text(STR("A haystack")); - static constexpr Text::const_pointer not_start_text(STR("nothing else")); - static constexpr Text::const_pointer excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_start_text = haystack.starts_with(start_text); - static constexpr bool constains_not_start_text = haystack.starts_with(not_start_text); - - CHECK_TRUE(contains_start_text); - CHECK_FALSE(constains_not_start_text); - } - - //************************************************************************* - TEST(test_starts_with_char) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type start_text(STR('A')); - static constexpr Text::value_type not_start_text(STR('e')); - - static constexpr bool contains_start_text = haystack.starts_with(start_text); - static constexpr bool constains_not_start_text = haystack.starts_with(not_start_text); - - CHECK_TRUE(contains_start_text); - CHECK_FALSE(constains_not_start_text); - } - - //************************************************************************* - TEST(test_ends_with_string) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text not_end_text(STR("A haystack")); - static constexpr Text end_text(STR("nothing else")); - static constexpr Text excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_end_text = haystack.ends_with(end_text); - static constexpr bool constains_not_end_text = haystack.ends_with(not_end_text); - static constexpr bool contains_excess = haystack.ends_with(excess); - - CHECK_TRUE(contains_end_text); - CHECK_FALSE(constains_not_end_text); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_ends_with_view) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr View not_end_text(STR("A haystack")); - static constexpr View end_text(STR("nothing else")); - static constexpr View excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_end_text = haystack.ends_with(end_text); - static constexpr bool constains_not_end_text = haystack.ends_with(not_end_text); - static constexpr bool contains_excess = haystack.ends_with(excess); - - CHECK_TRUE(contains_end_text); - CHECK_FALSE(constains_not_end_text); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_ends_with_pointer) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer not_end_text(STR("A haystack")); - static constexpr Text::const_pointer end_text(STR("nothing else")); - static constexpr Text::const_pointer excess(STR("A really gigantic pin or needle that's really really big")); - - static constexpr bool contains_end_text = haystack.ends_with(end_text); - static constexpr bool constains_not_end_text = haystack.ends_with(not_end_text); - static constexpr bool contains_excess = haystack.ends_with(excess); - - CHECK_TRUE(contains_end_text); - CHECK_FALSE(constains_not_end_text); - CHECK_FALSE(contains_excess); - } - - //************************************************************************* - TEST(test_ends_with_char) - { - static constexpr Text::const_pointer the_haystack = (STR("A haystack with a needle and nothing else")); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type not_end_text(STR('A')); - static constexpr Text::value_type end_text(STR('e')); - - static constexpr bool contains_end_text = haystack.ends_with(end_text); - static constexpr bool constains_not_end_text = haystack.ends_with(not_end_text); - - CHECK_TRUE(contains_end_text); - CHECK_FALSE(constains_not_end_text); - } - - //************************************************************************* - TEST(test_rfind_string) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text needle(STR("needle")); - static constexpr Text pin(STR("pin")); - - static constexpr size_t position_needle = haystack.rfind(needle); - CHECK_EQUAL(37, position_needle); - - static constexpr size_t position_pin = haystack.rfind(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_string_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text needle(STR("needle")); - static constexpr Text pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos); - CHECK_EQUAL(37, position_needle1); - - static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1); - CHECK_EQUAL(18, position_needle2); - - static constexpr size_t position_pin = haystack.rfind(pin, 0ULL); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_view) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr View needle(STR("needle")); - static constexpr View pin(STR("pin")); - - static constexpr size_t position_needle = haystack.rfind(needle); - CHECK_EQUAL(37, position_needle); - - static constexpr size_t position_pin = haystack.rfind(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_view_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr View needle(STR("needle")); - static constexpr View pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos); - CHECK_EQUAL(37, position_needle1); - - static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1); - CHECK_EQUAL(18, position_needle2); - - static constexpr size_t position_pin = haystack.rfind(pin, Text::npos); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_pointer) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer needle(STR("needle")); - static constexpr Text::const_pointer pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos); - CHECK_EQUAL(37, position_needle1); - - static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1); - CHECK_EQUAL(18, position_needle2); - - static constexpr size_t position_pin = haystack.rfind(pin, Text::npos); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_pointer_n) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::const_pointer needle(STR("needle")); - static constexpr Text::const_pointer pin(STR("pin")); - - static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos, 4); - CHECK_EQUAL(37, position_needle1); - - static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1 + 1, 4); - CHECK_EQUAL(18, position_needle2); - - static constexpr size_t position_pin = haystack.rfind(pin, Text::npos, 4); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_character) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type needle(STR('n')); - static constexpr Text::value_type pin(STR('p')); - - static constexpr size_t position_needle = haystack.rfind(needle); - CHECK_EQUAL(37, position_needle); - - static constexpr size_t position_pin = haystack.rfind(pin); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_rfind_character_position) - { - static constexpr Text::const_pointer the_haystack = STR("A haystack with a needle and another needle"); - static constexpr Text haystack(the_haystack); - - static constexpr Text::value_type needle(STR('n')); - static constexpr Text::value_type pin(STR('p')); - - static constexpr size_t position_needle1 = haystack.rfind(needle, Text::npos); - CHECK_EQUAL(37, position_needle1); - - static constexpr size_t position_needle2 = haystack.rfind(needle, position_needle1); - CHECK_EQUAL(30, position_needle2); - - static constexpr size_t position_pin = haystack.rfind(pin, Text::npos); - CHECK_EQUAL(Text::npos, position_pin); - } - - //************************************************************************* - TEST(test_substr) - { - // Equal. - static constexpr Text sub1(text.substr(text.size())); - CHECK_EQUAL(0, sub1.size()); - - // Whole string. - static constexpr Text sub2(text.substr()); - CHECK_TRUE(Equal(text, sub2)); - - // Starting from position 2. - static constexpr Text sub3(text.substr(2)); - CHECK_TRUE(Equal(View(text.begin() + 2, text.end()), sub3)); - - // Starting from position 2 for 3 characters. - static constexpr Text sub4(text.substr(2, 3)); - CHECK_TRUE(Equal(View(text.begin() + 2, text.begin() + 2 + 3), sub4)); - - // Starting from position 2 for too many characters. - static constexpr Text sub5(text.substr(2, text.size())); - CHECK_TRUE(Equal(View(text.begin() + 2, text.end()), sub3)); - } - - //************************************************************************* - TEST(test_compare_string) - { - // Equal. - static constexpr auto text_compare_with_same = text.compare(text_same); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text.compare(text_less); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text.compare(text_greater); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text.compare(text_less_length); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text.compare(text_greater_length); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_position_length_string) - { - // Equal. - static constexpr auto text_compare_with_same = text_xxx.compare(3, length, text_same); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text_xxx.compare(3, length, text_less); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, text_greater); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, text_less_length); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, text_greater_length); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_position_length_string_subposition_sublength) - { - // Equal. - static constexpr auto text_compare_with_same = text_xxx.compare(3, length, text_same_xxx, 3, text_same.size()); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text_xxx.compare(3, length, text_less_xxx, 3, text_less.size()); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, text_greater_xxx, 3, text_greater.size()); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, text_less_length_xxx, 3, text_less_length.size()); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, text_greater_length_xxx, 3, text_greater_length.size()); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_view) - { - // Equal. - static constexpr auto text_compare_with_same = text.compare(View(text_same)); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text.compare(View(text_less)); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text.compare(View(text_greater)); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text.compare(View(text_less_length)); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text.compare(View(text_greater_length)); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_position_length_view) - { - // Equal. - static constexpr auto text_compare_with_same = text_xxx.compare(3, length, View(text_same)); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text_xxx.compare(3, length, View(text_less)); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, View(text_greater)); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, View(text_less_length)); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, View(text_greater_length)); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_position_length_view_subposition_sublength) - { - // Equal. - static constexpr auto text_compare_with_same = text_xxx.compare(3, length, View(text_same_xxx), 3, text_same.size()); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text_xxx.compare(3, length, View(text_less_xxx), 3, text_less.size()); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, View(text_greater_xxx), 3, text_greater.size()); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, View(text_less_length_xxx), 3, text_less_length.size()); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, View(text_greater_length_xxx), 3, text_greater_length.size()); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_c_string) - { - // Equal. - static constexpr auto text_compare_with_same = text.compare(text_same.data()); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text.compare(text_less.data()); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text.compare(text_greater.data()); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text.compare(text_less_length.data()); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text.compare(text_greater_length.data()); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_position_length_c_string) - { - // Equal. - static constexpr auto text_compare_with_same = text_xxx.compare(3, length, text_same.data()); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text_xxx.compare(3, length, text_less.data()); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, text_greater.data()); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, text_less_length.data()); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, text_greater_length.data()); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_compare_position_length_c_string_n) - { - // Equal. - static constexpr auto text_compare_with_same = text_xxx.compare(3, length, text_same.data(), text_same.size()); - CHECK_EQUAL(0, text_compare_with_same); - - // Less. - static constexpr auto text_compare_with_less = text_xxx.compare(3, length, text_less.data(), text_less.size()); - CHECK_EQUAL(1, text_compare_with_less); - - // Greater. - static constexpr auto text_compare_with_greater = text_xxx.compare(3, length, text_greater.data(), text_greater.size()); - CHECK_EQUAL(-1, text_compare_with_greater); - - // Shorter - static constexpr auto text_compare_with_less_length = text_xxx.compare(3, length, text_less_length.data(), text_less_length.size()); - CHECK_EQUAL(1, text_compare_with_less_length); - - // Longer. - static constexpr auto text_compare_with_greater_length = text_xxx.compare(3, length, text_greater_length.data(), text_greater_length.size()); - CHECK_EQUAL(-1, text_compare_with_greater_length); - } - - //************************************************************************* - TEST(test_find_first_of_string_position) - { - static constexpr auto text_find_first_of_word = text.find_first_of(text_word, 2); - CHECK_EQUAL(4, text_find_first_of_word); - - static constexpr auto text_find_first_of_he = text.find_first_of(text_he, 2); - CHECK_EQUAL(Text::npos, text_find_first_of_he); - } - - //************************************************************************* - TEST(test_find_first_of_view_position) - { - static constexpr auto text_find_first_of_word = text.find_first_of(View(text_word), 2); - CHECK_EQUAL(4, text_find_first_of_word); - - static constexpr auto text_find_first_of_he = text.find_first_of(View(text_he), 2); - CHECK_EQUAL(Text::npos, text_find_first_of_he); - } - - //************************************************************************* - TEST(test_find_first_of_pointer_position) - { - static constexpr auto text_find_first_of_word = text.find_first_of(text_word.data(), 2); - CHECK_EQUAL(4, text_find_first_of_word); - - static constexpr auto text_find_first_of_he = text.find_first_of(text_he.data(), 2); - CHECK_EQUAL(Text::npos, text_find_first_of_he); - } - - //************************************************************************* - TEST(test_find_first_of_pointer_position_n) - { - static constexpr auto text_find_first_of_word = text.find_first_of(text_word.data(), 2, text_word.size()); - CHECK_EQUAL(4, text_find_first_of_word); - - static constexpr auto text_find_first_of_he = text.find_first_of(text_he.data(), 2, text_he.size()); - CHECK_EQUAL(Text::npos, text_find_first_of_he); - } - - //************************************************************************* - TEST(test_find_first_of_character_position) - { - static constexpr auto text_find_first_of_o = text.find_first_of(STR('o'), 2); - CHECK_EQUAL(4, text_find_first_of_o); - - static constexpr auto text_find_first_of_h = text.find_first_of(STR('h'), 2); - CHECK_EQUAL(Text::npos, text_find_first_of_h); - } - - //************************************************************************* - TEST(test_find_last_of_string_position) - { - static constexpr auto text_find_last_of_word = text.find_last_of(text_word, 9); - CHECK_EQUAL(8, text_find_last_of_word); - - static constexpr auto text_find_last_of_rd = text.find_last_of(text_rd, 7); - CHECK_EQUAL(Text::npos, text_find_last_of_rd); - } - - //************************************************************************* - TEST(test_find_last_of_view_position) - { - static constexpr auto text_find_last_of_word = text.find_last_of(View(text_word), 9); - CHECK_EQUAL(8, text_find_last_of_word); - - static constexpr auto text_find_last_of_rd = text.find_last_of(View(text_rd), 7); - CHECK_EQUAL(Text::npos, text_find_last_of_rd); - } - - //************************************************************************* - TEST(test_find_last_of_pointer_position) - { - static constexpr auto text_find_last_of_word = text.find_last_of(text_word.data(), 9); - CHECK_EQUAL(8, text_find_last_of_word); - - static constexpr auto text_find_last_of_rd = text.find_last_of(text_rd.data(), 7); - CHECK_EQUAL(Text::npos, text_find_last_of_rd); - } - - //************************************************************************* - TEST(test_find_last_of_pointer_position_n) - { - static constexpr auto text_find_last_of_word = text.find_last_of(text_word.data(), 9, text_word.size()); - CHECK_EQUAL(8, text_find_last_of_word); - - static constexpr auto text_find_last_of_rd = text.find_last_of(text_rd.data(), 7, text_rd.size()); - CHECK_EQUAL(Text::npos, text_find_last_of_rd); - } - - //************************************************************************* - TEST(test_find_last_of_character_position) - { - static constexpr auto text_find_last_of_o = text.find_last_of(STR('o'), 9); - CHECK_EQUAL(7, text_find_last_of_o); - - static constexpr auto text_find_last_of_h = text.find_last_of(STR('h'), 7); - CHECK_EQUAL(Text::npos, text_find_last_of_h); - } - - //************************************************************************* - TEST(test_find_first_not_of_string_position) - { - static constexpr auto text_find_first_not_of_word = text.find_first_not_of(text_hello, 2); - CHECK_EQUAL(5, text_find_first_not_of_word); - - static constexpr auto text_find_first_not_of_llo_world = text.find_first_not_of(text_llo_world, 2); - CHECK_EQUAL(Text::npos, text_find_first_not_of_llo_world); - } - - //************************************************************************* - TEST(test_find_first_not_of_view_position) - { - static constexpr auto text_find_first_not_of_word = text.find_first_not_of(View(text_hello), 2); - CHECK_EQUAL(5, text_find_first_not_of_word); - - static constexpr auto text_find_first_not_of_llo_world = text.find_first_not_of(View(text_llo_world), 2); - CHECK_EQUAL(Text::npos, text_find_first_not_of_llo_world); - } - - //************************************************************************* - TEST(test_find_first_not_of_pointer_position) - { - static constexpr auto text_find_first_not_of_word = text.find_first_not_of(text_hello.data(), 2); - CHECK_EQUAL(5, text_find_first_not_of_word); - - static constexpr auto text_find_first_not_of_llo_world = text.find_first_not_of(text_llo_world.data(), 2); - CHECK_EQUAL(Text::npos, text_find_first_not_of_llo_world); - } - - //************************************************************************* - TEST(test_find_first_not_of_pointer_position_n) - { - static constexpr auto text_find_first_not_of_word = text.find_first_not_of(text_hello.data(), 2, text_hello.size()); - CHECK_EQUAL(5, text_find_first_not_of_word); - - static constexpr auto text_find_first_not_of_llo_world = text.find_first_not_of(text_llo_world.data(), 2, text_llo_world.size()); - CHECK_EQUAL(Text::npos, text_find_first_not_of_llo_world); - } - - //************************************************************************* - TEST(test_find_first_not_of_character_position) - { - static constexpr auto text_find_first_not_of_o = text.find_first_not_of(STR('l'), 2); - CHECK_EQUAL(4, text_find_first_not_of_o); - - static constexpr auto text_find_first_not_of_h = text.find_first_not_of(STR('h'), 2); - CHECK_EQUAL(2, text_find_first_not_of_h); - } - -// //************************************************************************* -// TEST(test_find_last_not_of_string_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); -// size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); -// position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST(test_find_last_not_of_view_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); -// size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); -// position2 = text.find_last_not_of(View(STR("ZEXD")), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); -// position2 = text.find_last_not_of(View(STR("ZEXD")), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); -// position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); -// position2 = text.find_last_not_of(View(STR("ZEXD")), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST(test_find_last_not_of_pointer_position) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); -// size_t position2 = text.find_last_not_of(STR("ZEXD")); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 3); -// position2 = text.find_last_not_of(STR("ZEXD"), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5); -// position2 = text.find_last_not_of(STR("ZEXD"), 5); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size()); -// position2 = text.find_last_not_of(STR("ZEXD"), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100); -// position2 = text.find_last_not_of(STR("ZEXD"), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST(test_find_last_not_of_pointer_position_n) -// { -// TextSTD compare_text(STR("ABCDEFABCDE")); -// Text text(STR("ABCDEFABCDE")); -// -// size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); -// size_t position2 = text.find_last_not_of(STR("ZEXD"), 0, 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 5, 3); -// position2 = text.find_last_not_of(STR("ZEXD"), 5, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 1, 3); -// position2 = text.find_last_not_of(STR("ZEXD"), 1, 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), compare_text.size(), 4); -// position2 = text.find_last_not_of(STR("ZEXD"), text.size(), 4); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR("ZEXD"), 100, 4); -// position2 = text.find_last_not_of(STR("ZEXD"), 100, 4); -// -// CHECK_EQUAL(position1, position2); -// } -// -// //************************************************************************* -// TEST(test_find_last_not_of_character_position) -// { -// TextSTD compare_text(STR("ABCDEF")); -// Text text(STR("ABCDEF")); -// -// size_t position1 = compare_text.find_last_not_of(STR('F')); -// size_t position2 = text.find_last_not_of(STR('F')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('Z')); -// position2 = text.find_last_not_of(STR('Z')); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('A'), compare_text.size()); -// position2 = text.find_last_not_of(STR('A'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('C'), 3); -// position2 = text.find_last_not_of(STR('C'), 3); -// -// CHECK_EQUAL(position1, position2); -// -// position1 = compare_text.find_last_not_of(STR('C'), compare_text.size()); -// position2 = text.find_last_not_of(STR('C'), text.size()); -// -// CHECK_EQUAL(position1, position2); -// -//#include "etl/private/diagnostic_array_bounds_push.h" -// position1 = compare_text.find_last_not_of(STR('C'), 100); -// position2 = text.find_last_not_of(STR('C'), 100); -// -// CHECK_EQUAL(position1, position2); -//#include "etl/private/diagnostic_pop.h" -// } -// -// //************************************************************************* -// TEST(test_hash) -// { -// // Test with actual string type. -// Text text(STR("ABCDEFHIJKL")); -// size_t hash = etl::hash()(text); -// size_t compare_hash = etl::private_hash::generic_hash(reinterpret_cast(&text[0]), reinterpret_cast(&text[text.size()])); -// CHECK_EQUAL(compare_hash, hash); -// -// // Test with interface string type. -// IText& itext = text; -// hash = etl::hash()(itext); -// CHECK_EQUAL(compare_hash, hash); -// } -// -// //************************************************************************* -// TEST(test_memcpy_repair) -// { -// Text text; -// -// text.assign(STR("ABCDEF")); -// -// char buffer[Sizeof(Text)]; -// -// memcpy(&buffer, (const void*)&text, Sizeof(text)); -// -// Text& rtext(*reinterpret_cast(buffer)); -// rtext.repair(); -// -// CHECK(!rtext.empty()); -// CHECK(!rtext.full()); -// -// bool is_equal = Equal(text, rtext); -// CHECK(is_equal); -// -// text = STR("GHIJKL"); -// is_equal = Equal(text, rtext); -// CHECK(!is_equal); -// } -// -// //************************************************************************* -// TEST(test_memcpy_repair_virtual) -// { -// Text text; -// -// text.assign(STR("ABCDEF")); -// -// char buffer[Sizeof(Text)]; -// -// memcpy(&buffer, (const void*)&text, Sizeof(text)); -// -// IText& itext(*reinterpret_cast(buffer)); -// itext.repair(); -// -// CHECK(!itext.empty()); -// CHECK(!itext.full()); -// -// bool is_equal = Equal(text, itext); -// CHECK(is_equal); -// -// text = STR("GHIJKL"); -// is_equal = Equal(text, itext); -// CHECK(!is_equal); -// } -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// //************************************************************************* -// TEST(test_truncate_over_many_operations) -// { -// Text text(short_text.c_str()); -// CHECK_FALSE(text.is_truncated()); -// -// text.insert(3, initial_text.c_str()); -// CHECK_TRUE(text.is_truncated()); -// -// while (text.size() != 0) -// { -// text.pop_back(); -// CHECK_TRUE(text.is_truncated()); -// } -// -// text.clear(); -// CHECK_FALSE(text.is_truncated()); -// -// text.assign(longer_text.c_str()); -// CHECK_TRUE(text.is_truncated()); -// -// text.assign(short_text.c_str()); -// CHECK_FALSE(text.is_truncated()); -// } -// -// //************************************************************************* -// TEST(test_add_from_truncated) -// { -// Text text1(short_text.c_str()); -// TextS text2(short_text.c_str()); -// -// CHECK_FALSE(text1.is_truncated()); -// CHECK_TRUE(text2.is_truncated()); -// -// // text2 has the truncate flag set. -// text1 += text2; -// -// CHECK(text1.is_truncated()); -// } -// -// //************************************************************************* -// TEST(test_add_to_truncated) -// { -// Text text1(longer_text.c_str()); -// Text text2(short_text.c_str()); -// -// CHECK(text1.is_truncated()); -// CHECK_FALSE(text2.is_truncated()); -// -// // Clear text but not the truncate flag. -// text1.erase(text1.begin(), text1.end()); -// -// // text1 still has the truncate flag set. -// text1 += text2; -// -// CHECK(text1.is_truncated()); -// } -// -// //************************************************************************* -// TEST(test_clear_truncated) -// { -// Text text(longer_text.c_str()); -// CHECK_TRUE(text.is_truncated()); -// -// text.clear_truncated(); -// CHECK_FALSE(text.is_truncated()); -// } -//#endif -// -//#if ETL_HAS_STRING_CLEAR_AFTER_USE -// //************************************************************************* -// TEST(test_secure_after_destructor) -// { -// char buffer[Sizeof(Text)]; -// std::fill_n(buffer, Sizeof(Text), 0); -// ::new (buffer) Text(STR("ABCDEF")); -// -// Text& text = *reinterpret_cast(buffer); -// text.set_secure(); -// -// CHECK(Text(STR("ABCDEF")) == text); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// // Destroy the text object. -// std::atomic_signal_fence(std::memory_order_seq_cst); -// text.~Text(); -// std::atomic_signal_fence(std::memory_order_seq_cst); -// -// // Check there no non-zero values in the string. -// CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST(test_secure_after_assign) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pe = text.end(); -// -// text.assign(STR("ABC")); -// -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST(test_secure_after_reSize_down) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pe = text.end(); -// -// text.reSize(text.size() - 3U); -// -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST(test_secure_after_erase) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// text.erase(pb + 2, pb + 5); -// -// // Check there no non-zero values in the remainder of the string. -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST(test_secure_after_replace) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// text.replace(pb + 1, pb + 4, STR("G")); -// -// // Check there no non-zero values in the remainder of the string. -// CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST(test_secure_after_clear) -// { -// Text text; -// text.set_secure(); -// text.assign(STR("ABCDEF")); -// -// Text::pointer pb = text.begin(); -// Text::pointer pe = text.end(); -// -// text.clear(); -// -// // Check there no non-zero values in the remainder of the string. -// CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); -// } -// -// //************************************************************************* -// TEST(test_secure_flag_after_copy) -// { -// Text text1 = STR("Hello World"); -// text1.set_secure(); -// -// Text text2(text1); -// -// Text text3; -// text3 = text1; -// -// Text text4(text1, 6U, 3U); -// -// CHECK(text2.is_secure()); -// CHECK(text3.is_secure()); -// CHECK(text4.is_secure()); -// } -//#endif -// -// //************************************************************************* -// TEST(test_initialize_free_space_empty_string) -// { -// Text empty; -// Text text; -// -// text.initialize_free_space(); -// -// CHECK(text.empty()); -// CHECK(text == empty); -// -// for (size_t i = text.size(); i < text.max_size(); ++i) -// { -// CHECK_EQUAL(0, text[i]); -// } -// } -// -// //************************************************************************* -// TEST(test_initialize_free_space_part_filled_string) -// { -// Text empty; -// Text initial = STR("ABC"); -// Text text(initial); -// -// text.initialize_free_space(); -// -// CHECK(text == initial); -// CHECK(text != empty); -// -// for (size_t i = text.size(); i < text.max_size(); ++i) -// { -// CHECK_EQUAL(0, text[i]); -// } -// } -// -// //************************************************************************* -// TEST(test_update_after_c_string_max_size) -// { -// Text text; -// -// text.initialize_free_space(); -// std::fill(text.data(), text.data() + text.max_size(), STR('A')); -// text.trim_to_terminator(); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// CHECK_EQUAL(text.max_size(), text.size()); -// } -// -// //************************************************************************* -// TEST(test_update_after_c_string_shorter_size) -// { -// Text text; -// -// text.initialize_free_space(); -// std::fill(text.data(), text.data() + text.max_size() - 1, STR('A')); -// text.trim_to_terminator(); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_FALSE(text.is_truncated()); -//#endif -// CHECK_EQUAL(text.max_size() - 1, text.size()); -// } -// -// //************************************************************************* -// TEST(test_update_after_c_string_greater_size) -// { -// Text text; -// -// text.initialize_free_space(); -// std::fill(text.data(), text.data() + text.max_size() + 1, STR('A')); // Overwrites to terminating null. -// text.trim_to_terminator(); -// -//#if ETL_HAS_STRING_TRUNCATION_CHECKS -// CHECK_TRUE(text.is_truncated()); -//#else -// CHECK_FALSE(text.is_truncated()); -//#endif -// CHECK_EQUAL(text.max_size(), text.size()); -// } -// -// //************************************************************************* -//#if ETL_USING_STL -// TEST(test_write_string_to_std_basic_ostream) -// { -// Text text1 = STR("Hello World"); -// -// std::stringstream sstream; -// -// sstream << text1; -// -// TextSTD sstream_string = sstream.str(); -// -// View sstream_view(sstream_string.data(), sstream_string.size()); -// -// CHECK(text1 == sstream_view); -// } -//#endif +#endif }; } + +#endif diff --git a/test/test_const_string_u16.cpp b/test/test_const_string_u16.cpp new file mode 100644 index 00000000..729a24db --- /dev/null +++ b/test/test_const_string_u16.cpp @@ -0,0 +1,525 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/const_u16string.h" +#include "etl/string_view.h" + +#if ETL_USING_CPP14 + +#undef STR +#define STR(x) u##x + +namespace +{ + SUITE(test_const_string_char16_t) + { + using Text = etl::const_u16string; + using View = etl::u16string_view; + + using TextSTD = std::u16string; + + static constexpr Text::const_pointer text_pointer = STR("Hello World"); + static constexpr Text text(STR("Hello World")); + static constexpr size_t Length = etl::strlen(STR("Hello World")); + + //************************************************************************* + template + bool Equal(const T1& compare_text, const T2& test_text) + { + return (compare_text.size() == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text.begin()); + } + + //************************************************************************* + template + bool Equal(const T1* compare_text, const T2& test_text) + { + return (etl::strlen(compare_text) == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text); + } + + //************************************************************************* + TEST(test_constructor_null_string) + { + static constexpr Text text_from_literal_empty(STR("")); + + static constexpr auto text_empty = text_from_literal_empty.empty(); + CHECK_TRUE(text_empty); + + static constexpr auto text_full = text_from_literal_empty.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal_empty.capacity(); + CHECK_EQUAL(0, text_capacity); + + static constexpr auto text_max_size = text_from_literal_empty.max_size(); + CHECK_EQUAL(0, text_max_size); + + static constexpr auto text_size = text_from_literal_empty.size(); + CHECK_EQUAL(0, text_size); + + static constexpr auto text_length = text_from_literal_empty.length(); + CHECK_EQUAL(0, text_length); + + static constexpr auto text_available = text_from_literal_empty.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal_empty.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal_empty.is_secure(); + CHECK_FALSE(text_is_secure); + } + + //************************************************************************* + TEST(test_constructor_char_pointer) + { + static constexpr Text text_from_pointer(text_pointer); + + static constexpr auto text_empty = text_from_pointer.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_pointer.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_pointer.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_pointer.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_pointer.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_pointer.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_pointer.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_pointer.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_pointer.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_pointer.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_pointer.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_pointer.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_pointer.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_pointer.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_pointer.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_pointer.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_pointer.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_pointer.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_pointer.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u16string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_from_literal) + { + static constexpr Text text_from_literal(STR("Hello World")); + + static constexpr auto text_empty = text_from_literal.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_literal.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_literal.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_literal.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_literal.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_literal.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_literal.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_literal.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_literal.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_literal.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_literal.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_literal.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_literal.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_literal.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_literal.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_literal.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u16string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_truncated) + { + static constexpr Text text_from_pointer(text_pointer, true); + static constexpr Text text_from_literal(STR("Hello World"), true); + + static constexpr auto text_from_pointer_is_truncated = text_from_pointer.is_truncated(); + CHECK_TRUE(text_from_pointer_is_truncated); + + static constexpr auto text_from_literal_is_truncated = text_from_literal.is_truncated(); + CHECK_TRUE(text_from_literal_is_truncated); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + static constexpr Text text_copy(text); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u16string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_copy_constructor_from_truncated) + { + static constexpr Text text_original(STR("Hello World"), true); + static constexpr Text text_copy(text_original); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_TRUE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u16string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_begin) + { + static constexpr Text::const_iterator p_begin = text.begin(); + static constexpr Text::const_iterator p_cbegin = text.cbegin(); + + CHECK_EQUAL(&text_pointer[0], p_begin); + CHECK_EQUAL(&text_pointer[0], p_cbegin); + } + + //************************************************************************* + TEST(test_index) + { + static constexpr Text::value_type c0 = text[0]; + static constexpr Text::value_type c1 = text[1]; + static constexpr Text::value_type c2 = text[2]; + static constexpr Text::value_type c3 = text[3]; + static constexpr Text::value_type c4 = text[4]; + static constexpr Text::value_type c5 = text[5]; + static constexpr Text::value_type c6 = text[6]; + static constexpr Text::value_type c7 = text[7]; + static constexpr Text::value_type c8 = text[8]; + static constexpr Text::value_type c9 = text[9]; + static constexpr Text::value_type c10 = text[10]; + static constexpr Text::value_type c11 = text[11]; + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + CHECK_EQUAL(text_pointer[11], c11); + } + + //************************************************************************* + TEST(test_at) + { + static constexpr Text::value_type c0 = text.at(0); + static constexpr Text::value_type c1 = text.at(1); + static constexpr Text::value_type c2 = text.at(2); + static constexpr Text::value_type c3 = text.at(3); + static constexpr Text::value_type c4 = text.at(4); + static constexpr Text::value_type c5 = text.at(5); + static constexpr Text::value_type c6 = text.at(6); + static constexpr Text::value_type c7 = text.at(7); + static constexpr Text::value_type c8 = text.at(8); + static constexpr Text::value_type c9 = text.at(9); + static constexpr Text::value_type c10 = text.at(10); + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + } + + //************************************************************************* + TEST(test_front) + { + CHECK_TRUE(text_pointer[0] == text.front()); + } + + //************************************************************************* + TEST(test_back) + { + CHECK_TRUE(text_pointer[Length - 1] == text.back()); + } + + //************************************************************************* + TEST(test_data) + { + static constexpr Text::const_pointer p_data = text.data(); + + CHECK_EQUAL(&text[0], p_data); + } + + //************************************************************************* + TEST(test_data_end) + { + static constexpr Text::const_pointer p_data = text.data_end(); + + CHECK_EQUAL(&text[Length], p_data); + } + + //************************************************************************* + TEST(test_c_str) + { + static constexpr Text::const_pointer p_data = text.c_str(); + + CHECK_EQUAL(&text[0], p_data); + CHECK_EQUAL(Length, etl::strlen(p_data)); + } + + //************************************************************************* + TEST(test_const_iterator) + { + static constexpr Text::const_iterator itr = text.begin(); + + Text::const_iterator begin = text.begin(); + Text::const_iterator end = text.end(); + + bool is_equal = std::equal(begin, end, itr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_const_reverse_iterator) + { + static constexpr Text::const_reverse_iterator ritr = text.rbegin(); + + etl::reverse_iterator rbegin(text_pointer + Length); + etl::reverse_iterator rend(text_pointer); + + bool is_equal = std::equal(rbegin, rend, ritr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_to_view) + { + static constexpr View view(text); + + CHECK_TRUE(text.begin() == view.begin()); + CHECK_TRUE(text.end() == view.end()); + + bool is_equal = std::equal(text.begin(), text.end(), view.begin()); + CHECK_TRUE(is_equal); + } + }; +} + +#endif diff --git a/test/test_const_string_u32.cpp b/test/test_const_string_u32.cpp new file mode 100644 index 00000000..92e6e017 --- /dev/null +++ b/test/test_const_string_u32.cpp @@ -0,0 +1,525 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/const_u32string.h" +#include "etl/string_view.h" + +#if ETL_USING_CPP14 + +#undef STR +#define STR(x) U##x + +namespace +{ + SUITE(test_const_string_char32_t) + { + using Text = etl::const_u32string; + using View = etl::u32string_view; + + using TextSTD = std::u32string; + + static constexpr Text::const_pointer text_pointer = STR("Hello World"); + static constexpr Text text(STR("Hello World")); + static constexpr size_t Length = etl::strlen(STR("Hello World")); + + //************************************************************************* + template + bool Equal(const T1& compare_text, const T2& test_text) + { + return (compare_text.size() == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text.begin()); + } + + //************************************************************************* + template + bool Equal(const T1* compare_text, const T2& test_text) + { + return (etl::strlen(compare_text) == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text); + } + + //************************************************************************* + TEST(test_constructor_null_string) + { + static constexpr Text text_from_literal_empty(STR("")); + + static constexpr auto text_empty = text_from_literal_empty.empty(); + CHECK_TRUE(text_empty); + + static constexpr auto text_full = text_from_literal_empty.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal_empty.capacity(); + CHECK_EQUAL(0, text_capacity); + + static constexpr auto text_max_size = text_from_literal_empty.max_size(); + CHECK_EQUAL(0, text_max_size); + + static constexpr auto text_size = text_from_literal_empty.size(); + CHECK_EQUAL(0, text_size); + + static constexpr auto text_length = text_from_literal_empty.length(); + CHECK_EQUAL(0, text_length); + + static constexpr auto text_available = text_from_literal_empty.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal_empty.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal_empty.is_secure(); + CHECK_FALSE(text_is_secure); + } + + //************************************************************************* + TEST(test_constructor_char_pointer) + { + static constexpr Text text_from_pointer(text_pointer); + + static constexpr auto text_empty = text_from_pointer.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_pointer.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_pointer.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_pointer.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_pointer.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_pointer.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_pointer.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_pointer.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_pointer.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_pointer.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_pointer.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_pointer.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_pointer.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_pointer.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_pointer.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_pointer.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_pointer.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_pointer.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_pointer.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u32string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_from_literal) + { + static constexpr Text text_from_literal(STR("Hello World")); + + static constexpr auto text_empty = text_from_literal.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_literal.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_literal.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_literal.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_literal.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_literal.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_literal.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_literal.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_literal.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_literal.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_literal.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_literal.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_literal.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_literal.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_literal.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_literal.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u32string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_truncated) + { + static constexpr Text text_from_pointer(text_pointer, true); + static constexpr Text text_from_literal(STR("Hello World"), true); + + static constexpr auto text_from_pointer_is_truncated = text_from_pointer.is_truncated(); + CHECK_TRUE(text_from_pointer_is_truncated); + + static constexpr auto text_from_literal_is_truncated = text_from_literal.is_truncated(); + CHECK_TRUE(text_from_literal_is_truncated); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + static constexpr Text text_copy(text); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u32string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_copy_constructor_from_truncated) + { + static constexpr Text text_original(STR("Hello World"), true); + static constexpr Text text_copy(text_original); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_TRUE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u32string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_begin) + { + static constexpr Text::const_iterator p_begin = text.begin(); + static constexpr Text::const_iterator p_cbegin = text.cbegin(); + + CHECK_EQUAL(&text_pointer[0], p_begin); + CHECK_EQUAL(&text_pointer[0], p_cbegin); + } + + //************************************************************************* + TEST(test_index) + { + static constexpr Text::value_type c0 = text[0]; + static constexpr Text::value_type c1 = text[1]; + static constexpr Text::value_type c2 = text[2]; + static constexpr Text::value_type c3 = text[3]; + static constexpr Text::value_type c4 = text[4]; + static constexpr Text::value_type c5 = text[5]; + static constexpr Text::value_type c6 = text[6]; + static constexpr Text::value_type c7 = text[7]; + static constexpr Text::value_type c8 = text[8]; + static constexpr Text::value_type c9 = text[9]; + static constexpr Text::value_type c10 = text[10]; + static constexpr Text::value_type c11 = text[11]; + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + CHECK_EQUAL(text_pointer[11], c11); + } + + //************************************************************************* + TEST(test_at) + { + static constexpr Text::value_type c0 = text.at(0); + static constexpr Text::value_type c1 = text.at(1); + static constexpr Text::value_type c2 = text.at(2); + static constexpr Text::value_type c3 = text.at(3); + static constexpr Text::value_type c4 = text.at(4); + static constexpr Text::value_type c5 = text.at(5); + static constexpr Text::value_type c6 = text.at(6); + static constexpr Text::value_type c7 = text.at(7); + static constexpr Text::value_type c8 = text.at(8); + static constexpr Text::value_type c9 = text.at(9); + static constexpr Text::value_type c10 = text.at(10); + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + } + + //************************************************************************* + TEST(test_front) + { + CHECK_TRUE(text_pointer[0] == text.front()); + } + + //************************************************************************* + TEST(test_back) + { + CHECK_TRUE(text_pointer[Length - 1] == text.back()); + } + + //************************************************************************* + TEST(test_data) + { + static constexpr Text::const_pointer p_data = text.data(); + + CHECK_EQUAL(&text[0], p_data); + } + + //************************************************************************* + TEST(test_data_end) + { + static constexpr Text::const_pointer p_data = text.data_end(); + + CHECK_EQUAL(&text[Length], p_data); + } + + //************************************************************************* + TEST(test_c_str) + { + static constexpr Text::const_pointer p_data = text.c_str(); + + CHECK_EQUAL(&text[0], p_data); + CHECK_EQUAL(Length, etl::strlen(p_data)); + } + + //************************************************************************* + TEST(test_const_iterator) + { + static constexpr Text::const_iterator itr = text.begin(); + + Text::const_iterator begin = text.begin(); + Text::const_iterator end = text.end(); + + bool is_equal = std::equal(begin, end, itr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_const_reverse_iterator) + { + static constexpr Text::const_reverse_iterator ritr = text.rbegin(); + + etl::reverse_iterator rbegin(text_pointer + Length); + etl::reverse_iterator rend(text_pointer); + + bool is_equal = std::equal(rbegin, rend, ritr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_to_view) + { + static constexpr View view(text); + + CHECK_TRUE(text.begin() == view.begin()); + CHECK_TRUE(text.end() == view.end()); + + bool is_equal = std::equal(text.begin(), text.end(), view.begin()); + CHECK_TRUE(is_equal); + } + }; +} + +#endif diff --git a/test/test_const_string_u8.cpp b/test/test_const_string_u8.cpp new file mode 100644 index 00000000..eca0cf5f --- /dev/null +++ b/test/test_const_string_u8.cpp @@ -0,0 +1,528 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include "etl/platform.h" +#if ETL_USING_CPP20 + +#include +#include +#include +#include + +#include "etl/const_u8string.h" +#include "etl/string_view.h" + +#undef STR +#define STR(x) u8##x + +namespace +{ + SUITE(test_const_string_char8_t) + { + using Text = etl::const_u8string; + using View = etl::u8string_view; + +#if ETL_USING_CPP20 + using TextSTD = std::u8string; +#endif + + static constexpr const char8_t* text_pointer = u8"Hello World"; + static constexpr Text text(STR("Hello World")); + static constexpr size_t Length = etl::strlen(STR("Hello World")); + + //************************************************************************* + template + bool Equal(const T1& compare_text, const T2& test_text) + { + return (compare_text.size() == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text.begin()); + } + + //************************************************************************* + template + bool Equal(const T1* compare_text, const T2& test_text) + { + return (etl::strlen(compare_text) == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text); + } + + //************************************************************************* + TEST(test_constructor_null_string) + { + static constexpr Text text_from_literal_empty(STR("")); + + static constexpr auto text_empty = text_from_literal_empty.empty(); + CHECK_TRUE(text_empty); + + static constexpr auto text_full = text_from_literal_empty.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal_empty.capacity(); + CHECK_EQUAL(0, text_capacity); + + static constexpr auto text_max_size = text_from_literal_empty.max_size(); + CHECK_EQUAL(0, text_max_size); + + static constexpr auto text_size = text_from_literal_empty.size(); + CHECK_EQUAL(0, text_size); + + static constexpr auto text_length = text_from_literal_empty.length(); + CHECK_EQUAL(0, text_length); + + static constexpr auto text_available = text_from_literal_empty.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal_empty.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal_empty.is_secure(); + CHECK_FALSE(text_is_secure); + } + + //************************************************************************* + TEST(test_constructor_char_pointer) + { + static constexpr Text text_from_pointer(text_pointer); + + static constexpr auto text_empty = text_from_pointer.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_pointer.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_pointer.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_pointer.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_pointer.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_pointer.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_pointer.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_pointer.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_pointer.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_pointer.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_pointer.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_pointer.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_pointer.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_pointer.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_pointer.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_pointer.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_pointer.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_pointer.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_pointer.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u8string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_from_literal) + { + static constexpr Text text_from_literal(STR("Hello World")); + + static constexpr auto text_empty = text_from_literal.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_literal.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_literal.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_literal.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_literal.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_literal.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_literal.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_literal.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_literal.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_literal.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_literal.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_literal.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_literal.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_literal.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_literal.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_literal.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u8string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_truncated) + { + static constexpr Text text_from_pointer(text_pointer, true); + static constexpr Text text_from_literal(STR("Hello World"), true); + + static constexpr auto text_from_pointer_is_truncated = text_from_pointer.is_truncated(); + CHECK_TRUE(text_from_pointer_is_truncated); + + static constexpr auto text_from_literal_is_truncated = text_from_literal.is_truncated(); + CHECK_TRUE(text_from_literal_is_truncated); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + static constexpr Text text_copy(text); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u8string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_copy_constructor_from_truncated) + { + static constexpr Text text_original(STR("Hello World"), true); + static constexpr Text text_copy(text_original); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_TRUE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::u8string(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_begin) + { + static constexpr Text::const_iterator p_begin = text.begin(); + static constexpr Text::const_iterator p_cbegin = text.cbegin(); + + CHECK_EQUAL(&text_pointer[0], p_begin); + CHECK_EQUAL(&text_pointer[0], p_cbegin); + } + + //************************************************************************* + TEST(test_index) + { + static constexpr Text::value_type c0 = text[0]; + static constexpr Text::value_type c1 = text[1]; + static constexpr Text::value_type c2 = text[2]; + static constexpr Text::value_type c3 = text[3]; + static constexpr Text::value_type c4 = text[4]; + static constexpr Text::value_type c5 = text[5]; + static constexpr Text::value_type c6 = text[6]; + static constexpr Text::value_type c7 = text[7]; + static constexpr Text::value_type c8 = text[8]; + static constexpr Text::value_type c9 = text[9]; + static constexpr Text::value_type c10 = text[10]; + static constexpr Text::value_type c11 = text[11]; + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + CHECK_EQUAL(text_pointer[11], c11); + } + + //************************************************************************* + TEST(test_at) + { + static constexpr Text::value_type c0 = text.at(0); + static constexpr Text::value_type c1 = text.at(1); + static constexpr Text::value_type c2 = text.at(2); + static constexpr Text::value_type c3 = text.at(3); + static constexpr Text::value_type c4 = text.at(4); + static constexpr Text::value_type c5 = text.at(5); + static constexpr Text::value_type c6 = text.at(6); + static constexpr Text::value_type c7 = text.at(7); + static constexpr Text::value_type c8 = text.at(8); + static constexpr Text::value_type c9 = text.at(9); + static constexpr Text::value_type c10 = text.at(10); + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + } + + //************************************************************************* + TEST(test_front) + { + CHECK_TRUE(text_pointer[0] == text.front()); + } + + //************************************************************************* + TEST(test_back) + { + CHECK_TRUE(text_pointer[Length - 1] == text.back()); + } + + //************************************************************************* + TEST(test_data) + { + static constexpr Text::const_pointer p_data = text.data(); + + CHECK_EQUAL(&text[0], p_data); + } + + //************************************************************************* + TEST(test_data_end) + { + static constexpr Text::const_pointer p_data = text.data_end(); + + CHECK_EQUAL(&text[Length], p_data); + } + + //************************************************************************* + TEST(test_c_str) + { + static constexpr Text::const_pointer p_data = text.c_str(); + + CHECK_EQUAL(&text[0], p_data); + CHECK_EQUAL(Length, etl::strlen(p_data)); + } + + //************************************************************************* + TEST(test_const_iterator) + { + static constexpr Text::const_iterator itr = text.begin(); + + Text::const_iterator begin = text.begin(); + Text::const_iterator end = text.end(); + + bool is_equal = std::equal(begin, end, itr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_const_reverse_iterator) + { + static constexpr Text::const_reverse_iterator ritr = text.rbegin(); + + etl::reverse_iterator rbegin(text_pointer + Length); + etl::reverse_iterator rend(text_pointer); + + bool is_equal = std::equal(rbegin, rend, ritr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_to_view) + { + static constexpr View view(text); + + CHECK_TRUE(text.begin() == view.begin()); + CHECK_TRUE(text.end() == view.end()); + + bool is_equal = std::equal(text.begin(), text.end(), view.begin()); + CHECK_TRUE(is_equal); + } + }; +} + +#endif diff --git a/test/test_const_string_wchar_t.cpp b/test/test_const_string_wchar_t.cpp new file mode 100644 index 00000000..e44f237e --- /dev/null +++ b/test/test_const_string_wchar_t.cpp @@ -0,0 +1,543 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2025 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include +#include +#include +#include + +#include "etl/const_wstring.h" +#include "etl/string_view.h" + +#if ETL_USING_CPP14 + +#undef STR +#define STR(x) L##x + +namespace +{ + SUITE(test_const_string_wchar_t) + { + using Text = etl::const_wstring; + using View = etl::wstring_view; + + using TextSTD = std::wstring; + + static constexpr Text::const_pointer text_pointer = STR("Hello World"); + static constexpr Text text(STR("Hello World")); + static constexpr size_t Length = etl::strlen(STR("Hello World")); + + //************************************************************************* + template + bool Equal(const T1& compare_text, const T2& test_text) + { + return (compare_text.size() == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text.begin()); + } + + //************************************************************************* + template + bool Equal(const T1* compare_text, const T2& test_text) + { + return (etl::strlen(compare_text) == test_text.size()) && std::equal(test_text.begin(), test_text.end(), compare_text); + } + + //************************************************************************* + TEST(test_constructor_null_string) + { + static constexpr Text text_from_literal_empty(STR("")); + + static constexpr auto text_empty = text_from_literal_empty.empty(); + CHECK_TRUE(text_empty); + + static constexpr auto text_full = text_from_literal_empty.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal_empty.capacity(); + CHECK_EQUAL(0, text_capacity); + + static constexpr auto text_max_size = text_from_literal_empty.max_size(); + CHECK_EQUAL(0, text_max_size); + + static constexpr auto text_size = text_from_literal_empty.size(); + CHECK_EQUAL(0, text_size); + + static constexpr auto text_length = text_from_literal_empty.length(); + CHECK_EQUAL(0, text_length); + + static constexpr auto text_available = text_from_literal_empty.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal_empty.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal_empty.is_secure(); + CHECK_FALSE(text_is_secure); + } + + //************************************************************************* + TEST(test_constructor_char_pointer) + { + static constexpr Text text_from_pointer(text_pointer); + + static constexpr auto text_empty = text_from_pointer.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_pointer.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_pointer.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_pointer.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_pointer.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_pointer.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_pointer.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_pointer.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_pointer.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_pointer.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_pointer.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_pointer.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_pointer.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_pointer.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_pointer.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_pointer.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_pointer.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_pointer.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_pointer.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::wstring(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_from_literal) + { + static constexpr Text text_from_literal(STR("Hello World")); + + static constexpr auto text_empty = text_from_literal.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_from_literal.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_from_literal.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_from_literal.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_from_literal.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_from_literal.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_from_literal.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_from_literal.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_from_literal.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_from_literal.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_from_literal.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_from_literal.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_from_literal.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_from_literal.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_from_literal.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_from_literal.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_from_literal.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_from_literal.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_from_literal.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::wstring(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_constructor_truncated) + { + static constexpr Text text_from_pointer(text_pointer, true); + static constexpr Text text_from_literal(STR("Hello World"), true); + + static constexpr auto text_from_pointer_is_truncated = text_from_pointer.is_truncated(); + CHECK_TRUE(text_from_pointer_is_truncated); + + static constexpr auto text_from_literal_is_truncated = text_from_literal.is_truncated(); + CHECK_TRUE(text_from_literal_is_truncated); + } + + //************************************************************************* + TEST(test_copy_constructor) + { + static constexpr Text text_copy(text); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_FALSE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::wstring(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_copy_constructor_from_truncated) + { + static constexpr Text text_original(STR("Hello World"), true); + static constexpr Text text_copy(text_original); + + static constexpr auto text_empty = text_copy.empty(); + CHECK_FALSE(text_empty); + + static constexpr auto text_full = text_copy.full(); + CHECK_TRUE(text_full); + + static constexpr auto text_capacity = text_copy.capacity(); + CHECK_EQUAL(Length, text_capacity); + + static constexpr auto text_max_size = text_copy.max_size(); + CHECK_EQUAL(Length, text_max_size); + + static constexpr auto text_size = text_copy.size(); + CHECK_EQUAL(Length, text_size); + + static constexpr auto text_length = text_copy.length(); + CHECK_EQUAL(Length, text_length); + + static constexpr auto text_available = text_copy.available(); + CHECK_EQUAL(0, text_available); + + static constexpr auto text_is_truncated = text_copy.is_truncated(); + CHECK_TRUE(text_is_truncated); + + static constexpr auto text_is_secure = text_copy.is_secure(); + CHECK_FALSE(text_is_secure); + + static constexpr Text::const_pointer text_data = text_copy.data(); + CHECK_EQUAL(&text_pointer[0], text_data); + + static constexpr Text::const_pointer text_data_end = text_copy.data_end(); + CHECK_EQUAL(&text_pointer[Length], text_data_end); + + static constexpr auto text_begin = text_copy.begin(); + CHECK_EQUAL(&text_pointer[0], text_begin); + + static constexpr auto text_cbegin = text_copy.cbegin(); + CHECK_EQUAL(&text_pointer[0], text_cbegin); + + static constexpr auto text_rbegin = text_copy.rbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_rbegin)); + + static constexpr auto text_crbegin = text_copy.crbegin(); + CHECK_EQUAL(&text_pointer[Length - 1], etl::addressof(*text_crbegin)); + + static constexpr auto text_end = text_copy.end(); + CHECK_EQUAL(&text_pointer[Length], text_end); + + static constexpr auto text_cend = text_copy.cend(); + CHECK_EQUAL(&text_pointer[Length], text_cend); + + static constexpr auto text_rend = text_copy.rend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_rend)); + + static constexpr auto text_crend = text_copy.crend(); + CHECK_EQUAL(&text_pointer[0] - 1, etl::addressof(*text_crend)); + + bool is_equal = Equal(std::wstring(text_pointer), text); + CHECK(is_equal); + } + + //************************************************************************* + TEST(test_begin) + { + static constexpr Text::const_iterator p_begin = text.begin(); + static constexpr Text::const_iterator p_cbegin = text.cbegin(); + + CHECK_EQUAL(&text_pointer[0], p_begin); + CHECK_EQUAL(&text_pointer[0], p_cbegin); + } + + //************************************************************************* + TEST(test_index) + { + static constexpr Text::value_type c0 = text[0]; + static constexpr Text::value_type c1 = text[1]; + static constexpr Text::value_type c2 = text[2]; + static constexpr Text::value_type c3 = text[3]; + static constexpr Text::value_type c4 = text[4]; + static constexpr Text::value_type c5 = text[5]; + static constexpr Text::value_type c6 = text[6]; + static constexpr Text::value_type c7 = text[7]; + static constexpr Text::value_type c8 = text[8]; + static constexpr Text::value_type c9 = text[9]; + static constexpr Text::value_type c10 = text[10]; + static constexpr Text::value_type c11 = text[11]; + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + CHECK_EQUAL(text_pointer[11], c11); + } + + //************************************************************************* + TEST(test_at) + { + static constexpr Text::value_type c0 = text.at(0); + static constexpr Text::value_type c1 = text.at(1); + static constexpr Text::value_type c2 = text.at(2); + static constexpr Text::value_type c3 = text.at(3); + static constexpr Text::value_type c4 = text.at(4); + static constexpr Text::value_type c5 = text.at(5); + static constexpr Text::value_type c6 = text.at(6); + static constexpr Text::value_type c7 = text.at(7); + static constexpr Text::value_type c8 = text.at(8); + static constexpr Text::value_type c9 = text.at(9); + static constexpr Text::value_type c10 = text.at(10); + + CHECK_EQUAL(text_pointer[0], c0); + CHECK_EQUAL(text_pointer[1], c1); + CHECK_EQUAL(text_pointer[2], c2); + CHECK_EQUAL(text_pointer[3], c3); + CHECK_EQUAL(text_pointer[4], c4); + CHECK_EQUAL(text_pointer[5], c5); + CHECK_EQUAL(text_pointer[6], c6); + CHECK_EQUAL(text_pointer[7], c7); + CHECK_EQUAL(text_pointer[8], c8); + CHECK_EQUAL(text_pointer[9], c9); + CHECK_EQUAL(text_pointer[10], c10); + } + + //************************************************************************* + TEST(test_front) + { + CHECK_TRUE(text_pointer[0] == text.front()); + } + + //************************************************************************* + TEST(test_back) + { + CHECK_TRUE(text_pointer[Length - 1] == text.back()); + } + + //************************************************************************* + TEST(test_data) + { + static constexpr Text::const_pointer p_data = text.data(); + + CHECK_EQUAL(&text[0], p_data); + } + + //************************************************************************* + TEST(test_data_end) + { + static constexpr Text::const_pointer p_data = text.data_end(); + + CHECK_EQUAL(&text[Length], p_data); + } + + //************************************************************************* + TEST(test_c_str) + { + static constexpr Text::const_pointer p_data = text.c_str(); + + CHECK_EQUAL(&text[0], p_data); + CHECK_EQUAL(Length, etl::strlen(p_data)); + } + + //************************************************************************* + TEST(test_const_iterator) + { + static constexpr Text::const_iterator itr = text.begin(); + + Text::const_iterator begin = text.begin(); + Text::const_iterator end = text.end(); + + bool is_equal = std::equal(begin, end, itr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_const_reverse_iterator) + { + static constexpr Text::const_reverse_iterator ritr = text.rbegin(); + + etl::reverse_iterator rbegin(text_pointer + Length); + etl::reverse_iterator rend(text_pointer); + + bool is_equal = std::equal(rbegin, rend, ritr); + CHECK_TRUE(is_equal); + } + + //************************************************************************* + TEST(test_to_view) + { + static constexpr View view(text); + + CHECK_TRUE(text.begin() == view.begin()); + CHECK_TRUE(text.end() == view.end()); + + bool is_equal = std::equal(text.begin(), text.end(), view.begin()); + CHECK_TRUE(is_equal); + } + + //************************************************************************* +#if ETL_USING_STL + TEST(test_write_string_to_std_basic_ostream) + { + Text text1(STR("Hello World")); + + std::wstringstream sstream; + + sstream << text1; + + TextSTD sstream_string = sstream.str(); + + View sstream_view(sstream_string.data(), sstream_string.size()); + + CHECK(text1 == sstream_view); + } +#endif + }; +} + +#endif diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index d6af72ea..fec31736 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3293,11 +3293,16 @@ + + + + + @@ -9426,6 +9431,10 @@ + + + + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 2e066e65..ffd8a194 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1527,6 +1527,21 @@ ETL\Strings + + ETL\Strings + + + ETL\Strings + + + ETL\Strings + + + ETL\Strings + + + ETL\Strings + @@ -3689,6 +3704,18 @@ Tests\Strings + + Tests\Strings + + + Tests\Strings + + + Tests\Strings + + + Tests\Strings + Tests\Callbacks & Delegates