diff --git a/include/etl/private/string_utilities_helper.h b/include/etl/private/string_utilities_helper.h index a5fe9a17..67a980c2 100644 --- a/include/etl/private/string_utilities_helper.h +++ b/include/etl/private/string_utilities_helper.h @@ -305,12 +305,12 @@ namespace etl do { position = s.find(p_old, position); - if (position != etl::istring::npos) + if (position != TIString::npos) { s.replace(position, etl::strlen(p_old), p_new, etl::strlen(p_new)); position += etl::strlen(p_new); } - } while (position != etl::istring::npos); + } while (position != TIString::npos); ++pairsbegin; } diff --git a/include/etl/u16string_utilities.h b/include/etl/u16string_utilities.h new file mode 100644 index 00000000..fafb2881 --- /dev/null +++ b/include/etl/u16string_utilities.h @@ -0,0 +1,508 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2020 John Wellbelove, John Lagerquist + +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_U16STRING_UTILITIES_INCLUDED +#define ETL_U16STRING_UTILITIES_INCLUDED + +#include "platform.h" +#include "u16string.h" +#include "string_view.h" +#include "algorithm.h" +#include "private/string_utilities_helper.h" + +#include + +namespace etl +{ + //*************************************************************************** + /// trim_whitespace_left + /// Trim left of whitespace + //*************************************************************************** + inline void trim_whitespace_left(etl::iu16string& s) + { + etl::private_string_utilities::trim_from_left(s, u" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_whitespace_left + /// View trim left of whitespace + //*************************************************************************** + inline etl::u16string_view trim_whitespace_left(const etl::u16string_view& view) + { + return etl::private_string_utilities::view_trim_from_left(view, u" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_from_left + /// Trim left of specified characters + //*************************************************************************** + inline void trim_from_left(etl::iu16string& s, etl::iu16string::const_pointer trim_characters) + { + etl::private_string_utilities::trim_from_left(s, trim_characters); + } + + //*************************************************************************** + /// trim_from_left + /// View trim left of specified characters + //*************************************************************************** + inline etl::u16string_view trim_from_left(const etl::u16string_view& view, etl::iu16string::const_pointer trim_characters) + { + return etl::private_string_utilities::view_trim_from_left(view, trim_characters); + } + + //*************************************************************************** + /// trim_left + /// Trim left, up to, but not including, delimiters. + //*************************************************************************** + inline void trim_left(etl::iu16string& s, etl::iu16string::const_pointer delimiters) + { + etl::private_string_utilities::trim_left_delimiters(s, delimiters); + } + + //*************************************************************************** + /// trim_left + /// Trim left, up to, but not including, delimiters. + //*************************************************************************** + inline etl::u16string_view trim_left(etl::u16string_view& s, etl::u16string_view::const_pointer delimiters) + { + return etl::private_string_utilities::view_trim_left_delimiters(s, delimiters); + } + + //*************************************************************************** + /// trim_whitespace_right + /// Trim right of whitespace + //*************************************************************************** + inline void trim_whitespace_right(etl::iu16string& s) + { + etl::private_string_utilities::trim_from_right(s, u" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_whitespace_right + /// Trim right of whitespace + //*************************************************************************** + inline etl::u16string_view trim_whitespace_right(const etl::u16string_view& view) + { + return etl::private_string_utilities::view_trim_from_right(view, u" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_from_right + /// Trim right of specified characters + //*************************************************************************** + inline void trim_from_right(etl::iu16string& s, etl::iu16string::const_pointer trim_characters) + { + etl::private_string_utilities::trim_from_right(s, trim_characters); + } + + //*************************************************************************** + /// trim_from_right + /// Trim right of specified characters + //*************************************************************************** + inline etl::u16string_view trim_from_right(const etl::u16string_view& view, etl::iu16string::const_pointer trim_characters) + { + return etl::private_string_utilities::view_trim_from_right(view, trim_characters); + } + + //*************************************************************************** + /// trim_right + //*************************************************************************** + inline void trim_right(etl::iu16string& s, etl::iu16string::const_pointer delimiters) + { + etl::private_string_utilities::trim_right_delimiters(s, delimiters); + } + + //*************************************************************************** + /// trim_right + //*************************************************************************** + inline etl::u16string_view trim_right(const etl::u16string_view& view, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::view_trim_right_delimiters(view, delimiters); + } + + //*************************************************************************** + /// trim_whitespace + /// Trim both ends of whitespace + //*************************************************************************** + inline void trim_whitespace(etl::iu16string& s) + { + etl::private_string_utilities::trim_from(s, u" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_whitespace + /// Trim both ends of whitespace + //*************************************************************************** + inline etl::u16string_view trim_whitespace(const etl::u16string_view& view) + { + return etl::private_string_utilities::view_trim_from(view, u" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_from + /// Trim right of specified characters + //*************************************************************************** + inline void trim_from(etl::iu16string& s, etl::iu16string::const_pointer trim_characters) + { + etl::private_string_utilities::trim_from(s, trim_characters); + } + + //*************************************************************************** + /// trim_from + /// Trim right of specified characters + //*************************************************************************** + inline etl::u16string_view trim_from(const etl::u16string_view& view, etl::iu16string::const_pointer trim_characters) + { + return etl::private_string_utilities::view_trim_from(view, trim_characters); + } + + //*************************************************************************** + /// trim + //*************************************************************************** + inline void trim(etl::iu16string& s, etl::iu16string::const_pointer delimiters) + { + etl::private_string_utilities::trim_delimiters(s, delimiters); + } + + //*************************************************************************** + /// trim + //*************************************************************************** + inline etl::u16string_view trim(const etl::u16string_view& view, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::view_trim_delimiters(view, delimiters); + } + + //*************************************************************************** + /// reverse + /// Reverse the string + //*************************************************************************** + inline void reverse(etl::iu16string& s) + { + etl::private_string_utilities::reverse(s); + } + + //*************************************************************************** + /// Get up to the first n characters. + //*************************************************************************** + inline void left_n(etl::iu16string& s, size_t n) + { + n = (n > s.size()) ? s.size() : n; + + s.erase(s.begin() + n, s.end()); + } + + //*************************************************************************** + /// Get a view of up to the first n characters. + //*************************************************************************** + inline etl::u16string_view left_n(etl::u16string_view view, size_t n) + { + n = (n > view.size()) ? view.size() : n; + + return etl::u16string_view(view.begin(), view.begin() + n); + } + + //*************************************************************************** + /// Get up to the last n characters. + //*************************************************************************** + inline void right_n(etl::iu16string& s, size_t n) + { + n = (n > s.size()) ? s.size() : n; + + s.erase(s.begin(), s.end() - n); + } + + //*************************************************************************** + /// Get a view of up to the last n characters. + //*************************************************************************** + inline etl::u16string_view right_n(etl::u16string_view view, size_t n) + { + n = (n > view.size()) ? view.size() : n; + + return etl::u16string_view(view.end() - n, view.end()); + } + + //*************************************************************************** + /// pad_left + //*************************************************************************** + inline void pad_left(etl::iu16string& s, size_t required_size, etl::iu16string::value_type pad_char) + { + etl::private_string_utilities::pad_left(s, required_size, pad_char); + } + + //*************************************************************************** + /// pad_right + //*************************************************************************** + inline void pad_right(etl::iu16string& s, size_t required_size, etl::iu16string::value_type pad_char) + { + etl::private_string_utilities::pad_right(s, required_size, pad_char); + } + + //*************************************************************************** + /// pad + //*************************************************************************** + void pad(etl::iu16string& s, size_t required_size, string_pad_direction pad_direction, etl::iu16string::value_type pad_char) + { + etl::private_string_utilities::pad(s, required_size, pad_direction, pad_char); + } + + //*************************************************************************** + /// to_upper_case + //*************************************************************************** + inline void to_upper_case(etl::iu16string& s) + { + etl::iu16string::iterator itr = s.begin(); + + while (itr != s.end()) + { + *itr = etl::iu16string::value_type(::toupper(*itr)); + ++itr; + } + } + + //*************************************************************************** + /// to_lower_case + //*************************************************************************** + inline void to_lower_case(etl::iu16string& s) + { + etl::iu16string::iterator itr = s.begin(); + + while (itr != s.end()) + { + *itr = etl::iu16string::value_type(::tolower(*itr)); + ++itr; + } + } + + //*************************************************************************** + /// to_sentence_case + //*************************************************************************** + inline void to_sentence_case(etl::iu16string& s) + { + etl::iu16string::iterator itr = s.begin(); + + *itr = etl::iu16string::value_type(::toupper(*itr)); + ++itr; + + while (itr != s.end()) + { + *itr = etl::iu16string::value_type(::tolower(*itr)); + } + } + + //*************************************************************************** + /// transform + //*************************************************************************** + inline void transform(etl::iu16string& s, + const etl::pair* pairsbegin, + const etl::pair* pairsend) + { + etl::private_string_utilities::transform_characters(s, pairsbegin, pairsend); + } + + //*************************************************************************** + /// transform + //*************************************************************************** + inline void transform(etl::iu16string& s, + const etl::pair* pairsbegin, + const etl::pair* pairsend) + { + etl::private_string_utilities::transform_strings(s, pairsbegin, pairsend); + } + + //*************************************************************************** + /// get_token + //*************************************************************************** + inline etl::u16string_view get_token(const etl::iu16string& s, etl::iu16string::const_pointer delimiters, const u16string_view& last_view) + { + return etl::private_string_utilities::get_token(s, delimiters, last_view); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::iterator find_first_of(etl::iu16string::iterator first, etl::iu16string::iterator last, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(first, last, delimiters); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::const_iterator find_first_of(etl::iu16string::const_iterator first, etl::iu16string::const_iterator last, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(first, last, delimiters); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::iterator find_first_of(etl::iu16string& s, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(s.begin(), s.end(), delimiters); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::const_iterator find_first_of(const etl::iu16string& s, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::const_iterator find_first_of(const etl::u16string_view& s, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iu16string::iterator find_first_not_of(etl::iu16string::iterator first, etl::iu16string::iterator last, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(first, last, delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iu16string::const_iterator find_first_not_of(etl::iu16string::const_iterator first, etl::iu16string::const_iterator last, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(first, last, delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iu16string::iterator find_first_not_of(etl::iu16string& s, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(s.begin(), s.end(), delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iu16string::const_iterator find_first_not_of(const etl::iu16string& s, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iu16string::const_iterator find_first_not_of(const etl::u16string_view& view, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(view.cbegin(), view.cend(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::iterator find_last_of(etl::iu16string::iterator first, etl::iu16string::iterator last, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(first, last, delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::const_iterator find_last_of(etl::iu16string::const_iterator first, etl::iu16string::const_iterator last, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(first, last, delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::iterator find_last_of(etl::iu16string& s, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(s.begin(), s.end(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::const_iterator find_last_of(const etl::iu16string& s, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::const_iterator find_last_of(const etl::u16string_view& view, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(view.cbegin(), view.cend(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::iterator find_last_not_of(etl::iu16string::iterator first, etl::iu16string::iterator last, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(first, last, delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::const_iterator find_last_not_of(etl::iu16string::const_iterator first, etl::iu16string::const_iterator last, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(first, last, delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::iterator find_last_not_of(etl::iu16string& s, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(s.begin(), s.end(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::const_iterator find_last_not_of(const etl::iu16string& s, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu16string::const_iterator find_last_not_of(const etl::u16string_view& view, etl::iu16string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(view.cbegin(), view.cend(), delimiters); + } +} + +#endif \ No newline at end of file diff --git a/include/etl/u32string_utilities.h b/include/etl/u32string_utilities.h new file mode 100644 index 00000000..1ee73222 --- /dev/null +++ b/include/etl/u32string_utilities.h @@ -0,0 +1,508 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2020 John Wellbelove, John Lagerquist + +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_U32STRING_UTILITIES_INCLUDED +#define ETL_U32STRING_UTILITIES_INCLUDED + +#include "platform.h" +#include "u32string.h" +#include "string_view.h" +#include "algorithm.h" +#include "private/string_utilities_helper.h" + +#include + +namespace etl +{ + //*************************************************************************** + /// trim_whitespace_left + /// Trim left of whitespace + //*************************************************************************** + inline void trim_whitespace_left(etl::iu32string& s) + { + etl::private_string_utilities::trim_from_left(s, U" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_whitespace_left + /// View trim left of whitespace + //*************************************************************************** + inline etl::u32string_view trim_whitespace_left(const etl::u32string_view& view) + { + return etl::private_string_utilities::view_trim_from_left(view, U" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_from_left + /// Trim left of specified characters + //*************************************************************************** + inline void trim_from_left(etl::iu32string& s, etl::iu32string::const_pointer trim_characters) + { + etl::private_string_utilities::trim_from_left(s, trim_characters); + } + + //*************************************************************************** + /// trim_from_left + /// View trim left of specified characters + //*************************************************************************** + inline etl::u32string_view trim_from_left(const etl::u32string_view& view, etl::iu32string::const_pointer trim_characters) + { + return etl::private_string_utilities::view_trim_from_left(view, trim_characters); + } + + //*************************************************************************** + /// trim_left + /// Trim left, up to, but not including, delimiters. + //*************************************************************************** + inline void trim_left(etl::iu32string& s, etl::iu32string::const_pointer delimiters) + { + etl::private_string_utilities::trim_left_delimiters(s, delimiters); + } + + //*************************************************************************** + /// trim_left + /// Trim left, up to, but not including, delimiters. + //*************************************************************************** + inline etl::u32string_view trim_left(etl::u32string_view& s, etl::u32string_view::const_pointer delimiters) + { + return etl::private_string_utilities::view_trim_left_delimiters(s, delimiters); + } + + //*************************************************************************** + /// trim_whitespace_right + /// Trim right of whitespace + //*************************************************************************** + inline void trim_whitespace_right(etl::iu32string& s) + { + etl::private_string_utilities::trim_from_right(s, U" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_whitespace_right + /// Trim right of whitespace + //*************************************************************************** + inline etl::u32string_view trim_whitespace_right(const etl::u32string_view& view) + { + return etl::private_string_utilities::view_trim_from_right(view, U" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_from_right + /// Trim right of specified characters + //*************************************************************************** + inline void trim_from_right(etl::iu32string& s, etl::iu32string::const_pointer trim_characters) + { + etl::private_string_utilities::trim_from_right(s, trim_characters); + } + + //*************************************************************************** + /// trim_from_right + /// Trim right of specified characters + //*************************************************************************** + inline etl::u32string_view trim_from_right(const etl::u32string_view& view, etl::iu32string::const_pointer trim_characters) + { + return etl::private_string_utilities::view_trim_from_right(view, trim_characters); + } + + //*************************************************************************** + /// trim_right + //*************************************************************************** + inline void trim_right(etl::iu32string& s, etl::iu32string::const_pointer delimiters) + { + etl::private_string_utilities::trim_right_delimiters(s, delimiters); + } + + //*************************************************************************** + /// trim_right + //*************************************************************************** + inline etl::u32string_view trim_right(const etl::u32string_view& view, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::view_trim_right_delimiters(view, delimiters); + } + + //*************************************************************************** + /// trim_whitespace + /// Trim both ends of whitespace + //*************************************************************************** + inline void trim_whitespace(etl::iu32string& s) + { + etl::private_string_utilities::trim_from(s, U" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_whitespace + /// Trim both ends of whitespace + //*************************************************************************** + inline etl::u32string_view trim_whitespace(const etl::u32string_view& view) + { + return etl::private_string_utilities::view_trim_from(view, U" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_from + /// Trim right of specified characters + //*************************************************************************** + inline void trim_from(etl::iu32string& s, etl::iu32string::const_pointer trim_characters) + { + etl::private_string_utilities::trim_from(s, trim_characters); + } + + //*************************************************************************** + /// trim_from + /// Trim right of specified characters + //*************************************************************************** + inline etl::u32string_view trim_from(const etl::u32string_view& view, etl::iu32string::const_pointer trim_characters) + { + return etl::private_string_utilities::view_trim_from(view, trim_characters); + } + + //*************************************************************************** + /// trim + //*************************************************************************** + inline void trim(etl::iu32string& s, etl::iu32string::const_pointer delimiters) + { + etl::private_string_utilities::trim_delimiters(s, delimiters); + } + + //*************************************************************************** + /// trim + //*************************************************************************** + inline etl::u32string_view trim(const etl::u32string_view& view, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::view_trim_delimiters(view, delimiters); + } + + //*************************************************************************** + /// reverse + /// Reverse the string + //*************************************************************************** + inline void reverse(etl::iu32string& s) + { + etl::private_string_utilities::reverse(s); + } + + //*************************************************************************** + /// Get up to the first n characters. + //*************************************************************************** + inline void left_n(etl::iu32string& s, size_t n) + { + n = (n > s.size()) ? s.size() : n; + + s.erase(s.begin() + n, s.end()); + } + + //*************************************************************************** + /// Get a view of up to the first n characters. + //*************************************************************************** + inline etl::u32string_view left_n(etl::u32string_view view, size_t n) + { + n = (n > view.size()) ? view.size() : n; + + return etl::u32string_view(view.begin(), view.begin() + n); + } + + //*************************************************************************** + /// Get up to the last n characters. + //*************************************************************************** + inline void right_n(etl::iu32string& s, size_t n) + { + n = (n > s.size()) ? s.size() : n; + + s.erase(s.begin(), s.end() - n); + } + + //*************************************************************************** + /// Get a view of up to the last n characters. + //*************************************************************************** + inline etl::u32string_view right_n(etl::u32string_view view, size_t n) + { + n = (n > view.size()) ? view.size() : n; + + return etl::u32string_view(view.end() - n, view.end()); + } + + //*************************************************************************** + /// pad_left + //*************************************************************************** + inline void pad_left(etl::iu32string& s, size_t required_size, etl::iu32string::value_type pad_char) + { + etl::private_string_utilities::pad_left(s, required_size, pad_char); + } + + //*************************************************************************** + /// pad_right + //*************************************************************************** + inline void pad_right(etl::iu32string& s, size_t required_size, etl::iu32string::value_type pad_char) + { + etl::private_string_utilities::pad_right(s, required_size, pad_char); + } + + //*************************************************************************** + /// pad + //*************************************************************************** + void pad(etl::iu32string& s, size_t required_size, string_pad_direction pad_direction, etl::iu32string::value_type pad_char) + { + etl::private_string_utilities::pad(s, required_size, pad_direction, pad_char); + } + + //*************************************************************************** + /// to_upper_case + //*************************************************************************** + inline void to_upper_case(etl::iu32string& s) + { + etl::iu32string::iterator itr = s.begin(); + + while (itr != s.end()) + { + *itr = etl::iu32string::value_type(::toupper(*itr)); + ++itr; + } + } + + //*************************************************************************** + /// to_lower_case + //*************************************************************************** + inline void to_lower_case(etl::iu32string& s) + { + etl::iu32string::iterator itr = s.begin(); + + while (itr != s.end()) + { + *itr = etl::iu32string::value_type(::tolower(*itr)); + ++itr; + } + } + + //*************************************************************************** + /// to_sentence_case + //*************************************************************************** + inline void to_sentence_case(etl::iu32string& s) + { + etl::iu32string::iterator itr = s.begin(); + + *itr = etl::iu32string::value_type(::toupper(*itr)); + ++itr; + + while (itr != s.end()) + { + *itr = etl::iu32string::value_type(::tolower(*itr)); + } + } + + //*************************************************************************** + /// transform + //*************************************************************************** + inline void transform(etl::iu32string& s, + const etl::pair* pairsbegin, + const etl::pair* pairsend) + { + etl::private_string_utilities::transform_characters(s, pairsbegin, pairsend); + } + + //*************************************************************************** + /// transform + //*************************************************************************** + inline void transform(etl::iu32string& s, + const etl::pair* pairsbegin, + const etl::pair* pairsend) + { + etl::private_string_utilities::transform_strings(s, pairsbegin, pairsend); + } + + //*************************************************************************** + /// get_token + //*************************************************************************** + inline etl::u32string_view get_token(const etl::iu32string& s, etl::iu32string::const_pointer delimiters, const u32string_view& last_view) + { + return etl::private_string_utilities::get_token(s, delimiters, last_view); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::iterator find_first_of(etl::iu32string::iterator first, etl::iu32string::iterator last, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(first, last, delimiters); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::const_iterator find_first_of(etl::iu32string::const_iterator first, etl::iu32string::const_iterator last, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(first, last, delimiters); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::iterator find_first_of(etl::iu32string& s, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(s.begin(), s.end(), delimiters); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::const_iterator find_first_of(const etl::iu32string& s, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::const_iterator find_first_of(const etl::u32string_view& s, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iu32string::iterator find_first_not_of(etl::iu32string::iterator first, etl::iu32string::iterator last, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(first, last, delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iu32string::const_iterator find_first_not_of(etl::iu32string::const_iterator first, etl::iu32string::const_iterator last, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(first, last, delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iu32string::iterator find_first_not_of(etl::iu32string& s, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(s.begin(), s.end(), delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iu32string::const_iterator find_first_not_of(const etl::iu32string& s, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iu32string::const_iterator find_first_not_of(const etl::u32string_view& view, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(view.cbegin(), view.cend(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::iterator find_last_of(etl::iu32string::iterator first, etl::iu32string::iterator last, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(first, last, delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::const_iterator find_last_of(etl::iu32string::const_iterator first, etl::iu32string::const_iterator last, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(first, last, delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::iterator find_last_of(etl::iu32string& s, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(s.begin(), s.end(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::const_iterator find_last_of(const etl::iu32string& s, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::const_iterator find_last_of(const etl::u32string_view& view, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(view.cbegin(), view.cend(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::iterator find_last_not_of(etl::iu32string::iterator first, etl::iu32string::iterator last, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(first, last, delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::const_iterator find_last_not_of(etl::iu32string::const_iterator first, etl::iu32string::const_iterator last, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(first, last, delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::iterator find_last_not_of(etl::iu32string& s, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(s.begin(), s.end(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::const_iterator find_last_not_of(const etl::iu32string& s, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iu32string::const_iterator find_last_not_of(const etl::u32string_view& view, etl::iu32string::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(view.cbegin(), view.cend(), delimiters); + } +} + +#endif \ No newline at end of file diff --git a/include/etl/wstring_utilities.h b/include/etl/wstring_utilities.h new file mode 100644 index 00000000..10b5550d --- /dev/null +++ b/include/etl/wstring_utilities.h @@ -0,0 +1,508 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2020 John Wellbelove, John Lagerquist + +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_WSTRING_UTILITIES_INCLUDED +#define ETL_WSTRING_UTILITIES_INCLUDED + +#include "platform.h" +#include "wstring.h" +#include "string_view.h" +#include "algorithm.h" +#include "private/string_utilities_helper.h" + +#include + +namespace etl +{ + //*************************************************************************** + /// trim_whitespace_left + /// Trim left of whitespace + //*************************************************************************** + inline void trim_whitespace_left(etl::iwstring& s) + { + etl::private_string_utilities::trim_from_left(s, L" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_whitespace_left + /// View trim left of whitespace + //*************************************************************************** + inline etl::wstring_view trim_whitespace_left(const etl::wstring_view& view) + { + return etl::private_string_utilities::view_trim_from_left(view, L" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_from_left + /// Trim left of specified characters + //*************************************************************************** + inline void trim_from_left(etl::iwstring& s, etl::iwstring::const_pointer trim_characters) + { + etl::private_string_utilities::trim_from_left(s, trim_characters); + } + + //*************************************************************************** + /// trim_from_left + /// View trim left of specified characters + //*************************************************************************** + inline etl::wstring_view trim_from_left(const etl::wstring_view& view, etl::iwstring::const_pointer trim_characters) + { + return etl::private_string_utilities::view_trim_from_left(view, trim_characters); + } + + //*************************************************************************** + /// trim_left + /// Trim left, up to, but not including, delimiters. + //*************************************************************************** + inline void trim_left(etl::iwstring& s, etl::iwstring::const_pointer delimiters) + { + etl::private_string_utilities::trim_left_delimiters(s, delimiters); + } + + //*************************************************************************** + /// trim_left + /// Trim left, up to, but not including, delimiters. + //*************************************************************************** + inline etl::wstring_view trim_left(etl::wstring_view& s, etl::wstring_view::const_pointer delimiters) + { + return etl::private_string_utilities::view_trim_left_delimiters(s, delimiters); + } + + //*************************************************************************** + /// trim_whitespace_right + /// Trim right of whitespace + //*************************************************************************** + inline void trim_whitespace_right(etl::iwstring& s) + { + etl::private_string_utilities::trim_from_right(s, L" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_whitespace_right + /// Trim right of whitespace + //*************************************************************************** + inline etl::wstring_view trim_whitespace_right(const etl::wstring_view& view) + { + return etl::private_string_utilities::view_trim_from_right(view, L" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_from_right + /// Trim right of specified characters + //*************************************************************************** + inline void trim_from_right(etl::iwstring& s, etl::iwstring::const_pointer trim_characters) + { + etl::private_string_utilities::trim_from_right(s, trim_characters); + } + + //*************************************************************************** + /// trim_from_right + /// Trim right of specified characters + //*************************************************************************** + inline etl::wstring_view trim_from_right(const etl::wstring_view& view, etl::iwstring::const_pointer trim_characters) + { + return etl::private_string_utilities::view_trim_from_right(view, trim_characters); + } + + //*************************************************************************** + /// trim_right + //*************************************************************************** + inline void trim_right(etl::iwstring& s, etl::iwstring::const_pointer delimiters) + { + etl::private_string_utilities::trim_right_delimiters(s, delimiters); + } + + //*************************************************************************** + /// trim_right + //*************************************************************************** + inline etl::wstring_view trim_right(const etl::wstring_view& view, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::view_trim_right_delimiters(view, delimiters); + } + + //*************************************************************************** + /// trim_whitespace + /// Trim both ends of whitespace + //*************************************************************************** + inline void trim_whitespace(etl::iwstring& s) + { + etl::private_string_utilities::trim_from(s, L" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_whitespace + /// Trim both ends of whitespace + //*************************************************************************** + inline etl::wstring_view trim_whitespace(const etl::wstring_view& view) + { + return etl::private_string_utilities::view_trim_from(view, L" \t\n\r\f\v"); + } + + //*************************************************************************** + /// trim_from + /// Trim right of specified characters + //*************************************************************************** + inline void trim_from(etl::iwstring& s, etl::iwstring::const_pointer trim_characters) + { + etl::private_string_utilities::trim_from(s, trim_characters); + } + + //*************************************************************************** + /// trim_from + /// Trim right of specified characters + //*************************************************************************** + inline etl::wstring_view trim_from(const etl::wstring_view& view, etl::iwstring::const_pointer trim_characters) + { + return etl::private_string_utilities::view_trim_from(view, trim_characters); + } + + //*************************************************************************** + /// trim + //*************************************************************************** + inline void trim(etl::iwstring& s, etl::iwstring::const_pointer delimiters) + { + etl::private_string_utilities::trim_delimiters(s, delimiters); + } + + //*************************************************************************** + /// trim + //*************************************************************************** + inline etl::wstring_view trim(const etl::wstring_view& view, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::view_trim_delimiters(view, delimiters); + } + + //*************************************************************************** + /// reverse + /// Reverse the string + //*************************************************************************** + inline void reverse(etl::iwstring& s) + { + etl::private_string_utilities::reverse(s); + } + + //*************************************************************************** + /// Get up to the first n characters. + //*************************************************************************** + inline void left_n(etl::iwstring& s, size_t n) + { + n = (n > s.size()) ? s.size() : n; + + s.erase(s.begin() + n, s.end()); + } + + //*************************************************************************** + /// Get a view of up to the first n characters. + //*************************************************************************** + inline etl::wstring_view left_n(etl::wstring_view view, size_t n) + { + n = (n > view.size()) ? view.size() : n; + + return etl::wstring_view(view.begin(), view.begin() + n); + } + + //*************************************************************************** + /// Get up to the last n characters. + //*************************************************************************** + inline void right_n(etl::iwstring& s, size_t n) + { + n = (n > s.size()) ? s.size() : n; + + s.erase(s.begin(), s.end() - n); + } + + //*************************************************************************** + /// Get a view of up to the last n characters. + //*************************************************************************** + inline etl::wstring_view right_n(etl::wstring_view view, size_t n) + { + n = (n > view.size()) ? view.size() : n; + + return etl::wstring_view(view.end() - n, view.end()); + } + + //*************************************************************************** + /// pad_left + //*************************************************************************** + inline void pad_left(etl::iwstring& s, size_t required_size, etl::iwstring::value_type pad_char) + { + etl::private_string_utilities::pad_left(s, required_size, pad_char); + } + + //*************************************************************************** + /// pad_right + //*************************************************************************** + inline void pad_right(etl::iwstring& s, size_t required_size, etl::iwstring::value_type pad_char) + { + etl::private_string_utilities::pad_right(s, required_size, pad_char); + } + + //*************************************************************************** + /// pad + //*************************************************************************** + void pad(etl::iwstring& s, size_t required_size, string_pad_direction pad_direction, etl::iwstring::value_type pad_char) + { + etl::private_string_utilities::pad(s, required_size, pad_direction, pad_char); + } + + //*************************************************************************** + /// to_upper_case + //*************************************************************************** + inline void to_upper_case(etl::iwstring& s) + { + etl::iwstring::iterator itr = s.begin(); + + while (itr != s.end()) + { + *itr = etl::iwstring::value_type(::toupper(*itr)); + ++itr; + } + } + + //*************************************************************************** + /// to_lower_case + //*************************************************************************** + inline void to_lower_case(etl::iwstring& s) + { + etl::iwstring::iterator itr = s.begin(); + + while (itr != s.end()) + { + *itr = etl::iwstring::value_type(::tolower(*itr)); + ++itr; + } + } + + //*************************************************************************** + /// to_sentence_case + //*************************************************************************** + inline void to_sentence_case(etl::iwstring& s) + { + etl::iwstring::iterator itr = s.begin(); + + *itr = etl::iwstring::value_type(::toupper(*itr)); + ++itr; + + while (itr != s.end()) + { + *itr = etl::iwstring::value_type(::tolower(*itr)); + } + } + + //*************************************************************************** + /// transform + //*************************************************************************** + inline void transform(etl::iwstring& s, + const etl::pair* pairsbegin, + const etl::pair* pairsend) + { + etl::private_string_utilities::transform_characters(s, pairsbegin, pairsend); + } + + //*************************************************************************** + /// transform + //*************************************************************************** + inline void transform(etl::iwstring& s, + const etl::pair* pairsbegin, + const etl::pair* pairsend) + { + etl::private_string_utilities::transform_strings(s, pairsbegin, pairsend); + } + + //*************************************************************************** + /// get_token + //*************************************************************************** + inline etl::wstring_view get_token(const etl::iwstring& s, etl::iwstring::const_pointer delimiters, const wstring_view& last_view) + { + return etl::private_string_utilities::get_token(s, delimiters, last_view); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::iterator find_first_of(etl::iwstring::iterator first, etl::iwstring::iterator last, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(first, last, delimiters); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::const_iterator find_first_of(etl::iwstring::const_iterator first, etl::iwstring::const_iterator last, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(first, last, delimiters); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::iterator find_first_of(etl::iwstring& s, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(s.begin(), s.end(), delimiters); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::const_iterator find_first_of(const etl::iwstring& s, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find first of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::const_iterator find_first_of(const etl::wstring_view& s, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iwstring::iterator find_first_not_of(etl::iwstring::iterator first, etl::iwstring::iterator last, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(first, last, delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iwstring::const_iterator find_first_not_of(etl::iwstring::const_iterator first, etl::iwstring::const_iterator last, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(first, last, delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iwstring::iterator find_first_not_of(etl::iwstring& s, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(s.begin(), s.end(), delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iwstring::const_iterator find_first_not_of(const etl::iwstring& s, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find first not of delimiters within the string + //********************************************************************* + inline etl::iwstring::const_iterator find_first_not_of(const etl::wstring_view& view, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_first_not_of(view.cbegin(), view.cend(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::iterator find_last_of(etl::iwstring::iterator first, etl::iwstring::iterator last, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(first, last, delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::const_iterator find_last_of(etl::iwstring::const_iterator first, etl::iwstring::const_iterator last, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(first, last, delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::iterator find_last_of(etl::iwstring& s, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(s.begin(), s.end(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::const_iterator find_last_of(const etl::iwstring& s, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::const_iterator find_last_of(const etl::wstring_view& view, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_of(view.cbegin(), view.cend(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::iterator find_last_not_of(etl::iwstring::iterator first, etl::iwstring::iterator last, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(first, last, delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::const_iterator find_last_not_of(etl::iwstring::const_iterator first, etl::iwstring::const_iterator last, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(first, last, delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::iterator find_last_not_of(etl::iwstring& s, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(s.begin(), s.end(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::const_iterator find_last_not_of(const etl::iwstring& s, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(s.cbegin(), s.cend(), delimiters); + } + + //********************************************************************* + /// Find last of any of delimiters within the string + //********************************************************************* + inline etl::iwstring::const_iterator find_last_not_of(const etl::wstring_view& view, etl::iwstring::const_pointer delimiters) + { + return etl::private_string_utilities::find_last_not_of(view.cbegin(), view.cend(), delimiters); + } +} + +#endif \ No newline at end of file diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index e0da11ec..e7011ab8 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -448,14 +448,15 @@ - + + @@ -470,6 +471,7 @@ + @@ -578,9 +580,15 @@ + + + - + + + + @@ -592,8 +600,6 @@ - - @@ -608,7 +614,6 @@ - diff --git a/test/test_u16string_stream.cpp b/test/test_string_stream_u16.cpp similarity index 100% rename from test/test_u16string_stream.cpp rename to test/test_string_stream_u16.cpp diff --git a/test/test_u32string_stream.cpp b/test/test_string_stream_u32.cpp similarity index 100% rename from test/test_u32string_stream.cpp rename to test/test_string_stream_u32.cpp diff --git a/test/test_wstring_stream.cpp b/test/test_string_stream_wchar_t.cpp similarity index 100% rename from test/test_wstring_stream.cpp rename to test/test_string_stream_wchar_t.cpp diff --git a/test/test_string_utilities_char.cpp b/test/test_string_utilities.cpp similarity index 99% rename from test/test_string_utilities_char.cpp rename to test/test_string_utilities.cpp index 6d26a5e3..041fdbb7 100644 --- a/test/test_string_utilities_char.cpp +++ b/test/test_string_utilities.cpp @@ -263,7 +263,7 @@ namespace TEST(test_view_trim_left_string_delimiters) { String text(STR("qztfpHello Worldqztfp")); - String expected("Hello Worldqztfp"); + String expected(STR("Hello Worldqztfp")); StringView textview(text); StringView expectedview(expected); diff --git a/test/test_string_utilities_u16.cpp b/test/test_string_utilities_u16.cpp new file mode 100644 index 00000000..96fc6f0c --- /dev/null +++ b/test/test_string_utilities_u16.cpp @@ -0,0 +1,1431 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2020 jwellbelove + +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 "UnitTest++/UnitTest++.h" + +#include "etl/u16string.h" +#include "etl/string_view.h" +#include "etl/u16string_utilities.h" +#include "etl/vector.h" + +#undef STR +#define STR(x) u##x + +namespace +{ + SUITE(test_wstring_utilities_char) + { + static const size_t SIZE = 50; + + typedef etl::u16string String; + typedef etl::iu16string IString; + typedef etl::u16string_view StringView; + typedef etl::iu16string::value_type Char; + typedef etl::vector Vector; + + //************************************************************************* + TEST(test_trim_whitespace_left_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_whitespace_left(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_left_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_left(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_left) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + etl::trim_whitespace_left(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_left) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_left(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_left_nothing_to_trim) + { + String text(STR("Hello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + etl::trim_whitespace_left(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_left_nothing_to_trim) + { + String text(STR("Hello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_left(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_left_pointer_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_from_left(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_left_pointer_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_left(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_left_pointer) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + etl::trim_from_left(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_left_pointer) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_left(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_left_pointer_nothing_to_trim) + { + String text(STR("Hello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + etl::trim_from_left(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_left_pointer_nothing_to_trim) + { + String text(STR("Hello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_left(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_left_pointer_length_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_from_left(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_trim_left_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + etl::trim_left(text, STR("Hel")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_left_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_left(textview, STR("Hel")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_left_pointer_delimiters_nothing_to_trim) + { + String text(STR("Hello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + etl::trim_left(text, STR("Hel")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_left_pointer_delimiters_nothing_to_trim) + { + String text(STR("Hello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_left(textview, STR("Hel")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_view_trim_left_string_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_left(textview, STR("Hel")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_right_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_whitespace_right(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_right_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_right(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_right) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR(" \t\n\r\f\vHello World")); + + etl::trim_whitespace_right(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_right) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR(" \t\n\r\f\vHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_right(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_right_nothing_to_trim) + { + String text(STR(" \t\n\r\f\vHello World")); + String expected(STR(" \t\n\r\f\vHello World")); + + etl::trim_whitespace_right(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_right_nothing_to_trim) + { + String text(STR(" \t\n\r\f\vHello World")); + String expected(STR(" \t\n\r\f\vHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_right(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_right_pointer_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_from_right(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_right_pointer_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_right(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_right_pointer) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR(" \t\n\r\f\vHello World")); + + etl::trim_from_right(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_right_pointer) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR(" \t\n\r\f\vHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_right(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_right_pointer_nothing_to_trim) + { + String text(STR(" \t\n\r\f\vHello World")); + String expected(STR(" \t\n\r\f\vHello World")); + + etl::trim_from_right(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_right_pointer_nothing_to_trim) + { + String text(STR(" \t\n\r\f\vHello World")); + String expected(STR(" \t\n\r\f\vHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_right(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_right_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("qztfpHello World")); + + etl::trim_right(text, STR("rld")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_right_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("qztfpHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_right(textview, STR("rld")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_right_pointer_delimiters_nothing_to_trim) + { + String text(STR("qztfpHello World")); + String expected(STR("qztfpHello World")); + + etl::trim_right(text, STR("rld")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_right_pointer_delimiters_nothing_to_trim) + { + String text(STR("qztfpHello World")); + String expected(STR("qztfpHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_right(textview, STR("rld")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_whitespace(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World")); + + etl::trim_whitespace(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::trim_whitespace(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_from(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World")); + + etl::trim_from(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::trim_from(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello World")); + + etl::trim(text, STR("Hd")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim(textview, STR("Hd")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_pointer_delimiters_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::trim(text, STR("Hd")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_pointer_delimiters_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim(textview, STR("Hd")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_reverse) + { + String text(STR("Hello World")); + String expected(STR("dlroW olleH")); + + etl::reverse(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_right_n_view) + { + String text(STR("Hello World")); + String expected(STR("World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::right_n(textview, expected.size()); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_right_n_view_excess) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::right_n(textview, text.size() * 2U); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_right_n_string) + { + String text(STR("Hello World")); + String expected(STR("World")); + + etl::right_n(text, 5U); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_right_n_string_excess) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::right_n(text, text.size() * 2U); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_left_n_view) + { + String text(STR("Hello World")); + String expected(STR("Hello")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::left_n(textview, expected.size()); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_left_n_view_excess) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::left_n(textview, text.size() * 2U); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_left_n_string) + { + String text(STR("Hello World")); + String expected(STR("Hello")); + + etl::left_n(text, expected.size()); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_left_n_string_excess) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::left_n(text, text.size() * 2U); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_transform_characters) + { + String text(STR("This+++is a *file//name:")); + String expected(STR("This---is_a__-file__name_")); + + etl::pair lookup[] = + { + { STR('+'), STR('-') }, + { STR(' '), STR('_') }, + { STR('*'), STR('-') }, + { STR('/'), STR('_') }, + { STR(':'), STR('_') } + }; + + etl::transform(text, etl::begin(lookup), etl::end(lookup)); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_transform_characters_empty_string) + { + String text(STR("")); + String expected(STR("")); + + etl::pair lookup[] = + { + { STR('+'), STR('-') }, + { STR(' '), STR('_') }, + { STR('*'), STR('-') }, + { STR('/'), STR('_') }, + { STR(':'), STR('_') } + }; + + etl::transform(text, etl::begin(lookup), etl::end(lookup)); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_transform_strings) + { + String text(STR("This+++is a *file//name:")); + String expected(STR("Thisxyis%20a%20%20-file_name.txt")); + + etl::pair lookup[] = + { + { STR("+++"), STR("xy") }, + { STR(" "), STR("%20") }, + { STR("*"), STR("-") }, + { STR("//"), STR("_") }, + { STR(":"), STR(".txt") } + }; + + etl::transform(text, etl::begin(lookup), etl::end(lookup)); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_transform_strings_empty_strings) + { + String text(STR("")); + String expected(STR("")); + + etl::pair lookup[] = + { + { STR("+++"), STR("xy") }, + { STR(" "), STR("%20") }, + { STR("*"), STR("-") }, + { STR("//"), STR("_") }, + { STR(":"), STR(".txt") } + }; + + etl::transform(text, etl::begin(lookup), etl::end(lookup)); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_get_token_pointer_delimiters) + { + String text(STR(" The cat.sat, on;the:mat .,;:")); + Vector tokens; + + StringView token; + + while (token.end() != text.end()) + { + token = etl::get_token(text, STR(" .,;:"), token); + + if (!token.empty()) + { + tokens.emplace_back(token.begin(), token.end()); + } + } + + CHECK_EQUAL(6U, tokens.size()); + } + + //************************************************************************* + TEST(test_pad_left) + { + String text(STR("Hello World")); + String expected(STR("xxxxHello World")); + + etl::pad_left(text, expected.size(), STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_left_smaller) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::pad_left(text, text.size() - 1U, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_left_greater_than_capacity) + { + String text(STR("Hello World")); + String expected(text); + expected.insert(0U, text.capacity() - expected.size(), STR('x')); + + etl::pad_left(text, text.capacity() + 1U, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_right) + { + String text(STR("Hello World")); + String expected(STR("Hello Worldxxxx")); + + etl::pad_right(text, expected.size(), STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_right_smaller) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::pad_right(text, text.size() - 1U, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_right_greater_than_capacity) + { + String text(STR("Hello World")); + String expected(text); + expected.insert(text.size(), text.capacity() - expected.size(), STR('x')); + + etl::pad_right(text, text.capacity() + 1U, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_left) + { + String text(STR("Hello World")); + String expected(STR("xxxxHello World")); + + etl::pad(text, expected.size(), etl::string_pad_direction::LEFT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_left_smaller) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::pad(text, text.size() - 1U, etl::string_pad_direction::LEFT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_left_greater_than_capacity) + { + String text(STR("Hello World")); + String expected(text); + expected.insert(0U, text.capacity() - expected.size(), STR('x')); + + etl::pad(text, text.capacity() + 1U, etl::string_pad_direction::LEFT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_right) + { + String text(STR("Hello World")); + String expected(STR("Hello Worldxxxx")); + + etl::pad(text, expected.size(), etl::string_pad_direction::RIGHT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_right_smaller) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::pad(text, text.size() - 1U, etl::string_pad_direction::RIGHT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_right_greater_than_capacity) + { + String text(STR("Hello World")); + String expected(text); + expected.insert(text.size(), text.capacity() - expected.size(), STR('x')); + + etl::pad(text, text.capacity() + 1U, etl::string_pad_direction::RIGHT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_find_first_of_iterator_iterator) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_of(text.begin(), text.end(), STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_iterator_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_of(text.begin(), text.end(), STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_of_const_iterator_const_iterator) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_of(text.cbegin(), text.cend(), STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_const_iterator_const_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_of(text.begin(), text.end(), STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_of_string) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_of(text, STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_string_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_of(text, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_of_const_string) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_of(text, STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_const_string_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_of(text, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_of_string_view) + { + const String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_first_of(textview, STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_string_view_not_found) + { + const String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_first_of(textview, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_iterator_iterator) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_not_of(text.begin(), text.end(), STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_iterator_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + String::iterator itr = etl::find_first_not_of(text.begin(), text.end(), STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_const_iterator_const_iterator) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_not_of(text.cbegin(), text.cend(), STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_const_iterator_const_iterator_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_not_of(text.cbegin(), text.cend(), STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_string) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_not_of(text, STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_string_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_not_of(text, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_const_string) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_not_of(text, STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_const_string_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_not_of(text, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_string_view) + { + const String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_first_not_of(textview, STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_string_view_not_found) + { + const String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_first_not_of(textview, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_iterator_iterator) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_of(text.begin(), text.end(), STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_iterator_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_of(text.begin(), text.end(), STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_const_iterator_const_iterator) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_of(text.cbegin(), text.cend(), STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_const_iterator_const_iterator_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_of(text.cbegin(), text.cend(), STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_string) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_of(text, STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_string_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_of(text, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_const_string) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_of(text, STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_const_string_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_of(text, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_string_view) + { + String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_last_of(textview, STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_string_view_not_found) + { + String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_last_of(textview, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_iterator_iterator) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_not_of(text.begin(), text.end(), STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_iterator_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_not_of(text.begin(), text.end(), STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_const_iterator_const_iterator) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_not_of(text.cbegin(), text.cend(), STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_const_iterator_const_iterator_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_not_of(text.cbegin(), text.cend(), STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_string) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_not_of(text, STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_string_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_not_of(text, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_const_string) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_not_of(text, STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_const_string_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_not_of(text, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_string_view) + { + String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_last_not_of(textview, STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_string_view_not_found) + { + String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_last_not_of(textview, STR("abcHello World")); + + CHECK(text.end() == itr); + } + }; +} diff --git a/test/test_string_utilities_u32.cpp b/test/test_string_utilities_u32.cpp new file mode 100644 index 00000000..dec24c16 --- /dev/null +++ b/test/test_string_utilities_u32.cpp @@ -0,0 +1,1431 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2020 jwellbelove + +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 "UnitTest++/UnitTest++.h" + +#include "etl/u32string.h" +#include "etl/string_view.h" +#include "etl/u32string_utilities.h" +#include "etl/vector.h" + +#undef STR +#define STR(x) U##x + +namespace +{ + SUITE(test_wstring_utilities_char) + { + static const size_t SIZE = 50; + + typedef etl::u32string String; + typedef etl::iu32string IString; + typedef etl::u32string_view StringView; + typedef etl::iu32string::value_type Char; + typedef etl::vector Vector; + + //************************************************************************* + TEST(test_trim_whitespace_left_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_whitespace_left(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_left_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_left(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_left) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + etl::trim_whitespace_left(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_left) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_left(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_left_nothing_to_trim) + { + String text(STR("Hello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + etl::trim_whitespace_left(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_left_nothing_to_trim) + { + String text(STR("Hello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_left(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_left_pointer_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_from_left(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_left_pointer_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_left(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_left_pointer) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + etl::trim_from_left(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_left_pointer) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_left(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_left_pointer_nothing_to_trim) + { + String text(STR("Hello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + etl::trim_from_left(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_left_pointer_nothing_to_trim) + { + String text(STR("Hello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_left(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_left_pointer_length_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_from_left(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_trim_left_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + etl::trim_left(text, STR("Hel")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_left_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_left(textview, STR("Hel")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_left_pointer_delimiters_nothing_to_trim) + { + String text(STR("Hello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + etl::trim_left(text, STR("Hel")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_left_pointer_delimiters_nothing_to_trim) + { + String text(STR("Hello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_left(textview, STR("Hel")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_view_trim_left_string_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_left(textview, STR("Hel")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_right_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_whitespace_right(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_right_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_right(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_right) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR(" \t\n\r\f\vHello World")); + + etl::trim_whitespace_right(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_right) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR(" \t\n\r\f\vHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_right(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_right_nothing_to_trim) + { + String text(STR(" \t\n\r\f\vHello World")); + String expected(STR(" \t\n\r\f\vHello World")); + + etl::trim_whitespace_right(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_right_nothing_to_trim) + { + String text(STR(" \t\n\r\f\vHello World")); + String expected(STR(" \t\n\r\f\vHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_right(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_right_pointer_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_from_right(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_right_pointer_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_right(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_right_pointer) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR(" \t\n\r\f\vHello World")); + + etl::trim_from_right(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_right_pointer) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR(" \t\n\r\f\vHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_right(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_right_pointer_nothing_to_trim) + { + String text(STR(" \t\n\r\f\vHello World")); + String expected(STR(" \t\n\r\f\vHello World")); + + etl::trim_from_right(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_right_pointer_nothing_to_trim) + { + String text(STR(" \t\n\r\f\vHello World")); + String expected(STR(" \t\n\r\f\vHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_right(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_right_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("qztfpHello World")); + + etl::trim_right(text, STR("rld")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_right_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("qztfpHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_right(textview, STR("rld")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_right_pointer_delimiters_nothing_to_trim) + { + String text(STR("qztfpHello World")); + String expected(STR("qztfpHello World")); + + etl::trim_right(text, STR("rld")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_right_pointer_delimiters_nothing_to_trim) + { + String text(STR("qztfpHello World")); + String expected(STR("qztfpHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_right(textview, STR("rld")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_whitespace(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World")); + + etl::trim_whitespace(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::trim_whitespace(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_from(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World")); + + etl::trim_from(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::trim_from(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello World")); + + etl::trim(text, STR("Hd")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim(textview, STR("Hd")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_pointer_delimiters_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::trim(text, STR("Hd")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_pointer_delimiters_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim(textview, STR("Hd")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_reverse) + { + String text(STR("Hello World")); + String expected(STR("dlroW olleH")); + + etl::reverse(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_right_n_view) + { + String text(STR("Hello World")); + String expected(STR("World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::right_n(textview, expected.size()); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_right_n_view_excess) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::right_n(textview, text.size() * 2U); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_right_n_string) + { + String text(STR("Hello World")); + String expected(STR("World")); + + etl::right_n(text, 5U); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_right_n_string_excess) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::right_n(text, text.size() * 2U); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_left_n_view) + { + String text(STR("Hello World")); + String expected(STR("Hello")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::left_n(textview, expected.size()); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_left_n_view_excess) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::left_n(textview, text.size() * 2U); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_left_n_string) + { + String text(STR("Hello World")); + String expected(STR("Hello")); + + etl::left_n(text, expected.size()); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_left_n_string_excess) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::left_n(text, text.size() * 2U); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_transform_characters) + { + String text(STR("This+++is a *file//name:")); + String expected(STR("This---is_a__-file__name_")); + + etl::pair lookup[] = + { + { STR('+'), STR('-') }, + { STR(' '), STR('_') }, + { STR('*'), STR('-') }, + { STR('/'), STR('_') }, + { STR(':'), STR('_') } + }; + + etl::transform(text, etl::begin(lookup), etl::end(lookup)); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_transform_characters_empty_string) + { + String text(STR("")); + String expected(STR("")); + + etl::pair lookup[] = + { + { STR('+'), STR('-') }, + { STR(' '), STR('_') }, + { STR('*'), STR('-') }, + { STR('/'), STR('_') }, + { STR(':'), STR('_') } + }; + + etl::transform(text, etl::begin(lookup), etl::end(lookup)); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_transform_strings) + { + String text(STR("This+++is a *file//name:")); + String expected(STR("Thisxyis%20a%20%20-file_name.txt")); + + etl::pair lookup[] = + { + { STR("+++"), STR("xy") }, + { STR(" "), STR("%20") }, + { STR("*"), STR("-") }, + { STR("//"), STR("_") }, + { STR(":"), STR(".txt") } + }; + + etl::transform(text, etl::begin(lookup), etl::end(lookup)); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_transform_strings_empty_strings) + { + String text(STR("")); + String expected(STR("")); + + etl::pair lookup[] = + { + { STR("+++"), STR("xy") }, + { STR(" "), STR("%20") }, + { STR("*"), STR("-") }, + { STR("//"), STR("_") }, + { STR(":"), STR(".txt") } + }; + + etl::transform(text, etl::begin(lookup), etl::end(lookup)); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_get_token_pointer_delimiters) + { + String text(STR(" The cat.sat, on;the:mat .,;:")); + Vector tokens; + + StringView token; + + while (token.end() != text.end()) + { + token = etl::get_token(text, STR(" .,;:"), token); + + if (!token.empty()) + { + tokens.emplace_back(token.begin(), token.end()); + } + } + + CHECK_EQUAL(6U, tokens.size()); + } + + //************************************************************************* + TEST(test_pad_left) + { + String text(STR("Hello World")); + String expected(STR("xxxxHello World")); + + etl::pad_left(text, expected.size(), STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_left_smaller) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::pad_left(text, text.size() - 1U, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_left_greater_than_capacity) + { + String text(STR("Hello World")); + String expected(text); + expected.insert(0U, text.capacity() - expected.size(), STR('x')); + + etl::pad_left(text, text.capacity() + 1U, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_right) + { + String text(STR("Hello World")); + String expected(STR("Hello Worldxxxx")); + + etl::pad_right(text, expected.size(), STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_right_smaller) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::pad_right(text, text.size() - 1U, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_right_greater_than_capacity) + { + String text(STR("Hello World")); + String expected(text); + expected.insert(text.size(), text.capacity() - expected.size(), STR('x')); + + etl::pad_right(text, text.capacity() + 1U, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_left) + { + String text(STR("Hello World")); + String expected(STR("xxxxHello World")); + + etl::pad(text, expected.size(), etl::string_pad_direction::LEFT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_left_smaller) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::pad(text, text.size() - 1U, etl::string_pad_direction::LEFT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_left_greater_than_capacity) + { + String text(STR("Hello World")); + String expected(text); + expected.insert(0U, text.capacity() - expected.size(), STR('x')); + + etl::pad(text, text.capacity() + 1U, etl::string_pad_direction::LEFT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_right) + { + String text(STR("Hello World")); + String expected(STR("Hello Worldxxxx")); + + etl::pad(text, expected.size(), etl::string_pad_direction::RIGHT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_right_smaller) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::pad(text, text.size() - 1U, etl::string_pad_direction::RIGHT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_right_greater_than_capacity) + { + String text(STR("Hello World")); + String expected(text); + expected.insert(text.size(), text.capacity() - expected.size(), STR('x')); + + etl::pad(text, text.capacity() + 1U, etl::string_pad_direction::RIGHT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_find_first_of_iterator_iterator) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_of(text.begin(), text.end(), STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_iterator_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_of(text.begin(), text.end(), STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_of_const_iterator_const_iterator) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_of(text.cbegin(), text.cend(), STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_const_iterator_const_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_of(text.begin(), text.end(), STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_of_string) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_of(text, STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_string_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_of(text, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_of_const_string) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_of(text, STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_const_string_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_of(text, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_of_string_view) + { + const String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_first_of(textview, STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_string_view_not_found) + { + const String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_first_of(textview, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_iterator_iterator) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_not_of(text.begin(), text.end(), STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_iterator_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + String::iterator itr = etl::find_first_not_of(text.begin(), text.end(), STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_const_iterator_const_iterator) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_not_of(text.cbegin(), text.cend(), STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_const_iterator_const_iterator_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_not_of(text.cbegin(), text.cend(), STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_string) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_not_of(text, STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_string_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_not_of(text, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_const_string) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_not_of(text, STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_const_string_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_not_of(text, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_string_view) + { + const String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_first_not_of(textview, STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_string_view_not_found) + { + const String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_first_not_of(textview, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_iterator_iterator) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_of(text.begin(), text.end(), STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_iterator_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_of(text.begin(), text.end(), STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_const_iterator_const_iterator) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_of(text.cbegin(), text.cend(), STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_const_iterator_const_iterator_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_of(text.cbegin(), text.cend(), STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_string) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_of(text, STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_string_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_of(text, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_const_string) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_of(text, STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_const_string_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_of(text, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_string_view) + { + String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_last_of(textview, STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_string_view_not_found) + { + String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_last_of(textview, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_iterator_iterator) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_not_of(text.begin(), text.end(), STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_iterator_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_not_of(text.begin(), text.end(), STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_const_iterator_const_iterator) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_not_of(text.cbegin(), text.cend(), STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_const_iterator_const_iterator_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_not_of(text.cbegin(), text.cend(), STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_string) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_not_of(text, STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_string_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_not_of(text, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_const_string) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_not_of(text, STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_const_string_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_not_of(text, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_string_view) + { + String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_last_not_of(textview, STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_string_view_not_found) + { + String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_last_not_of(textview, STR("abcHello World")); + + CHECK(text.end() == itr); + } + }; +} diff --git a/test/test_string_utilities_wchar_t.cpp b/test/test_string_utilities_wchar_t.cpp new file mode 100644 index 00000000..12e505d3 --- /dev/null +++ b/test/test_string_utilities_wchar_t.cpp @@ -0,0 +1,1431 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2020 jwellbelove + +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 "UnitTest++/UnitTest++.h" + +#include "etl/wstring.h" +#include "etl/string_view.h" +#include "etl/wstring_utilities.h" +#include "etl/vector.h" + +#undef STR +#define STR(x) L##x + +namespace +{ + SUITE(test_wstring_utilities_char) + { + static const size_t SIZE = 50; + + typedef etl::wstring String; + typedef etl::iwstring IString; + typedef etl::wstring_view StringView; + typedef etl::iwstring::value_type Char; + typedef etl::vector Vector; + + //************************************************************************* + TEST(test_trim_whitespace_left_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_whitespace_left(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_left_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_left(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_left) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + etl::trim_whitespace_left(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_left) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_left(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_left_nothing_to_trim) + { + String text(STR("Hello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + etl::trim_whitespace_left(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_left_nothing_to_trim) + { + String text(STR("Hello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_left(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_left_pointer_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_from_left(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_left_pointer_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_left(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_left_pointer) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + etl::trim_from_left(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_left_pointer) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_left(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_left_pointer_nothing_to_trim) + { + String text(STR("Hello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + etl::trim_from_left(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_left_pointer_nothing_to_trim) + { + String text(STR("Hello World\t\n\r\f\v ")); + String expected(STR("Hello World\t\n\r\f\v ")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_left(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_left_pointer_length_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_from_left(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_trim_left_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + etl::trim_left(text, STR("Hel")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_left_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_left(textview, STR("Hel")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_left_pointer_delimiters_nothing_to_trim) + { + String text(STR("Hello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + etl::trim_left(text, STR("Hel")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_left_pointer_delimiters_nothing_to_trim) + { + String text(STR("Hello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_left(textview, STR("Hel")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_view_trim_left_string_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello Worldqztfp")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_left(textview, STR("Hel")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_right_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_whitespace_right(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_right_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_right(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_right) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR(" \t\n\r\f\vHello World")); + + etl::trim_whitespace_right(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_right) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR(" \t\n\r\f\vHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_right(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_right_nothing_to_trim) + { + String text(STR(" \t\n\r\f\vHello World")); + String expected(STR(" \t\n\r\f\vHello World")); + + etl::trim_whitespace_right(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_right_nothing_to_trim) + { + String text(STR(" \t\n\r\f\vHello World")); + String expected(STR(" \t\n\r\f\vHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace_right(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_right_pointer_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_from_right(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_right_pointer_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_right(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_right_pointer) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR(" \t\n\r\f\vHello World")); + + etl::trim_from_right(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_right_pointer) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR(" \t\n\r\f\vHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_right(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_right_pointer_nothing_to_trim) + { + String text(STR(" \t\n\r\f\vHello World")); + String expected(STR(" \t\n\r\f\vHello World")); + + etl::trim_from_right(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_right_pointer_nothing_to_trim) + { + String text(STR(" \t\n\r\f\vHello World")); + String expected(STR(" \t\n\r\f\vHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from_right(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_right_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("qztfpHello World")); + + etl::trim_right(text, STR("rld")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_right_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("qztfpHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_right(textview, STR("rld")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_right_pointer_delimiters_nothing_to_trim) + { + String text(STR("qztfpHello World")); + String expected(STR("qztfpHello World")); + + etl::trim_right(text, STR("rld")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_right_pointer_delimiters_nothing_to_trim) + { + String text(STR("qztfpHello World")); + String expected(STR("qztfpHello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_right(textview, STR("rld")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_whitespace(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World")); + + etl::trim_whitespace(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_whitespace_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::trim_whitespace(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_whitespace_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_whitespace(textview); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_empty) + { + String text(STR("")); + String expected(STR("")); + + etl::trim_from(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_empty) + { + String text(STR("")); + String expected(STR("")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World")); + + etl::trim_from(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from) + { + String text(STR(" \t\n\r\f\vHello World\t\n\r\f\v ")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_from_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::trim_from(text, STR(" \t\n\r\f\v")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_from_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim_from(textview, STR(" \t\n\r\f\v")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello World")); + + etl::trim(text, STR("Hd")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_pointer_delimiters) + { + String text(STR("qztfpHello Worldqztfp")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim(textview, STR("Hd")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_trim_pointer_delimiters_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::trim(text, STR("Hd")); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_view_trim_pointer_delimiters_nothing_to_trim) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::trim(textview, STR("Hd")); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_reverse) + { + String text(STR("Hello World")); + String expected(STR("dlroW olleH")); + + etl::reverse(text); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_right_n_view) + { + String text(STR("Hello World")); + String expected(STR("World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::right_n(textview, expected.size()); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_right_n_view_excess) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::right_n(textview, text.size() * 2U); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_right_n_string) + { + String text(STR("Hello World")); + String expected(STR("World")); + + etl::right_n(text, 5U); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_right_n_string_excess) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::right_n(text, text.size() * 2U); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_left_n_view) + { + String text(STR("Hello World")); + String expected(STR("Hello")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::left_n(textview, expected.size()); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_left_n_view_excess) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + StringView textview(text); + StringView expectedview(expected); + + StringView view = etl::left_n(textview, text.size() * 2U); + + CHECK(expectedview == view); + } + + //************************************************************************* + TEST(test_left_n_string) + { + String text(STR("Hello World")); + String expected(STR("Hello")); + + etl::left_n(text, expected.size()); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_left_n_string_excess) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::left_n(text, text.size() * 2U); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_transform_characters) + { + String text(STR("This+++is a *file//name:")); + String expected(STR("This---is_a__-file__name_")); + + etl::pair lookup[] = + { + { STR('+'), STR('-') }, + { STR(' '), STR('_') }, + { STR('*'), STR('-') }, + { STR('/'), STR('_') }, + { STR(':'), STR('_') } + }; + + etl::transform(text, etl::begin(lookup), etl::end(lookup)); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_transform_characters_empty_string) + { + String text(STR("")); + String expected(STR("")); + + etl::pair lookup[] = + { + { STR('+'), STR('-') }, + { STR(' '), STR('_') }, + { STR('*'), STR('-') }, + { STR('/'), STR('_') }, + { STR(':'), STR('_') } + }; + + etl::transform(text, etl::begin(lookup), etl::end(lookup)); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_transform_strings) + { + String text(STR("This+++is a *file//name:")); + String expected(STR("Thisxyis%20a%20%20-file_name.txt")); + + etl::pair lookup[] = + { + { STR("+++"), STR("xy") }, + { STR(" "), STR("%20") }, + { STR("*"), STR("-") }, + { STR("//"), STR("_") }, + { STR(":"), STR(".txt") } + }; + + etl::transform(text, etl::begin(lookup), etl::end(lookup)); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_transform_strings_empty_strings) + { + String text(STR("")); + String expected(STR("")); + + etl::pair lookup[] = + { + { STR("+++"), STR("xy") }, + { STR(" "), STR("%20") }, + { STR("*"), STR("-") }, + { STR("//"), STR("_") }, + { STR(":"), STR(".txt") } + }; + + etl::transform(text, etl::begin(lookup), etl::end(lookup)); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_get_token_pointer_delimiters) + { + String text(STR(" The cat.sat, on;the:mat .,;:")); + Vector tokens; + + StringView token; + + while (token.end() != text.end()) + { + token = etl::get_token(text, STR(" .,;:"), token); + + if (!token.empty()) + { + tokens.emplace_back(token.begin(), token.end()); + } + } + + CHECK_EQUAL(6U, tokens.size()); + } + + //************************************************************************* + TEST(test_pad_left) + { + String text(STR("Hello World")); + String expected(STR("xxxxHello World")); + + etl::pad_left(text, expected.size(), STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_left_smaller) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::pad_left(text, text.size() - 1U, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_left_greater_than_capacity) + { + String text(STR("Hello World")); + String expected(text); + expected.insert(0U, text.capacity() - expected.size(), STR('x')); + + etl::pad_left(text, text.capacity() + 1U, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_right) + { + String text(STR("Hello World")); + String expected(STR("Hello Worldxxxx")); + + etl::pad_right(text, expected.size(), STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_right_smaller) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::pad_right(text, text.size() - 1U, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_right_greater_than_capacity) + { + String text(STR("Hello World")); + String expected(text); + expected.insert(text.size(), text.capacity() - expected.size(), STR('x')); + + etl::pad_right(text, text.capacity() + 1U, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_left) + { + String text(STR("Hello World")); + String expected(STR("xxxxHello World")); + + etl::pad(text, expected.size(), etl::string_pad_direction::LEFT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_left_smaller) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::pad(text, text.size() - 1U, etl::string_pad_direction::LEFT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_left_greater_than_capacity) + { + String text(STR("Hello World")); + String expected(text); + expected.insert(0U, text.capacity() - expected.size(), STR('x')); + + etl::pad(text, text.capacity() + 1U, etl::string_pad_direction::LEFT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_right) + { + String text(STR("Hello World")); + String expected(STR("Hello Worldxxxx")); + + etl::pad(text, expected.size(), etl::string_pad_direction::RIGHT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_right_smaller) + { + String text(STR("Hello World")); + String expected(STR("Hello World")); + + etl::pad(text, text.size() - 1U, etl::string_pad_direction::RIGHT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_pad_select_right_greater_than_capacity) + { + String text(STR("Hello World")); + String expected(text); + expected.insert(text.size(), text.capacity() - expected.size(), STR('x')); + + etl::pad(text, text.capacity() + 1U, etl::string_pad_direction::RIGHT, STR('x')); + + CHECK(expected == text); + } + + //************************************************************************* + TEST(test_find_first_of_iterator_iterator) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_of(text.begin(), text.end(), STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_iterator_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_of(text.begin(), text.end(), STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_of_const_iterator_const_iterator) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_of(text.cbegin(), text.cend(), STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_const_iterator_const_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_of(text.begin(), text.end(), STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_of_string) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_of(text, STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_string_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_of(text, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_of_const_string) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_of(text, STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_const_string_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_of(text, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_of_string_view) + { + const String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_first_of(textview, STR("Hel")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_of_string_view_not_found) + { + const String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_first_of(textview, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_iterator_iterator) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_not_of(text.begin(), text.end(), STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_iterator_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + String::iterator itr = etl::find_first_not_of(text.begin(), text.end(), STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_const_iterator_const_iterator) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_not_of(text.cbegin(), text.cend(), STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_const_iterator_const_iterator_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_not_of(text.cbegin(), text.cend(), STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_string) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_not_of(text, STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_string_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_first_not_of(text, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_const_string) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_not_of(text, STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_const_string_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_first_not_of(text, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_string_view) + { + const String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_first_not_of(textview, STR("abc")); + + CHECK_EQUAL(STR('H'), *itr); + } + + //************************************************************************* + TEST(test_find_first_not_of_string_view_not_found) + { + const String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_first_not_of(textview, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_iterator_iterator) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_of(text.begin(), text.end(), STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_iterator_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_of(text.begin(), text.end(), STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_const_iterator_const_iterator) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_of(text.cbegin(), text.cend(), STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_const_iterator_const_iterator_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_of(text.cbegin(), text.cend(), STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_string) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_of(text, STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_string_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_of(text, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_const_string) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_of(text, STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_const_string_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_of(text, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_of_string_view) + { + String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_last_of(textview, STR("rld")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_of_string_view_not_found) + { + String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_last_of(textview, STR("xyz")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_iterator_iterator) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_not_of(text.begin(), text.end(), STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_iterator_iterator_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_not_of(text.begin(), text.end(), STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_const_iterator_const_iterator) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_not_of(text.cbegin(), text.cend(), STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_const_iterator_const_iterator_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_not_of(text.cbegin(), text.cend(), STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_string) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_not_of(text, STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_string_not_found) + { + String text(STR("abcHello Worldabc")); + + String::iterator itr = etl::find_last_not_of(text, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_const_string) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_not_of(text, STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_const_string_not_found) + { + const String text(STR("abcHello Worldabc")); + + String::const_iterator itr = etl::find_last_not_of(text, STR("abcHello World")); + + CHECK(text.end() == itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_string_view) + { + String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_last_not_of(textview, STR("abc")); + + CHECK_EQUAL(STR('d'), *itr); + } + + //************************************************************************* + TEST(test_find_last_not_of_string_view_not_found) + { + String text(STR("abcHello Worldabc")); + StringView textview(text); + + String::const_iterator itr = etl::find_last_not_of(textview, STR("abcHello World")); + + CHECK(text.end() == itr); + } + }; +} diff --git a/test/vs2019/etl.vcxproj b/test/vs2019/etl.vcxproj index 6a0e77b3..60b8fe00 100644 --- a/test/vs2019/etl.vcxproj +++ b/test/vs2019/etl.vcxproj @@ -1136,8 +1136,10 @@ + + @@ -1235,6 +1237,7 @@ + @@ -1630,7 +1633,10 @@ - + + + + @@ -1643,8 +1649,8 @@ - - + + @@ -1659,7 +1665,7 @@ - + diff --git a/test/vs2019/etl.vcxproj.filters b/test/vs2019/etl.vcxproj.filters index e376a5df..470822a0 100644 --- a/test/vs2019/etl.vcxproj.filters +++ b/test/vs2019/etl.vcxproj.filters @@ -876,6 +876,15 @@ ETL\Private + + ETL\Strings + + + ETL\Strings + + + ETL\Strings + @@ -1355,16 +1364,25 @@ Source Files - + Source Files - + Source Files - + Source Files - + + Source Files + + + Source Files + + + Source Files + + Source Files