From 602261ce39b567c51eee16be2c9d90a8e776553f Mon Sep 17 00:00:00 2001 From: Aleksander Dejewski Date: Thu, 19 Dec 2024 14:33:02 +0100 Subject: [PATCH 01/55] Add contains() method to etl::unordered_map and etl::unordered_set (#990) * Add contains() method to etl::unordered_map and etl::unordered_set * Add contains() method to etl::unordered_multiset and etl::unordered_multimap Use predefined variables in UT Move contains() method to correct place in etl::unordered_set * Fix contains() parameter type --- include/etl/unordered_map.h | 8 ++++++++ include/etl/unordered_multimap.h | 8 ++++++++ include/etl/unordered_multiset.h | 8 ++++++++ include/etl/unordered_set.h | 8 ++++++++ test/test_unordered_map.cpp | 11 +++++++++++ test/test_unordered_multimap.cpp | 11 +++++++++++ test/test_unordered_multiset.cpp | 11 +++++++++++ test/test_unordered_set.cpp | 11 +++++++++++ 8 files changed, 76 insertions(+) diff --git a/include/etl/unordered_map.h b/include/etl/unordered_map.h index d8ed62a5b..8dd01af06 100644 --- a/include/etl/unordered_map.h +++ b/include/etl/unordered_map.h @@ -1361,6 +1361,14 @@ namespace etl } #endif + //************************************************************************* + /// Check if the unordered_map contains the key. + //************************************************************************* + bool contains(const_key_reference key) const + { + return find(key) != end(); + } + protected: //********************************************************************* diff --git a/include/etl/unordered_multimap.h b/include/etl/unordered_multimap.h index bb1ac4bfa..463e1cd9d 100644 --- a/include/etl/unordered_multimap.h +++ b/include/etl/unordered_multimap.h @@ -1216,6 +1216,14 @@ namespace etl } #endif + //************************************************************************* + /// Check if the unordered_multimap contains the key. + //************************************************************************* + bool contains(const_key_reference key) const + { + return find(key) != end(); + } + protected: //********************************************************************* diff --git a/include/etl/unordered_multiset.h b/include/etl/unordered_multiset.h index 212344b98..304dc4bc7 100644 --- a/include/etl/unordered_multiset.h +++ b/include/etl/unordered_multiset.h @@ -1194,6 +1194,14 @@ namespace etl } #endif + //************************************************************************* + /// Check if the unordered_multiset contains the key. + //************************************************************************* + bool contains(key_parameter_t key) const + { + return find(key) != end(); + } + protected: //********************************************************************* diff --git a/include/etl/unordered_set.h b/include/etl/unordered_set.h index 2b426ac59..1f9a7e6ee 100644 --- a/include/etl/unordered_set.h +++ b/include/etl/unordered_set.h @@ -1214,6 +1214,14 @@ namespace etl } #endif + //************************************************************************* + /// Check if the unordered_set contains the key. + //************************************************************************* + bool contains(key_parameter_t key) const + { + return find(key) != end(); + } + protected: //********************************************************************* diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 93f664574..4f7b1b7be 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -1207,5 +1207,16 @@ namespace CHECK_TRUE(map1 == map2a); CHECK_FALSE(map1 == map2b); } + + //************************************************************************* + TEST(test_contains) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + const char* not_inserted = "ZZ"; + + CHECK(data.contains(std::string(K0))); + CHECK(!data.contains(std::string(not_inserted))); + } }; } diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index 38d198bf0..60b9eb92e 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -1068,5 +1068,16 @@ namespace CHECK_TRUE(map1 == map2a); CHECK_FALSE(map1 == map2b); } + + //************************************************************************* + TEST(test_contains) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + const char* not_inserted = "ZZ"; + + CHECK(data.contains(K0)); + CHECK(!data.contains(not_inserted)); + } }; } diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index 8337a0153..843a490ea 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -943,5 +943,16 @@ namespace CHECK_TRUE(set1 == set2a); CHECK_FALSE(set1 == set2b); } + + //************************************************************************* + TEST(test_contains) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + NDC not_inserted = NDC("ZZ"); + + CHECK_TRUE(data.contains(N0)); + CHECK_FALSE(data.contains(not_inserted)); + } }; } diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index 7a4210cc0..e8641155b 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -909,5 +909,16 @@ namespace CHECK_TRUE(set1 == set2a); CHECK_FALSE(set1 == set2b); } + + //************************************************************************* + TEST(test_contains) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + NDC not_inserted = NDC("ZZ"); + + CHECK_TRUE(data.contains(N0)); + CHECK_FALSE(data.contains(not_inserted)); + } }; } From 6ea23883587d99d79209be12c8afe2acb351bd07 Mon Sep 17 00:00:00 2001 From: ZachOB <109545859+ZachOB@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:36:46 -0600 Subject: [PATCH 02/55] Fix build error in `icircular_buffer::iterator` and `icircular_buffer::const_iterator` (#956) --- include/etl/circular_buffer.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/include/etl/circular_buffer.h b/include/etl/circular_buffer.h index 0902f0daa..a6967d82b 100644 --- a/include/etl/circular_buffer.h +++ b/include/etl/circular_buffer.h @@ -251,7 +251,7 @@ namespace etl //************************************************************************* reference operator [](size_t index) { - return pbuffer[(current + index) % picb->buffer_size]; + return picb->pbuffer[(current + index) % picb->buffer_size]; } //************************************************************************* @@ -259,7 +259,7 @@ namespace etl //************************************************************************* const_reference operator [](size_t index) const { - return pbuffer[(current + index) % picb->buffer_size]; + return picb->pbuffer[(current + index) % picb->buffer_size]; } //************************************************************************* @@ -438,7 +438,7 @@ namespace etl //*************************************************** pointer get_buffer() const { - return pbuffer; + return picb->pbuffer; } protected: @@ -550,7 +550,7 @@ namespace etl //************************************************************************* const_reference operator [](size_t index) const { - return pbuffer[(current + index) % picb->buffer_size]; + return picb->pbuffer[(current + index) % picb->buffer_size]; } //************************************************************************* @@ -717,7 +717,7 @@ namespace etl //*************************************************** pointer get_buffer() const { - return pbuffer; + return picb->pbuffer; } protected: From 07333fd1dd0e5d89a767efa17b236485ac09a0ef Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 18 Sep 2024 20:37:15 +0100 Subject: [PATCH 03/55] Updated release notes and version --- include/etl/version.h | 2 +- library.json | 2 +- library.properties | 2 +- support/Release notes.txt | 6 ++++++ version.txt | 2 +- 5 files changed, 10 insertions(+), 4 deletions(-) diff --git a/include/etl/version.h b/include/etl/version.h index db5ed6d77..a7635e1ad 100644 --- a/include/etl/version.h +++ b/include/etl/version.h @@ -40,7 +40,7 @@ SOFTWARE. #define ETL_VERSION_MAJOR 20 #define ETL_VERSION_MINOR 39 -#define ETL_VERSION_PATCH 4 +#define ETL_VERSION_PATCH 5 #define ETL_VERSION ETL_STRING(ETL_VERSION_MAJOR) "." ETL_STRING(ETL_VERSION_MINOR) "." ETL_STRING(ETL_VERSION_PATCH) #define ETL_VERSION_W ETL_WIDE_STRING(ETL_VERSION_MAJOR) L"." ETL_WIDE_STRING(ETL_VERSION_MINOR) L"." ETL_WIDE_STRING(ETL_VERSION_PATCH) diff --git a/library.json b/library.json index 12bca01e0..e3e12882b 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library", - "version": "20.39.4", + "version": "20.39.5", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/library.properties b/library.properties index 99401ff4a..37bcbb484 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Embedded Template Library -version=20.39.4 +version=20.39.5 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index 97daedfd9..e45c4ea3b 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,4 +1,10 @@ =============================================================================== +20.39.5 + +Fixes: +#956 Fix build error (etl::circular_buffer) + +=============================================================================== 20.39.4 #948 Bug in queue pop can break queue.empty() diff --git a/version.txt b/version.txt index 55ed5f727..f5a151e50 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -20.39.4 +20.39.5 From 748e2357f53ece29333e91c0267cbd3d939d8d55 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 10:10:10 +0000 Subject: [PATCH 04/55] Updated nth_type to handle a type list of zero length --- include/etl/nth_type.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/include/etl/nth_type.h b/include/etl/nth_type.h index f870bb7cb..5bc1e836e 100644 --- a/include/etl/nth_type.h +++ b/include/etl/nth_type.h @@ -30,22 +30,49 @@ SOFTWARE. #define ETL_NTH_TYPE_INCLUDED #include "platform.h" +#include "static_assert.h" namespace etl { #if ETL_USING_CPP11 + + //*************************************************************************** + /// Finds the nth type in a variadic type parameter. + //*************************************************************************** + template + struct nth_type; + + //*************************************************************************** + /// Finds the nth type in a variadic type parameter. + //*************************************************************************** template - struct nth_type + struct nth_type { + ETL_STATIC_ASSERT(N <= sizeof...(TRest), "etl::nth_type out of range for type list"); + using type = typename nth_type::type; }; + //*************************************************************************** + /// Finds the 0thth type in a variadic type parameter. + //*************************************************************************** template struct nth_type<0U, T1, TRest...> { using type = T1; }; + //*************************************************************************** + /// Finds the 0thth type in a variadic type parameter. + //*************************************************************************** + template + struct nth_type + { + }; + + //*************************************************************************** + /// Finds the nth type in a variadic type parameter. + //*************************************************************************** template using nth_type_t = typename nth_type::type; #endif From 297b7e6786c59dfd8e2d243363773e94c447b7e4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 10:16:10 +0000 Subject: [PATCH 05/55] Redefined ETL_DEPRECATED --- include/etl/platform.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/include/etl/platform.h b/include/etl/platform.h index e66a0e08d..56ab83103 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -315,9 +315,15 @@ SOFTWARE. //************************************* // C++14 #if ETL_USING_CPP14 && !defined(ETL_FORCE_NO_ADVANCED_CPP) - #define ETL_CONSTEXPR14 constexpr - #define ETL_DEPRECATED [[deprecated]] - #define ETL_DEPRECATED_REASON(reason) [[deprecated(reason)]] + #define ETL_CONSTEXPR14 constexpr + + #if !defined(ETL_IN_UNIT_TEST) + #define ETL_DEPRECATED [[deprecated]] + #define ETL_DEPRECATED_REASON(reason) [[deprecated(reason)]] + #else + #define ETL_DEPRECATED + #define ETL_DEPRECATED_REASON(reason) + #endif #else #define ETL_CONSTEXPR14 #define ETL_DEPRECATED From ddef6a04ff270a1c03b563701cd4ee647d79127f Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 10:17:20 +0000 Subject: [PATCH 06/55] Fixed static definition --- include/etl/string.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/etl/string.h b/include/etl/string.h index 1fbc19d26..50b3bf624 100644 --- a/include/etl/string.h +++ b/include/etl/string.h @@ -72,6 +72,7 @@ namespace etl typedef istring interface_type; typedef istring::value_type value_type; + typedef istring::size_type size_type; static ETL_CONSTANT size_t MAX_SIZE = MAX_SIZE_; @@ -261,7 +262,7 @@ namespace etl }; template - ETL_CONSTANT size_t string::MAX_SIZE; + ETL_CONSTANT typename string::size_type string::MAX_SIZE; //*************************************************************************** /// A string implementation that uses a fixed size external buffer. From 0026a8b90818ac54d14cbeaab6aff43f45821c6d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 10:26:24 +0000 Subject: [PATCH 07/55] #965 Fix accident creation of a delegate to an rvalue delegate when copying/assigning from delegate with mismatching signature #966 A constructor for delegate with a freestanding function --- include/etl/private/delegate_cpp03.h | 61 +++- include/etl/private/delegate_cpp11.h | 176 +++++++++- test/test_delegate.cpp | 484 ++++++++++++++++++++++++++- 3 files changed, 687 insertions(+), 34 deletions(-) diff --git a/include/etl/private/delegate_cpp03.h b/include/etl/private/delegate_cpp03.h index 74da0e497..250fff6f6 100644 --- a/include/etl/private/delegate_cpp03.h +++ b/include/etl/private/delegate_cpp03.h @@ -168,6 +168,22 @@ namespace etl } }; + //***************************************************************** + /// The tag to identify an etl::delegate. + ///\ingroup delegate + //***************************************************************** + struct delegate_tag + { + }; + + //*************************************************************************** + /// is_delegate + //*************************************************************************** + template + struct is_delegate : etl::bool_constant::value> + { + }; + //************************************************************************* /// Declaration. //************************************************************************* @@ -175,14 +191,19 @@ namespace etl class delegate; template - class delegate : public private_delegate::call_if_impl, TReturn, TParam> + class delegate : public private_delegate::call_if_impl, TReturn, TParam>, + public delegate_tag { private: - + typedef delegate delegate_type; public: + typedef TReturn (*function_type)(TParam); + typedef TReturn return_type; + typedef TParam argument_type; + using private_delegate::call_if_impl, TReturn, TParam>::call_if; //************************************************************************* @@ -204,7 +225,7 @@ namespace etl // Construct from a functor. //************************************************************************* template - delegate(TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) + delegate(TFunctor& instance, typename etl::enable_if::value && !is_delegate::value, int>::type = 0) { assign((void*)(&instance), functor_stub); } @@ -213,7 +234,7 @@ namespace etl // Construct from a const functor. //************************************************************************* template - delegate(const TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) + delegate(const TFunctor& instance, typename etl::enable_if::value && !is_delegate::value, int>::type = 0) { assign((void*)(&instance), const_functor_stub); } @@ -232,7 +253,7 @@ namespace etl //************************************************************************* template static - typename etl::enable_if::value &&!etl::is_same::value, delegate>::type + typename etl::enable_if::value &&!is_delegate::value, delegate>::type create(TFunctor& instance) { return delegate((void*)(&instance), functor_stub); @@ -243,7 +264,7 @@ namespace etl //************************************************************************* template static - typename etl::enable_if::value && !etl::is_same::value, delegate>::type + typename etl::enable_if::value && !is_delegate::value, delegate>::type create(const TFunctor& instance) { return delegate((void*)(&instance), const_functor_stub); @@ -330,7 +351,7 @@ namespace etl /// Set from Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, void>::type + typename etl::enable_if::value && !is_delegate::value, void>::type set(TFunctor& instance) { assign((void*)(&instance), functor_stub); @@ -340,7 +361,7 @@ namespace etl /// Set from const Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, void>::type + typename etl::enable_if::value && !is_delegate::value, void>::type set(const TFunctor& instance) { assign((void*)(&instance), const_functor_stub); @@ -467,7 +488,7 @@ namespace etl /// Create from Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + typename etl::enable_if::value && !is_delegate::value, delegate&>::type operator =(TFunctor& instance) { assign((void*)(&instance), functor_stub); @@ -478,7 +499,7 @@ namespace etl /// Create from const Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + typename etl::enable_if::value && !is_delegate::value, delegate&>::type operator =(const TFunctor& instance) { assign((void*)(&instance), const_functor_stub); @@ -684,6 +705,10 @@ namespace etl public: + typedef TReturn (*function_type)(void); + typedef TReturn return_type; + typedef void argument_type; + using private_delegate::call_if_impl< delegate, TReturn, void>::call_if; //************************************************************************* @@ -705,7 +730,7 @@ namespace etl // Construct from functor. //************************************************************************* template - delegate(TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) + delegate(TFunctor& instance, typename etl::enable_if::value && !is_delegate::value, int>::type = 0) { assign((void*)(&instance), functor_stub); } @@ -714,7 +739,7 @@ namespace etl // Construct from const functor. //************************************************************************* template - delegate(const TFunctor& instance, typename etl::enable_if::value && !etl::is_same::value, int>::type = 0) + delegate(const TFunctor& instance, typename etl::enable_if::value && !is_delegate::value, int>::type = 0) { assign((void*)(&instance), const_functor_stub); } @@ -733,7 +758,7 @@ namespace etl //************************************************************************* template static - typename etl::enable_if::value && !etl::is_same::value, delegate>::type + typename etl::enable_if::value && !is_delegate::value, delegate>::type create(TFunctor& instance) { return delegate((void*)(&instance), functor_stub); @@ -744,7 +769,7 @@ namespace etl //************************************************************************* template static - typename etl::enable_if::value && !etl::is_same::value, delegate>::type + typename etl::enable_if::value && !is_delegate::value, delegate>::type create(const TFunctor& instance) { return delegate((void*)(&instance), const_functor_stub); @@ -831,7 +856,7 @@ namespace etl /// Set from Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, void>::type + typename etl::enable_if::value && !is_delegate::value, void>::type set(TFunctor& instance) { assign((void*)(&instance), functor_stub); @@ -841,7 +866,7 @@ namespace etl /// Set from const Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, void>::type + typename etl::enable_if::value && !is_delegate::value, void>::type set(const TFunctor& instance) { assign((void*)(&instance), const_functor_stub); @@ -968,7 +993,7 @@ namespace etl /// Create from Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + typename etl::enable_if::value && !is_delegate::value, delegate&>::type operator =(TFunctor& instance) { assign((void*)(&instance), functor_stub); @@ -979,7 +1004,7 @@ namespace etl /// Create from const Functor. //************************************************************************* template - typename etl::enable_if::value && !etl::is_same::value, delegate&>::type + typename etl::enable_if::value && !is_delegate::value, delegate&>::type operator =(const TFunctor& instance) { assign((void*)(&instance), const_functor_stub); diff --git a/include/etl/private/delegate_cpp11.h b/include/etl/private/delegate_cpp11.h index 8f438602c..acafc1684 100644 --- a/include/etl/private/delegate_cpp11.h +++ b/include/etl/private/delegate_cpp11.h @@ -83,16 +83,38 @@ namespace etl } }; + //***************************************************************** + /// The tag to identify an etl::delegate. + ///\ingroup delegate + //***************************************************************** + struct delegate_tag + { + }; + + //*************************************************************************** + /// is_delegate + //*************************************************************************** + template + struct is_delegate : etl::bool_constant::value> + { + }; + +#if ETL_USING_CPP17 + template + inline constexpr bool is_delegate_v = is_delegate::value; +#endif + //************************************************************************* /// Declaration. //************************************************************************* - template class delegate; + template + class delegate; //************************************************************************* /// Specialisation. //************************************************************************* template - class delegate final + class delegate final : public delegate_tag { public: @@ -111,7 +133,7 @@ namespace etl //************************************************************************* // Construct from lambda or functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_CONSTEXPR14 delegate(TLambda& instance) { assign((void*)(&instance), lambda_stub); @@ -120,7 +142,7 @@ namespace etl //************************************************************************* // Construct from const lambda or functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_CONSTEXPR14 delegate(const TLambda& instance) { assign((void*)(&instance), const_lambda_stub); @@ -139,7 +161,7 @@ namespace etl //************************************************************************* /// Create from Lambda or Functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_NODISCARD static ETL_CONSTEXPR14 delegate create(TLambda& instance) { @@ -149,7 +171,7 @@ namespace etl //************************************************************************* /// Create from const Lambda or Functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_NODISCARD static ETL_CONSTEXPR14 delegate create(const TLambda& instance) { @@ -257,7 +279,7 @@ namespace etl //************************************************************************* /// Set from Lambda or Functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_CONSTEXPR14 void set(TLambda& instance) { assign((void*)(&instance), lambda_stub); @@ -266,7 +288,7 @@ namespace etl //************************************************************************* /// Set from const Lambda or Functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_CONSTEXPR14 void set(const TLambda& instance) { assign((void*)(&instance), const_lambda_stub); @@ -348,7 +370,7 @@ namespace etl //************************************************************************* /// Execute the delegate if valid. - /// 'void' return. + /// 'void' return delegate. //************************************************************************* template ETL_CONSTEXPR14 @@ -368,7 +390,7 @@ namespace etl //************************************************************************* /// Execute the delegate if valid. - /// Non 'void' return. + /// Non 'void' return delegate. //************************************************************************* template ETL_CONSTEXPR14 @@ -427,7 +449,7 @@ namespace etl //************************************************************************* /// Create from Lambda or Functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_CONSTEXPR14 delegate& operator =(TLambda& instance) { assign((void*)(&instance), lambda_stub); @@ -437,7 +459,7 @@ namespace etl //************************************************************************* /// Create from const Lambda or Functor. //************************************************************************* - template ::value && !etl::is_same, TLambda>::value, void>> + template ::value && !is_delegate::value, void>> ETL_CONSTEXPR14 delegate& operator =(const TLambda& instance) { assign((void*)(&instance), const_lambda_stub); @@ -627,6 +649,136 @@ namespace etl //************************************************************************* invocation_element invocation; }; + +#if ETL_USING_CPP17 + namespace private_delegate + { + //*************************************************************************** + /// A template to extract the function type traits. + //*************************************************************************** + template + struct function_traits; + + //*************************************************************************** + /// Specialisation for function pointers + //*************************************************************************** + template + struct function_traits + { + using function_type = TReturn(TArgs...); + + enum : bool + { + is_const = false + }; + }; + + //*************************************************************************** + /// Specialisation for member function pointers + //*************************************************************************** + template + struct function_traits + { + using function_type = TReturn(TArgs...); + + enum : bool + { + is_const = false + }; + }; + + //*************************************************************************** + /// Specialisation for const member function pointers + //*************************************************************************** + template + struct function_traits + { + using function_type = TReturn(TArgs...); + + enum : bool + { + is_const = true + }; + }; + } + + //************************************************************************* + /// Make a delegate from a free function. + //************************************************************************* + template + constexpr auto make_delegate() ETL_NOEXCEPT + { + using function_type = typename etl::private_delegate::function_traits::function_type; + + return etl::delegate::template create(); + } + + //************************************************************************* + /// Make a delegate from a functor or lambda function. + //************************************************************************* + template ::value, void>> + constexpr auto make_delegate(TLambda& instance) ETL_NOEXCEPT + { + using function_type = typename etl::private_delegate::function_traits::function_type; + + return etl::delegate(instance); + } + + //************************************************************************* + /// Make a delegate from a functor, compile time. + //************************************************************************* + template + constexpr auto make_delegate() ETL_NOEXCEPT + { + using function_type = typename etl::private_delegate::function_traits::function_type; + + return etl::delegate::template create(); + } + + //************************************************************************* + /// Make a delegate from a member function at compile time. + //************************************************************************* + template ::is_const>> + constexpr auto make_delegate() ETL_NOEXCEPT + { + using function_type = typename etl::private_delegate::function_traits::function_type; + + return etl::delegate::template create(); + } + + //************************************************************************* + /// Make a delegate from a const member function at compile time. + //************************************************************************* + template ::is_const>> + constexpr auto make_delegate() ETL_NOEXCEPT + { + using function_type = typename etl::private_delegate::function_traits::function_type; + + return etl::delegate::template create(); + } + + //************************************************************************* + /// Make a delegate from a member function at run time. + //************************************************************************* + template + constexpr auto make_delegate(T& instance) ETL_NOEXCEPT + { + using function_type = typename etl::private_delegate::function_traits::function_type; + + return etl::delegate::template create(instance); + } + + //************************************************************************* + /// Make a delegate from a member function at run time. + //************************************************************************* + template + constexpr auto make_delegate(const T& instance) ETL_NOEXCEPT + { + using function_type = typename etl::private_delegate::function_traits::function_type; + + return etl::delegate::template create(instance); + } +#endif } #endif diff --git a/test/test_delegate.cpp b/test/test_delegate.cpp index 0f9d29a8e..de5b6c378 100644 --- a/test/test_delegate.cpp +++ b/test/test_delegate.cpp @@ -221,8 +221,6 @@ namespace parameter_correct = (data.d == VALUE1) && (j == VALUE2); } - //******************************************* - // operator() void operator()() { function_called = FunctionCalled::Operator_Called; @@ -234,6 +232,26 @@ namespace } }; + //******************************************* + // Functor with non-const operator() + struct Functor + { + void operator()() + { + function_called = FunctionCalled::Operator_Called; + } + }; + + //******************************************* + // Functor with const operator() + struct FunctorConst + { + void operator()() const + { + function_called = FunctionCalled::Operator_Const_Called; + } + }; + //******************************************* int times_2(int a) { @@ -242,6 +260,11 @@ namespace Object object_static; const Object const_object_static; + +#if ETL_USING_CPP17 + Functor functor_static; + const FunctorConst const_functor_static; +#endif } namespace @@ -314,6 +337,18 @@ namespace CHECK(function_called == FunctionCalled::Free_Void_Called); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_void) + { + auto d = etl::make_delegate<&free_void>(); + + d(); + + CHECK(function_called == FunctionCalled::Free_Void_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_free_void_constexpr) @@ -326,6 +361,18 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_void_constexpr) + { + constexpr auto d = etl::make_delegate<&free_void>(); + + d(); + + CHECK(function_called == FunctionCalled::Free_Void_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_free_int) { @@ -337,6 +384,19 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_int) + { + auto d = etl::make_delegate<&free_int>(); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Free_Int_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_free_int_constexpr) @@ -350,6 +410,19 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_int_constexpr) + { + constexpr auto d = etl::make_delegate<&free_int>(); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Free_Int_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_free_reference) { @@ -364,6 +437,22 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_reference) + { + etl::delegate d = etl::make_delegate<&free_reference>(); + + Data data; + data.d = VALUE1; + + d(data, VALUE2); + + CHECK(function_called == FunctionCalled::Free_Reference_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_free_reference_constexpr) @@ -380,6 +469,22 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_reference_constexpr) + { + constexpr etl::delegate d = etl::make_delegate<&free_reference>(); + + Data data; + data.d = VALUE1; + + d(data, VALUE2); + + CHECK(function_called == FunctionCalled::Free_Reference_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_free_moveableonly) { @@ -394,6 +499,22 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_moveableonly) + { + auto d = etl::make_delegate<&free_moveableonly>(); + + MoveableOnlyData data; + data.d = VALUE1; + + d(std::move(data)); + + CHECK(function_called == FunctionCalled::Free_Moveableonly_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_free_moveableonly_constexpr) @@ -410,6 +531,22 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_free_moveableonly_constexpr) + { + constexpr auto d = etl::make_delegate<&free_moveableonly>(); + + MoveableOnlyData data; + data.d = VALUE1; + + d(std::move(data)); + + CHECK(function_called == FunctionCalled::Free_Moveableonly_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_lambda_int) { @@ -434,6 +571,21 @@ namespace CHECK(parameter_correct); } +#if ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_make_delegate_lambda_int_create) + { + auto lambda = [](int i, int j) { function_called = FunctionCalled::Lambda_Called; parameter_correct = (i == VALUE1) && (j == VALUE2); }; + + auto d = etl::make_delegate(lambda); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Lambda_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_operator_void) { @@ -446,6 +598,20 @@ namespace CHECK(function_called == FunctionCalled::Operator_Called); } +#if ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_make_delegate_member_operator_void) + { + Functor object; + + auto d = etl::make_delegate(object); + + d(); + + CHECK(function_called == FunctionCalled::Operator_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_operator_void_create) { @@ -459,7 +625,7 @@ namespace } //************************************************************************* -#if ETL_USING_CPP14 +#if ETL_USING_CPP17 TEST_FIXTURE(SetupFixture, test_member_operator_void_create_constexpr) { static Object object; @@ -484,7 +650,21 @@ namespace CHECK(function_called == FunctionCalled::Operator_Const_Called); } -#if !defined(ETL_COMPILER_GCC) + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_operator_void_const) + { + const FunctorConst object; + + auto d = etl::make_delegate(object); + + d(); + + CHECK(function_called == FunctionCalled::Operator_Const_Called); + } +#endif + +#if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 8)) //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_operator_void_compile_time) { @@ -495,6 +675,18 @@ namespace CHECK(function_called == FunctionCalled::Operator_Called); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_operator_void_compile_time) + { + auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Operator_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_operator_void_compile_time_constexpr) @@ -507,6 +699,18 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_operator_void_compile_time_constexpr) + { + constexpr auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Operator_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_operator_void_compile_time_const) { @@ -517,6 +721,18 @@ namespace CHECK(function_called == FunctionCalled::Operator_Const_Called); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_operator_void_compile_time_const) + { + auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Operator_Const_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_operator_void_compile_time_const_constexpr) @@ -528,6 +744,18 @@ namespace CHECK(function_called == FunctionCalled::Operator_Const_Called); } #endif + + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_operator_void_compile_time_const_constexpr) + { + constexpr auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Operator_Const_Called); + } +#endif #endif //************************************************************************* @@ -556,6 +784,20 @@ namespace CHECK(function_called == FunctionCalled::Member_Void_Called); } +#if ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void) + { + Object object; + + auto d = etl::make_delegate(object); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_void_constexpr) @@ -570,6 +812,20 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_constexpr) + { + static Object object; + + constexpr auto d = etl::make_delegate(object); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_void_const) { @@ -582,6 +838,20 @@ namespace CHECK(function_called == FunctionCalled::Member_Void_Const_Called); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_const) + { + const Object object; + + auto d = etl::make_delegate(object); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_void_const_constexpr) @@ -596,6 +866,20 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_const_constexpr) + { + static const Object object; + + constexpr auto d = etl::make_delegate(object); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_int) { @@ -609,6 +893,21 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int) + { + Object object; + + auto d = etl::make_delegate(object); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_int_constexpr) @@ -624,6 +923,21 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_constexpr) + { + static Object object; + + constexpr auto d = etl::make_delegate(object); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_int_const) { @@ -637,6 +951,21 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_const) + { + const Object object; + + auto d = etl::make_delegate(object); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_int_const_constexpr) @@ -652,6 +981,21 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_const_constexpr) + { + static const Object object; + + constexpr auto d = etl::make_delegate(object); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_reference) { @@ -762,6 +1106,22 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +//#if ETL_USING_CPP17 +// TEST_FIXTURE(SetupFixture, test_make_delegate_member_static) +// { +// auto d = etl::make_delegate(); +// +// Data data; +// data.d = VALUE1; +// +// d(data, VALUE2); +// +// CHECK(function_called == FunctionCalled::Member_Static_Called); +// CHECK(parameter_correct); +// } +//#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_static_constexpr) @@ -778,6 +1138,22 @@ namespace } #endif + //************************************************************************* +//#if ETL_USING_CPP17 +// TEST_FIXTURE(SetupFixture, test_make_delegate_member_static_constexpr) +// { +// constexpr auto d = etl::make_delegate(); +// +// Data data; +// data.d = VALUE1; +// +// d(data, VALUE2); +// +// CHECK(function_called == FunctionCalled::Member_Static_Called); +// CHECK(parameter_correct); +// } +//#endif + #if !(defined(ETL_COMPILER_GCC) && (__GNUC__ <= 5)) //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_void_compile_time) @@ -799,6 +1175,18 @@ namespace CHECK(function_called == FunctionCalled::Member_Void_Called); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_compile_time_new_api) + { + auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_void_compile_time_constexpr) @@ -823,6 +1211,18 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_compile_time_constexpr_new_api) + { + constexpr auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_void_const_compile_time) { @@ -843,6 +1243,18 @@ namespace CHECK(function_called == FunctionCalled::Member_Void_Const_Called); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_const_compile_time_new_api) + { + auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_void_const_compile_time_constexpr) @@ -867,6 +1279,18 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_void_const_compile_time_constexpr_new_api) + { + constexpr auto d = etl::make_delegate(); + + d(); + + CHECK(function_called == FunctionCalled::Member_Void_Const_Called); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_int_compile_time) { @@ -889,6 +1313,19 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_compile_time_new_api) + { + auto d = etl::make_delegate(); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_int_compile_time_constexpr) @@ -915,6 +1352,19 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_compile_time_constexpr_new_api) + { + constexpr auto d = etl::make_delegate(); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_int_const_compile_time) { @@ -937,6 +1387,19 @@ namespace CHECK(parameter_correct); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_const_compile_tim1e_new_api) + { + auto d = etl::make_delegate(); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* #if ETL_USING_CPP14 TEST_FIXTURE(SetupFixture, test_member_int_const_compile_time_constexpr) @@ -963,6 +1426,19 @@ namespace } #endif + //************************************************************************* +#if ETL_USING_CPP17 + TEST_FIXTURE(SetupFixture, test_make_delegate_member_int_const_compile_time_constexpr_new_api) + { + constexpr auto d = etl::make_delegate(); + + d(VALUE1, VALUE2); + + CHECK(function_called == FunctionCalled::Member_Int_Const_Called); + CHECK(parameter_correct); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_member_reference_compile_time) { From fd82a9c113e9aba70027f3aa9caafb36e23b5d03 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 10:28:58 +0000 Subject: [PATCH 08/55] #959 Treat bitset with size_type --- include/etl/private/bitset_legacy.h | 2 ++ include/etl/private/bitset_new.h | 7 +++++++ test/test_bitset_legacy.cpp | 8 ++++++++ test/test_bitset_new_default_element_type.cpp | 8 ++++++++ test/test_bitset_new_explicit_single_element_type.cpp | 8 ++++++++ test/test_bitset_new_ext_default_element_type.cpp | 8 ++++++++ test/test_bitset_new_ext_explicit_single_element_type.cpp | 8 ++++++++ 7 files changed, 49 insertions(+) diff --git a/include/etl/private/bitset_legacy.h b/include/etl/private/bitset_legacy.h index 593f415b7..a1f407372 100644 --- a/include/etl/private/bitset_legacy.h +++ b/include/etl/private/bitset_legacy.h @@ -148,6 +148,8 @@ namespace etl public: + typedef size_t size_type; + typedef typename etl::make_unsigned::type element_type; typedef element_type element_t; // Backward compatibility diff --git a/include/etl/private/bitset_new.h b/include/etl/private/bitset_new.h index 323a4e479..2fcbc990e 100644 --- a/include/etl/private/bitset_new.h +++ b/include/etl/private/bitset_new.h @@ -171,6 +171,7 @@ namespace etl typedef TElement element_type; typedef TElement* pointer; typedef const TElement* const_pointer; + typedef size_t size_type; static ETL_CONSTANT size_t npos = etl::integral_limits::max; static ETL_CONSTANT size_t Bits_Per_Element = etl::integral_limits::bits; @@ -1937,6 +1938,8 @@ namespace etl typedef typename etl::private_bitset::bitset_common::span_type span_type; typedef typename etl::private_bitset::bitset_common::const_span_type const_span_type; + + using etl::private_bitset::bitset_common::Bits_Per_Element; using etl::private_bitset::bitset_common::All_Set_Element; using etl::private_bitset::bitset_common::All_Clear_Element; @@ -2826,6 +2829,8 @@ namespace etl { public: + typedef size_t size_type; + typedef etl::private_bitset::bitset_common<0U, unsigned char>::element_type element_type; typedef etl::private_bitset::bitset_common<0U, unsigned char>::span_type span_type; typedef etl::private_bitset::bitset_common<0U, unsigned char>::const_span_type const_span_type; @@ -2850,6 +2855,8 @@ namespace etl ETL_STATIC_ASSERT(etl::is_unsigned::value, "The element type must be unsigned"); + typedef size_t size_type; + typedef typename etl::private_bitset::bitset_common::element_type element_type; typedef typename etl::private_bitset::bitset_common::span_type span_type; typedef typename etl::private_bitset::bitset_common::const_span_type const_span_type; diff --git a/test/test_bitset_legacy.cpp b/test/test_bitset_legacy.cpp index a64722ba6..88bb30174 100644 --- a/test/test_bitset_legacy.cpp +++ b/test/test_bitset_legacy.cpp @@ -1493,6 +1493,14 @@ namespace CHECK_EQUAL("...*..*...**.*...*.*.**..****...", stdtext.c_str()); } + //************************************************************************* + TEST(test_global_size) + { + etl::bitset<32> b(0x12345678UL); + + CHECK_EQUAL(32, ETL_OR_STD::size(b)); + } + //************************************************************************* TEST(test_issue_497_count_inverted_bits) { diff --git a/test/test_bitset_new_default_element_type.cpp b/test/test_bitset_new_default_element_type.cpp index 4e8b51642..682cd2b8e 100644 --- a/test/test_bitset_new_default_element_type.cpp +++ b/test/test_bitset_new_default_element_type.cpp @@ -2722,5 +2722,13 @@ namespace CHECK_EQUAL(test_bit(6), t6); CHECK_EQUAL(test_bit(7), t7); } + + //************************************************************************* + TEST(test_global_size) + { + etl::bitset<32> b(0x12345678UL); + + CHECK_EQUAL(32, ETL_OR_STD::size(b)); + } }; } diff --git a/test/test_bitset_new_explicit_single_element_type.cpp b/test/test_bitset_new_explicit_single_element_type.cpp index 82badbb0e..f6db16a9b 100644 --- a/test/test_bitset_new_explicit_single_element_type.cpp +++ b/test/test_bitset_new_explicit_single_element_type.cpp @@ -2815,5 +2815,13 @@ namespace CHECK_EQUAL(test_bit(6), t6); CHECK_EQUAL(test_bit(7), t7); } + + //************************************************************************* + TEST(test_global_size) + { + etl::bitset<32, uint32_t> b(0x12345678UL); + + CHECK_EQUAL(32, ETL_OR_STD::size(b)); + } }; } diff --git a/test/test_bitset_new_ext_default_element_type.cpp b/test/test_bitset_new_ext_default_element_type.cpp index 64100f3ea..d944087d4 100644 --- a/test/test_bitset_new_ext_default_element_type.cpp +++ b/test/test_bitset_new_ext_default_element_type.cpp @@ -2471,5 +2471,13 @@ namespace CHECK_EQUAL(test_bit(6), t6); CHECK_EQUAL(test_bit(7), t7); } + + //************************************************************************* + TEST(test_global_size) + { + etl::bitset<32> b(0x12345678UL); + + CHECK_EQUAL(32, ETL_OR_STD::size(b)); + } }; } diff --git a/test/test_bitset_new_ext_explicit_single_element_type.cpp b/test/test_bitset_new_ext_explicit_single_element_type.cpp index 433434488..e34ffe663 100644 --- a/test/test_bitset_new_ext_explicit_single_element_type.cpp +++ b/test/test_bitset_new_ext_explicit_single_element_type.cpp @@ -2619,5 +2619,13 @@ namespace CHECK_EQUAL(test_bit(6), t6); CHECK_EQUAL(test_bit(7), t7); } + + //************************************************************************* + TEST(test_global_size) + { + etl::bitset<32, uint32_t> b(0x12345678UL); + + CHECK_EQUAL(32, ETL_OR_STD::size(b)); + } }; } From d0a9d696fe0e3cdacd2cdc21be8fb3dea6147e59 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 10:33:19 +0000 Subject: [PATCH 09/55] Simplified definition of is_base_of --- include/etl/generators/type_traits_generator.h | 9 ++------- include/etl/type_traits.h | 9 ++------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index f086b8414..9e4140802 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -639,18 +639,13 @@ namespace etl struct is_base_of { private: - - template struct dummy {}; - struct internal: TDerived, dummy{}; - static TBase* check(TBase*) { return (TBase*)0; } - template - static char check(dummy*) { return 0; } + static char check(...) { return 0; } public: - static const bool value = (sizeof(check((internal*)0)) == sizeof(TBase*)); + static const bool value = (sizeof(check((TDerived*)0)) == sizeof(TBase*)); }; // For when TBase or TDerived is a fundamental type. diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index 47489c2cc..327f164be 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -627,18 +627,13 @@ namespace etl struct is_base_of { private: - - template struct dummy {}; - struct internal: TDerived, dummy{}; - static TBase* check(TBase*) { return (TBase*)0; } - template - static char check(dummy*) { return 0; } + static char check(...) { return 0; } public: - static const bool value = (sizeof(check((internal*)0)) == sizeof(TBase*)); + static const bool value = (sizeof(check((TDerived*)0)) == sizeof(TBase*)); }; // For when TBase or TDerived is a fundamental type. From 4a1712b7339d594262082afc07c0971fe1f7f13f Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 11:50:33 +0000 Subject: [PATCH 10/55] #957 Support heterogenous lookup for maps --- include/etl/unordered_map.h | 320 +++++++++++++++++++++++++++++++ include/etl/unordered_multimap.h | 210 ++++++++++++++++++++ include/etl/unordered_multiset.h | 227 ++++++++++++++++++++++ include/etl/unordered_set.h | 270 ++++++++++++++++++++++++++ test/test_unordered_map.cpp | 284 +++++++++++++++++++++++---- test/test_unordered_multimap.cpp | 200 +++++++++++++++++-- test/test_unordered_multiset.cpp | 176 +++++++++++++++-- test/test_unordered_set.cpp | 177 +++++++++++++++-- 8 files changed, 1761 insertions(+), 103 deletions(-) diff --git a/include/etl/unordered_map.h b/include/etl/unordered_map.h index 8dd01af06..359218de1 100644 --- a/include/etl/unordered_map.h +++ b/include/etl/unordered_map.h @@ -52,6 +52,8 @@ SOFTWARE. #include "placement_new.h" #include "initializer_list.h" +#include "private/comparator_is_transparent.h" + #include //***************************************************************************** @@ -599,6 +601,18 @@ namespace etl return key_hash_function(key) % number_of_buckets; } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns the bucket index for the key. + ///\return The bucket index for the key. + //********************************************************************* + template ::value, int> = 0> + size_type get_bucket_index(const K& key) const + { + return key_hash_function(key) % number_of_buckets; + } +#endif + //********************************************************************* /// Returns the size of the bucket key. ///\return The bucket size of the bucket key. @@ -610,6 +624,20 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns the size of the bucket key. + ///\return The bucket size of the bucket key. + //********************************************************************* + template ::value, int> = 0> + size_type bucket_size(const K& key) const + { + size_t index = bucket(key); + + return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); + } +#endif + //********************************************************************* /// Returns the maximum number of the buckets the container can hold. ///\return The maximum number of the buckets the container can hold. @@ -716,6 +744,52 @@ namespace etl return pbucket->begin()->key_value_pair.second; } + //********************************************************************* + /// Returns a reference to the value at index 'key' + ///\param key The key. + ///\return A reference to the value at index 'key' + //********************************************************************* +#if ETL_USING_CPP11 + template ::value, int> = 0> + mapped_reference operator [](const K& key) + { + // Find the bucket. + bucket_t* pbucket = pbuckets + get_bucket_index(key); + + // Find the first node in the bucket. + local_iterator inode = pbucket->begin(); + + // Walk the list looking for the right one. + while (inode != pbucket->end()) + { + // Equal keys? + if (key_equal_function(key, inode->key_value_pair.first)) + { + // Found a match. + return inode->key_value_pair.second; + } + else + { + ++inode; + } + } +#endif + + // Doesn't exist, so add a new one. + // Get a new node. + node_t* node = allocate_data_node(); + node->clear(); + ::new ((void*)etl::addressof(node->key_value_pair.first)) key_type(key); + ::new ((void*)etl::addressof(node->key_value_pair.second)) mapped_type(); + ETL_INCREMENT_DEBUG_COUNT; + + pbucket->insert_after(pbucket->before_begin(), *node); + + adjust_first_last_markers_after_insert(pbucket); + + return pbucket->begin()->key_value_pair.second; + } + //********************************************************************* /// Returns a reference to the value at index 'key' /// If asserts or exceptions are enabled, emits an etl::unordered_map_out_of_range if the key is not in the range. @@ -786,6 +860,82 @@ namespace etl return begin()->second; } + //********************************************************************* + /// Returns a reference to the value at index 'key' + /// If asserts or exceptions are enabled, emits an etl::unordered_map_out_of_range if the key is not in the range. + ///\param key The key. + ///\return A reference to the value at index 'key' + //********************************************************************* +#if ETL_USING_CPP11 + template ::value, int> = 0> + mapped_reference at(const K& key) + { + // Find the bucket. + bucket_t* pbucket = pbuckets + get_bucket_index(key); + + // Find the first node in the bucket. + local_iterator inode = pbucket->begin(); + + // Walk the list looking for the right one. + while (inode != pbucket->end()) + { + // Equal keys? + if (key_equal_function(key, inode->key_value_pair.first)) + { + // Found a match. + return inode->key_value_pair.second; + } + else + { + ++inode; + } + } + + // Doesn't exist. + ETL_ASSERT(false, ETL_ERROR(unordered_map_out_of_range)); + + return begin()->second; + } +#endif + +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a const reference to the value at index 'key' + /// If asserts or exceptions are enabled, emits an etl::unordered_map_out_of_range if the key is not in the range. + ///\param key The key. + ///\return A const reference to the value at index 'key' + //********************************************************************* + template ::value, int> = 0> + const_mapped_reference at(const K& key) const + { + // Find the bucket. + bucket_t* pbucket = pbuckets + get_bucket_index(key); + + // Find the first node in the bucket. + local_iterator inode = pbucket->begin(); + + // Walk the list looking for the right one. + while (inode != pbucket->end()) + { + // Equal keys? + if (key_equal_function(key, inode->key_value_pair.first)) + { + // Found a match. + return inode->key_value_pair.second; + } + else + { + ++inode; + } + } + + // Doesn't exist. + ETL_ASSERT(false, ETL_ERROR(unordered_map_out_of_range)); + + return begin()->second; + } +#endif + //********************************************************************* /// Assigns values to the unordered_map. /// If asserts or exceptions are enabled, emits unordered_map_full if the unordered_map does not have enough free space. @@ -1040,6 +1190,41 @@ namespace etl return n; } + //********************************************************************* + /// Erases an element. + ///\param key The key to erase. + ///\return The number of elements erased. 0 or 1. + //********************************************************************* +#if ETL_USING_CPP11 + template ::value, int> = 0> + size_t erase(const K& key) + { + size_t n = 0UL; + size_t index = get_bucket_index(key); + + bucket_t& bucket = pbuckets[index]; + + local_iterator iprevious = bucket.before_begin(); + local_iterator icurrent = bucket.begin(); + + // Search for the key, if we have it. + while ((icurrent != bucket.end()) && (!key_equal_function(icurrent->key_value_pair.first, key))) + { + ++iprevious; + ++icurrent; + } + + // Did we find it? + if (icurrent != bucket.end()) + { + delete_data_node(iprevious, icurrent, bucket); + n = 1; + } + + return n; + } +#endif + //********************************************************************* /// Erases an element. ///\param ielement Iterator to the element. @@ -1141,6 +1326,19 @@ namespace etl return (find(key) == end()) ? 0 : 1; } + //********************************************************************* + /// Counts an element. + ///\param key The key to search for. + ///\return 1 if the key exists, otherwise 0. + //********************************************************************* +#if ETL_USING_CPP11 + template ::value, int> = 0> + size_t count(const K& key) const + { + return (find(key) == end()) ? 0 : 1; + } +#endif + //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1209,6 +1407,80 @@ namespace etl return end(); } + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* +#if ETL_USING_CPP11 + template ::value, int> = 0> + iterator find(const K& key) + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key_value_pair.first)) + { + return iterator((pbuckets + number_of_buckets), pbucket, inode); + } + + ++inode; + } + } + + return end(); + } +#endif + + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* +#if ETL_USING_CPP11 + template ::value, int> = 0> + const_iterator find(const K& key) const + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key_value_pair.first)) + { + return iterator((pbuckets + number_of_buckets), pbucket, inode); + } + + ++inode; + } + } + + return end(); + } +#endif + //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1251,6 +1523,54 @@ namespace etl return ETL_OR_STD::pair(f, l); } + //********************************************************************* + /// Returns a range containing all elements with key key in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return An iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* +#if ETL_USING_CPP11 + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) + { + iterator f = find(key); + iterator l = f; + + if (l != end()) + { + ++l; + } + + return ETL_OR_STD::pair(f, l); + } +#endif + + //********************************************************************* + /// Returns a range containing all elements with key key in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return A const iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* +#if ETL_USING_CPP11 + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) const + { + const_iterator f = find(key); + const_iterator l = f; + + if (l != end()) + { + ++l; + } + + return ETL_OR_STD::pair(f, l); + } +#endif + //************************************************************************* /// Gets the size of the unordered_map. //************************************************************************* diff --git a/include/etl/unordered_multimap.h b/include/etl/unordered_multimap.h index 463e1cd9d..c4eaff6b9 100644 --- a/include/etl/unordered_multimap.h +++ b/include/etl/unordered_multimap.h @@ -52,6 +52,8 @@ SOFTWARE. #include "placement_new.h" #include "initializer_list.h" +#include "private/comparator_is_transparent.h" + #include //***************************************************************************** @@ -597,6 +599,16 @@ namespace etl return key_hash_function(key) % number_of_buckets; } + //********************************************************************* + /// Returns the bucket index for the key. + ///\return The bucket index for the key. + //********************************************************************* + template ::value, int> = 0> + size_type get_bucket_index(const K& key) const + { + return key_hash_function(key) % number_of_buckets; + } + //********************************************************************* /// Returns the size of the bucket key. ///\return The bucket size of the bucket key. @@ -608,6 +620,18 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } + //********************************************************************* + /// Returns the size of the bucket key. + ///\return The bucket size of the bucket key. + //********************************************************************* + template ::value, int> = 0> + size_type bucket_size(const K& key) const + { + size_t index = bucket(key); + + return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); + } + //********************************************************************* /// Returns the maximum number of the buckets the container can hold. ///\return The maximum number of the buckets the container can hold. @@ -868,6 +892,41 @@ namespace etl return n; } + //********************************************************************* + /// Erases an element. + ///\param key The key to erase. + ///\return The number of elements erased. + //********************************************************************* + template ::value, int> = 0> + size_t erase(const K& key) + { + size_t n = 0UL; + size_t bucket_id = get_bucket_index(key); + + bucket_t& bucket = pbuckets[bucket_id]; + + local_iterator iprevious = bucket.before_begin(); + local_iterator icurrent = bucket.begin(); + + while (icurrent != bucket.end()) + { + if (key_equal_function(icurrent->key_value_pair.first, key)) + { + delete_data_node(iprevious, icurrent, bucket); + ++n; + icurrent = iprevious; + } + else + { + ++iprevious; + } + + ++icurrent; + } + + return n; + } + //********************************************************************* /// Erases an element. ///\param ielement Iterator to the element. @@ -985,6 +1044,33 @@ namespace etl return n; } + //********************************************************************* + /// Counts an element. + ///\param key The key to search for. + ///\return 1 if the key exists, otherwise 0. + //********************************************************************* + template ::value, int> = 0> + size_t count(const K& key) const + { + size_t n = 0UL; + const_iterator f = find(key); + const_iterator l = f; + + if (l != end()) + { + ++l; + ++n; + + while ((l != end()) && key_equal_function(key, l->first)) + { + ++l; + ++n; + } + } + + return n; + } + //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1053,6 +1139,76 @@ namespace etl return end(); } + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + iterator find(const K& key) + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key_value_pair.first)) + { + return iterator((pbuckets + number_of_buckets), pbucket, inode); + } + + ++inode; + } + } + + return end(); + } + + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + const_iterator find(const K& key) const + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key_value_pair.first)) + { + return const_iterator((pbuckets + number_of_buckets), pbucket, inode); + } + + ++inode; + } + } + + return end(); + } + //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1105,6 +1261,60 @@ namespace etl return ETL_OR_STD::pair(f, l); } + //********************************************************************* + /// Returns a range containing all elements with key key in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return An iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) + { + iterator f = find(key); + iterator l = f; + + if (l != end()) + { + ++l; + + while ((l != end()) && key_equal_function(key, l->first)) + { + ++l; + } + } + + return ETL_OR_STD::pair(f, l); + } + + //********************************************************************* + /// Returns a range containing all elements with key key in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return A const iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) const + { + const_iterator f = find(key); + const_iterator l = f; + + if (l != end()) + { + ++l; + + while ((l != end()) && key_equal_function(key, l->first)) + { + ++l; + } + } + + return ETL_OR_STD::pair(f, l); + } + //************************************************************************* /// Gets the size of the unordered_multimap. //************************************************************************* diff --git a/include/etl/unordered_multiset.h b/include/etl/unordered_multiset.h index 304dc4bc7..ea2fba385 100644 --- a/include/etl/unordered_multiset.h +++ b/include/etl/unordered_multiset.h @@ -51,6 +51,8 @@ SOFTWARE. #include "placement_new.h" #include "initializer_list.h" +#include "private/comparator_is_transparent.h" + #include //***************************************************************************** @@ -588,6 +590,16 @@ namespace etl return key_hash_function(key) % number_of_buckets; } + //********************************************************************* + /// Returns the bucket index for the key. + ///\return The bucket index for the key. + //********************************************************************* + template ::value, int> = 0> + size_type get_bucket_index(const K& key) const + { + return key_hash_function(key) % number_of_buckets; + } + //********************************************************************* /// Returns the size of the bucket key. ///\return The bucket size of the bucket key. @@ -599,6 +611,18 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } + //********************************************************************* + /// Returns the size of the bucket key. + ///\return The bucket size of the bucket key. + //********************************************************************* + template ::value, int> = 0> + size_type bucket_size(const K& key) const + { + size_t index = bucket(key); + + return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); + } + //********************************************************************* /// Returns the maximum number of the buckets the container can hold. ///\return The maximum number of the buckets the container can hold. @@ -712,6 +736,77 @@ namespace etl return result; } + //********************************************************************* + /// Inserts a value to the unordered_multiset. + /// If asserts or exceptions are enabled, emits unordered_multiset_full if the unordered_multiset is already full. + ///\param value The value to insert. + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair insert(const K& key) + { + ETL_OR_STD::pair result(end(), false); + + ETL_ASSERT(!full(), ETL_ERROR(unordered_multiset_full)); + + // Get the hash index. + size_t index = get_bucket_index(key); + + // Get the bucket & bucket iterator. + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // The first one in the bucket? + if (bucket.empty()) + { + // Get a new node. + node_t* node = allocate_data_node(); + node->clear(); + ::new (&node->key) value_type(key); + ETL_INCREMENT_DEBUG_COUNT; + + // Just add the pointer to the bucket; + bucket.insert_after(bucket.before_begin(), *node); + adjust_first_last_markers_after_insert(&bucket); + + result.first = iterator((pbuckets + number_of_buckets), pbucket, pbucket->begin()); + result.second = true; + } + else + { + // Step though the bucket looking for a place to insert. + local_iterator inode_previous = bucket.before_begin(); + local_iterator inode = bucket.begin(); + + while (inode != bucket.end()) + { + // Do we already have this key? + if (key_equal_function(inode->key, key)) + { + break; + } + + ++inode_previous; + ++inode; + } + + // Get a new node. + node_t* node = allocate_data_node(); + node->clear(); + ::new (&node->key) value_type(key); + ETL_INCREMENT_DEBUG_COUNT; + + // Add the node to the end of the bucket; + bucket.insert_after(inode_previous, *node); + adjust_first_last_markers_after_insert(&bucket); + ++inode_previous; + + result.first = iterator((pbuckets + number_of_buckets), pbucket, inode_previous); + result.second = true; + } + + return result; + } + #if ETL_USING_CPP11 //********************************************************************* /// Inserts a value to the unordered_multiset. @@ -846,6 +941,41 @@ namespace etl return n; } + //********************************************************************* + /// Erases an element. + ///\param key The key to erase. + ///\return The number of elements erased. 0 or 1. + //********************************************************************* + template ::value, int> = 0> + size_t erase(const K& key) + { + size_t n = 0UL; + size_t bucket_id = get_bucket_index(key); + + bucket_t& bucket = pbuckets[bucket_id]; + + local_iterator iprevious = bucket.before_begin(); + local_iterator icurrent = bucket.begin(); + + while (icurrent != bucket.end()) + { + if (key_equal_function(icurrent->key, key)) + { + delete_data_node(iprevious, icurrent, bucket); + ++n; + icurrent = iprevious; + } + else + { + ++iprevious; + } + + ++icurrent; + } + + return n; + } + //********************************************************************* /// Erases an element. ///\param ielement Iterator to the element. @@ -963,6 +1093,33 @@ namespace etl return n; } + //********************************************************************* + /// Counts an element. + ///\param key The key to search for. + ///\return 1 if the key exists, otherwise 0. + //********************************************************************* + template ::value, int> = 0> + size_t count(const K& key) const + { + size_t n = 0UL; + const_iterator f = find(key); + const_iterator l = f; + + if (l != end()) + { + ++l; + ++n; + + while ((l != end()) && key_equal_function(key, *l)) + { + ++l; + ++n; + } + } + + return n; + } + //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1031,6 +1188,76 @@ namespace etl return end(); } + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + iterator find(const K& key) + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key)) + { + return iterator(pbuckets + number_of_buckets, pbucket, inode); + } + + ++inode; + } + } + + return end(); + } + + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + const_iterator find(const K& key) const + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key)) + { + return iterator(pbuckets + number_of_buckets, pbucket, inode); + } + + ++inode; + } + } + + return end(); + } + //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first diff --git a/include/etl/unordered_set.h b/include/etl/unordered_set.h index 1f9a7e6ee..ec983b3a1 100644 --- a/include/etl/unordered_set.h +++ b/include/etl/unordered_set.h @@ -52,6 +52,8 @@ SOFTWARE. #include "placement_new.h" #include "initializer_list.h" +#include "private/comparator_is_transparent.h" + #include //***************************************************************************** @@ -589,6 +591,16 @@ namespace etl return key_hash_function(key) % number_of_buckets; } + //********************************************************************* + /// Returns the bucket index for the key. + ///\return The bucket index for the key. + //********************************************************************* + template ::value, int> = 0> + size_type get_bucket_index(const K& key) const + { + return key_hash_function(key) % number_of_buckets; + } + //********************************************************************* /// Returns the size of the bucket key. ///\return The bucket size of the bucket key. @@ -600,6 +612,18 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } + //********************************************************************* + /// Returns the size of the bucket key. + ///\return The bucket size of the bucket key. + //********************************************************************* + template ::value, int> = 0> + size_type bucket_size(const K& key) const + { + size_t index = bucket(key); + + return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); + } + //********************************************************************* /// Returns the maximum number of the buckets the container can hold. ///\return The maximum number of the buckets the container can hold. @@ -730,6 +754,94 @@ namespace etl return result; } + //********************************************************************* + /// Inserts a value to the unordered_set. + /// If asserts or exceptions are enabled, emits unordered_set_full if the unordered_set is already full. + ///\param value The value to insert. + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair insert(const K& key) + { + ETL_OR_STD::pair result(end(), false); + + if (full()) + { + iterator iter = find(key); + if (iter == end()) + { + ETL_ASSERT_FAIL(ETL_ERROR(unordered_set_full)); + } + else + { + result.first = iter; + result.second = false; + return result; + } + } + + // Get the hash index. + size_t index = get_bucket_index(key); + + // Get the bucket & bucket iterator. + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // The first one in the bucket? + if (bucket.empty()) + { + // Get a new node. + node_t* node = allocate_data_node(); + node->clear(); + ::new (&node->key) value_type(key); + ETL_INCREMENT_DEBUG_COUNT; + + // Just add the pointer to the bucket; + bucket.insert_after(bucket.before_begin(), *node); + adjust_first_last_markers_after_insert(&bucket); + + result.first = iterator(pbuckets + number_of_buckets, pbucket, pbucket->begin()); + result.second = true; + } + else + { + // Step though the bucket looking for a place to insert. + local_iterator inode_previous = bucket.before_begin(); + local_iterator inode = bucket.begin(); + + while (inode != bucket.end()) + { + // Do we already have this key? + if (key_equal_function(inode->key, key)) + { + break; + } + + ++inode_previous; + ++inode; + } + + // Not already there? + if (inode == bucket.end()) + { + // Get a new node. + node_t* node = allocate_data_node(); + node->clear(); + ::new (&node->key) value_type(key); + ETL_INCREMENT_DEBUG_COUNT; + + // Add the node to the end of the bucket; + bucket.insert_after(inode_previous, *node); + adjust_first_last_markers_after_insert(&bucket); + ++inode_previous; + + result.first = iterator(pbuckets + number_of_buckets, pbucket, inode_previous); + result.second = true; + } + } + + return result; + } + #if ETL_USING_CPP11 //********************************************************************* /// Inserts a value to the unordered_set. @@ -892,6 +1004,39 @@ namespace etl return n; } + //********************************************************************* + /// Erases an element. + ///\param key The key to erase. + ///\return The number of elements erased. 0 or 1. + //********************************************************************* + template ::value, int> = 0> + size_t erase(const K& key) + { + size_t n = 0UL; + size_t index = get_bucket_index(key); + + bucket_t& bucket = pbuckets[index]; + + local_iterator iprevious = bucket.before_begin(); + local_iterator icurrent = bucket.begin(); + + // Search for the key, if we have it. + while ((icurrent != bucket.end()) && (!key_equal_function(icurrent->key, key))) + { + ++iprevious; + ++icurrent; + } + + // Did we find it? + if (icurrent != bucket.end()) + { + delete_data_node(iprevious, icurrent, bucket); + n = 1; + } + + return n; + } + //********************************************************************* /// Erases an element. ///\param ielement Iterator to the element. @@ -993,6 +1138,17 @@ namespace etl return (find(key) == end()) ? 0 : 1; } + //********************************************************************* + /// Counts an element. + ///\param key The key to search for. + ///\return 1 if the key exists, otherwise 0. + //********************************************************************* + template ::value, int> = 0> + size_t count(const K& key) const + { + return (find(key) == end()) ? 0 : 1; + } + //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1061,6 +1217,76 @@ namespace etl return end(); } + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + iterator find(const K& key) + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key)) + { + return iterator(pbuckets + number_of_buckets, pbucket, inode); + } + + ++inode; + } + } + + return end(); + } + + //********************************************************************* + /// Finds an element. + ///\param key The key to search for. + ///\return An iterator to the element if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + const_iterator find(const K& key) const + { + size_t index = get_bucket_index(key); + + bucket_t* pbucket = pbuckets + index; + bucket_t& bucket = *pbucket; + + // Is the bucket not empty? + if (!bucket.empty()) + { + // Step though the list until we find the end or an equivalent key. + local_iterator inode = bucket.begin(); + local_iterator iend = bucket.end(); + + while (inode != iend) + { + // Do we have this one? + if (key_equal_function(key, inode->key)) + { + return iterator(pbuckets + number_of_buckets, pbucket, inode); + } + + ++inode; + } + } + + return end(); + } + //********************************************************************* /// Returns a range containing all elements with key 'key' in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1103,6 +1329,50 @@ namespace etl return ETL_OR_STD::pair(f, l); } + //********************************************************************* + /// Returns a range containing all elements with key 'key' in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return An iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) + { + iterator f = find(key); + iterator l = f; + + if (l != end()) + { + ++l; + } + + return ETL_OR_STD::pair(f, l); + } + + //********************************************************************* + /// Returns a range containing all elements with key 'key' in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return A const iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) const + { + const_iterator f = find(key); + const_iterator l = f; + + if (l != end()) + { + ++l; + } + + return ETL_OR_STD::pair(f, l); + } + //************************************************************************* /// Gets the size of the unordered_set. //************************************************************************* diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 4f7b1b7be..34767d698 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -130,6 +130,25 @@ namespace return true; } + //************************************************************************* + struct transparent_hash + { + typedef int is_transparent; + + size_t operator ()(const char* s) const + { + size_t sum = 0U; + size_t length = etl::strlen(s); + + return std::accumulate(s, s + length, sum); + } + + size_t operator ()(const std::string& text) const + { + return std::accumulate(text.begin(), text.end(), 0); + } + }; + typedef TestDataDC DC; typedef TestDataNDC NDC; @@ -204,17 +223,19 @@ namespace typedef etl::unordered_map DataDC; typedef etl::unordered_map DataNDC; typedef etl::iunordered_map IDataNDC; - - NDC N0 = NDC("A"); - NDC N1 = NDC("B"); - NDC N2 = NDC("C"); - NDC N3 = NDC("D"); - NDC N4 = NDC("E"); - NDC N5 = NDC("F"); - NDC N6 = NDC("G"); - NDC N7 = NDC("H"); - NDC N8 = NDC("I"); - NDC N9 = NDC("J"); + typedef etl::unordered_map> DataNDCTransparent; + typedef etl::unordered_map> DataDCTransparent; + + NDC N0 = NDC("A"); + NDC N1 = NDC("B"); + NDC N2 = NDC("C"); + NDC N3 = NDC("D"); + NDC N4 = NDC("E"); + NDC N5 = NDC("F"); + NDC N6 = NDC("G"); + NDC N7 = NDC("H"); + NDC N8 = NDC("I"); + NDC N9 = NDC("J"); NDC N10 = NDC("K"); NDC N11 = NDC("L"); NDC N12 = NDC("M"); @@ -226,16 +247,16 @@ namespace NDC N18 = NDC("S"); NDC N19 = NDC("T"); - DC M0 = DC("A"); - DC M1 = DC("B"); - DC M2 = DC("C"); - DC M3 = DC("D"); - DC M4 = DC("E"); - DC M5 = DC("F"); - DC M6 = DC("G"); - DC M7 = DC("H"); - DC M8 = DC("I"); - DC M9 = DC("J"); + DC M0 = DC("A"); + DC M1 = DC("B"); + DC M2 = DC("C"); + DC M3 = DC("D"); + DC M4 = DC("E"); + DC M5 = DC("F"); + DC M6 = DC("G"); + DC M7 = DC("H"); + DC M8 = DC("I"); + DC M9 = DC("J"); DC M10 = DC("K"); DC M11 = DC("L"); DC M12 = DC("M"); @@ -247,26 +268,47 @@ namespace DC M18 = DC("S"); DC M19 = DC("T"); - const char* K0 = "FF"; // 0 - const char* K1 = "FG"; // 1 - const char* K2 = "FH"; // 2 - const char* K3 = "FI"; // 3 - const char* K4 = "FJ"; // 4 - const char* K5 = "FK"; // 5 - const char* K6 = "FL"; // 6 - const char* K7 = "FM"; // 7 - const char* K8 = "FN"; // 8 - const char* K9 = "FO"; // 9 - const char* K10 = "FP"; // 0 - const char* K11 = "FQ"; // 1 - const char* K12 = "FR"; // 2 - const char* K13 = "FS"; // 3 - const char* K14 = "FT"; // 4 - const char* K15 = "FU"; // 5 - const char* K16 = "FV"; // 6 - const char* K17 = "FW"; // 7 - const char* K18 = "FX"; // 8 - const char* K19 = "FY"; // 9 + const char* CK0 = "FF"; // 0 + const char* CK1 = "FG"; // 1 + const char* CK2 = "FH"; // 2 + const char* CK3 = "FI"; // 3 + const char* CK4 = "FJ"; // 4 + const char* CK5 = "FK"; // 5 + const char* CK6 = "FL"; // 6 + const char* CK7 = "FM"; // 7 + const char* CK8 = "FN"; // 8 + const char* CK9 = "FO"; // 9 + const char* CK10 = "FP"; // 0 + const char* CK11 = "FQ"; // 1 + const char* CK12 = "FR"; // 2 + const char* CK13 = "FS"; // 3 + const char* CK14 = "FT"; // 4 + const char* CK15 = "FU"; // 5 + const char* CK16 = "FV"; // 6 + const char* CK17 = "FW"; // 7 + const char* CK18 = "FX"; // 8 + const char* CK19 = "FY"; // 9 + + std::string K0 = CK0; // 0 + std::string K1 = CK1; // 1 + std::string K2 = CK2; // 2 + std::string K3 = CK3; // 3 + std::string K4 = CK4; // 4 + std::string K5 = CK5; // 5 + std::string K6 = CK6; // 6 + std::string K7 = CK7; // 7 + std::string K8 = CK8; // 8 + std::string K9 = CK9; // 9 + std::string K10 = CK10; // 0 + std::string K11 = CK11; // 1 + std::string K12 = CK12; // 2 + std::string K13 = CK13; // 3 + std::string K14 = CK14; // 4 + std::string K15 = CK15; // 5 + std::string K16 = CK16; // 6 + std::string K17 = CK17; // 7 + std::string K18 = CK18; // 8 + std::string K19 = CK19; // 9 std::string K[] = { K0, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, K12, K13, K14, K15, K16, K17, K18, K19 }; @@ -502,6 +544,23 @@ namespace CHECK_EQUAL(M9, data[K9]); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_index_read_using_transparent_comparator_and_hasher) + { + DataDCTransparent data(initial_data_dc.begin(), initial_data_dc.end()); + + CHECK_EQUAL(M0, data[CK0]); + CHECK_EQUAL(M1, data[CK1]); + CHECK_EQUAL(M2, data[CK2]); + CHECK_EQUAL(M3, data[CK3]); + CHECK_EQUAL(M4, data[CK4]); + CHECK_EQUAL(M5, data[CK5]); + CHECK_EQUAL(M6, data[CK6]); + CHECK_EQUAL(M7, data[CK7]); + CHECK_EQUAL(M8, data[CK8]); + CHECK_EQUAL(M9, data[CK9]); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_write) { @@ -530,6 +589,34 @@ namespace CHECK_EQUAL(M0, data[K9]); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_index_write_using_transparent_comparator_and_hasher) + { + DataDCTransparent data(initial_data_dc.begin(), initial_data_dc.end()); + + data[CK0] = M9; + data[CK1] = M8; + data[CK2] = M7; + data[CK3] = M6; + data[CK4] = M5; + data[CK5] = M4; + data[CK6] = M3; + data[CK7] = M2; + data[CK8] = M1; + data[CK9] = M0; + + CHECK_EQUAL(M9, data[CK0]); + CHECK_EQUAL(M8, data[CK1]); + CHECK_EQUAL(M7, data[CK2]); + CHECK_EQUAL(M6, data[CK3]); + CHECK_EQUAL(M5, data[CK4]); + CHECK_EQUAL(M4, data[CK5]); + CHECK_EQUAL(M3, data[CK6]); + CHECK_EQUAL(M2, data[CK7]); + CHECK_EQUAL(M1, data[CK8]); + CHECK_EQUAL(M0, data[CK9]); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { @@ -547,6 +634,23 @@ namespace CHECK_EQUAL(data.at(K9), N9); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_at_using_transparent_comparator_and_hasher) + { + DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + CHECK_EQUAL(data.at(CK0), N0); + CHECK_EQUAL(data.at(CK1), N1); + CHECK_EQUAL(data.at(CK2), N2); + CHECK_EQUAL(data.at(CK3), N3); + CHECK_EQUAL(data.at(CK4), N4); + CHECK_EQUAL(data.at(CK5), N5); + CHECK_EQUAL(data.at(CK6), N6); + CHECK_EQUAL(data.at(CK7), N7); + CHECK_EQUAL(data.at(CK8), N8); + CHECK_EQUAL(data.at(CK9), N9); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { @@ -564,6 +668,23 @@ namespace CHECK_EQUAL(data.at(K9), N9); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_at_const_using_transparent_comparator_and_hasher) + { + const DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + CHECK_EQUAL(data.at(CK0), N0); + CHECK_EQUAL(data.at(CK1), N1); + CHECK_EQUAL(data.at(CK2), N2); + CHECK_EQUAL(data.at(CK3), N3); + CHECK_EQUAL(data.at(CK4), N4); + CHECK_EQUAL(data.at(CK5), N5); + CHECK_EQUAL(data.at(CK6), N6); + CHECK_EQUAL(data.at(CK7), N7); + CHECK_EQUAL(data.at(CK8), N8); + CHECK_EQUAL(data.at(CK9), N9); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { @@ -687,6 +808,23 @@ namespace CHECK(!data.empty()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_key_using_transparent_comparator) + { + DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + size_t count = data.erase(CK5); + + CHECK_EQUAL(1U, count); + + DataNDCTransparent::iterator idata = data.find(CK5); + CHECK(idata == data.end()); + + // Test that erase really does erase from the pool. + CHECK(!data.full()); + CHECK(!data.empty()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { @@ -837,6 +975,18 @@ namespace CHECK_EQUAL(0U, count); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_count_key_using_transparent_comparator) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + size_t count = data.count(CK5); + CHECK_EQUAL(1U, count); + + count = data.count(CK12); + CHECK_EQUAL(0U, count); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_equal_range) { @@ -863,6 +1013,32 @@ namespace CHECK_EQUAL(result.first->first, K9); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_equal_range_using_transparent_comparator) + { + DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + ETL_OR_STD::pair result; + + result = data.equal_range("FF"); + CHECK(result.first == data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, "FF"); + + result = data.equal_range("FJ"); + CHECK(result.first != data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, "FJ"); + + result = data.equal_range("FO"); + CHECK(result.first != data.begin()); + CHECK(result.second == data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, "FO"); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_equal_range_const) { @@ -889,6 +1065,32 @@ namespace CHECK_EQUAL(result.first->first, K9); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_equal_range_const_using_transparent_comparator) + { + const DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + ETL_OR_STD::pair result; + + result = data.equal_range("FF"); + CHECK(result.first == data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, "FF"); + + result = data.equal_range("FJ"); + CHECK(result.first != data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, "FJ"); + + result = data.equal_range("FO"); + CHECK(result.first != data.begin()); + CHECK(result.second == data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, "FO"); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_equal) { diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index 60b9eb92e..9789af61e 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -85,6 +85,25 @@ namespace return true; } + //************************************************************************* + struct transparent_hash + { + typedef int is_transparent; + + size_t operator ()(const char* s) const + { + size_t sum = 0U; + size_t length = etl::strlen(s); + + return std::accumulate(s, s + length, sum); + } + + size_t operator ()(const std::string& text) const + { + return std::accumulate(text.begin(), text.end(), 0); + } + }; + typedef TestDataDC DC; typedef TestDataNDC NDC; @@ -175,6 +194,8 @@ namespace typedef etl::unordered_multimap DataDC; typedef etl::unordered_multimap DataNDC; typedef etl::iunordered_multimap IDataNDC; + typedef etl::unordered_multimap> DataNDCTransparent; + typedef etl::unordered_multimap> DataDCTransparent; using ItemM = TestDataM; using DataM = etl::unordered_multimap>; @@ -200,26 +221,47 @@ namespace NDC N18 = NDC("S"); NDC N19 = NDC("T"); - const char* K0 = "FF"; // 0 - const char* K1 = "FG"; // 1 - const char* K2 = "FH"; // 2 - const char* K3 = "FI"; // 3 - const char* K4 = "FJ"; // 4 - const char* K5 = "FK"; // 5 - const char* K6 = "FL"; // 6 - const char* K7 = "FM"; // 7 - const char* K8 = "FN"; // 8 - const char* K9 = "FO"; // 9 - const char* K10 = "FP"; // 0 - const char* K11 = "FQ"; // 1 - const char* K12 = "FR"; // 2 - const char* K13 = "FS"; // 3 - const char* K14 = "FT"; // 4 - const char* K15 = "FU"; // 5 - const char* K16 = "FV"; // 6 - const char* K17 = "FW"; // 7 - const char* K18 = "FX"; // 8 - const char* K19 = "FY"; // 9 + const char* CK0 = "FF"; // 0 + const char* CK1 = "FG"; // 1 + const char* CK2 = "FH"; // 2 + const char* CK3 = "FI"; // 3 + const char* CK4 = "FJ"; // 4 + const char* CK5 = "FK"; // 5 + const char* CK6 = "FL"; // 6 + const char* CK7 = "FM"; // 7 + const char* CK8 = "FN"; // 8 + const char* CK9 = "FO"; // 9 + const char* CK10 = "FP"; // 0 + const char* CK11 = "FQ"; // 1 + const char* CK12 = "FR"; // 2 + const char* CK13 = "FS"; // 3 + const char* CK14 = "FT"; // 4 + const char* CK15 = "FU"; // 5 + const char* CK16 = "FV"; // 6 + const char* CK17 = "FW"; // 7 + const char* CK18 = "FX"; // 8 + const char* CK19 = "FY"; // 9 + + std::string K0 = CK0; // 0 + std::string K1 = CK1; // 1 + std::string K2 = CK2; // 2 + std::string K3 = CK3; // 3 + std::string K4 = CK4; // 4 + std::string K5 = CK5; // 5 + std::string K6 = CK6; // 6 + std::string K7 = CK7; // 7 + std::string K8 = CK8; // 8 + std::string K9 = CK9; // 9 + std::string K10 = CK10; // 0 + std::string K11 = CK11; // 1 + std::string K12 = CK12; // 2 + std::string K13 = CK13; // 3 + std::string K14 = CK14; // 4 + std::string K15 = CK15; // 5 + std::string K16 = CK16; // 6 + std::string K17 = CK17; // 7 + std::string K18 = CK18; // 8 + std::string K19 = CK19; // 9 std::string K[] = { K0, K1, K2, K3, K4, K5, K6, K7, K8, K9, K10, K11, K12, K13, K14, K15, K16, K17, K18, K19 }; @@ -572,6 +614,26 @@ namespace CHECK(idata == data.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_key_using_transparent_comparator) + { + DataNDCTransparent data(equal_data.begin(), equal_data.end()); + + size_t count = data.erase("FP"); + + CHECK_EQUAL(1U, count); + + DataNDCTransparent::iterator idata = data.find("FP"); + CHECK(idata == data.end()); + + count = data.erase("FQ"); + + CHECK_EQUAL(3U, count); + + idata = data.find("FQ"); + CHECK(idata == data.end()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { @@ -717,7 +779,6 @@ namespace CHECK_EQUAL(data.size(), size_t(0)); } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_count_key) { @@ -733,6 +794,31 @@ namespace CHECK_EQUAL(0U, count); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_count_key_using_transparent_comparator) + { + DataNDCTransparent data(equal_data.begin(), equal_data.end()); + + size_t count = data.count(K10); + CHECK_EQUAL(1U, count); + + count = data.count(K11); + CHECK_EQUAL(3U, count); + + count = data.count(K1); + CHECK_EQUAL(0U, count); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find) + { + DataNDC data(initial_data.begin(), initial_data.end()); + + DataNDC::iterator idata = data.find(K3); + + CHECK(idata != data.end()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_const) { @@ -743,6 +829,26 @@ namespace CHECK(idata != data.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_using_transparent_comparator) + { + DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + DataNDCTransparent::iterator idata = data.find(CK3); + + CHECK(idata != data.end()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_const_using_transparent_comparator) + { + const DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + DataNDCTransparent::const_iterator idata = data.find(CK3); + + CHECK(idata != data.end()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_equal_range) { @@ -795,6 +901,58 @@ namespace CHECK_EQUAL(result.first->first, K12); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_equal_range_using_transparent_comparator) + { + DataNDCTransparent data(equal_data.begin(), equal_data.end()); + + ETL_OR_STD::pair result; + + result = data.equal_range(CK10); + CHECK(result.first == data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, CK10); + + result = data.equal_range(CK11); + CHECK(result.first != data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 3); + CHECK_EQUAL(result.first->first, CK11); + + result = data.equal_range(CK12); + CHECK(result.first != data.begin()); + CHECK(result.second == data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, CK12); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_equal_range_const_using_transparent_comparator) + { + const DataNDCTransparent data(equal_data.begin(), equal_data.end()); + + ETL_OR_STD::pair result; + + result = data.equal_range(CK10); + CHECK(result.first == data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, CK10); + + result = data.equal_range(CK11); + CHECK(result.first != data.begin()); + CHECK(result.second != data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 3); + CHECK_EQUAL(result.first->first, CK11); + + result = data.equal_range(CK12); + CHECK(result.first != data.begin()); + CHECK(result.second == data.end()); + CHECK_EQUAL(std::distance(result.first, result.second), 1); + CHECK_EQUAL(result.first->first, CK12); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_equal) { diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index 843a490ea..49b8f59f0 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -135,6 +135,22 @@ namespace } }; + //************************************************************************* + struct transparent_hash + { + typedef int is_transparent; + + size_t operator ()(const char* s) const + { + return std::accumulate(s, s + etl::strlen(s), 0); + } + + size_t operator ()(const std::string& s) const + { + return std::accumulate(s.begin(), s.end(), 0); + } + }; + SUITE(test_unordered_multiset) { static const size_t SIZE = 10; @@ -165,26 +181,49 @@ namespace typedef etl::unordered_multiset DataNDC; typedef etl::iunordered_multiset IDataNDC; - NDC N0 = NDC("FF"); - NDC N1 = NDC("FG"); - NDC N2 = NDC("FH"); - NDC N3 = NDC("FI"); - NDC N4 = NDC("FJ"); - NDC N5 = NDC("FK"); - NDC N6 = NDC("FL"); - NDC N7 = NDC("FM"); - NDC N8 = NDC("FN"); - NDC N9 = NDC("FO"); - NDC N10 = NDC("FP"); - NDC N11 = NDC("FQ"); - NDC N12 = NDC("FR"); - NDC N13 = NDC("FS"); - NDC N14 = NDC("FT"); - NDC N15 = NDC("FU"); - NDC N16 = NDC("FV"); - NDC N17 = NDC("FW"); - NDC N18 = NDC("FX"); - NDC N19 = NDC("FY"); + typedef etl::unordered_multiset> DataTransparent; + + const char* CK0 = "FF"; // 0 + const char* CK1 = "FG"; // 1 + const char* CK2 = "FH"; // 2 + const char* CK3 = "FI"; // 3 + const char* CK4 = "FJ"; // 4 + const char* CK5 = "FK"; // 5 + const char* CK6 = "FL"; // 6 + const char* CK7 = "FM"; // 7 + const char* CK8 = "FN"; // 8 + const char* CK9 = "FO"; // 9 + const char* CK10 = "FP"; // 0 + const char* CK11 = "FQ"; // 1 + const char* CK12 = "FR"; // 2 + const char* CK13 = "FS"; // 3 + const char* CK14 = "FT"; // 4 + const char* CK15 = "FU"; // 5 + const char* CK16 = "FV"; // 6 + const char* CK17 = "FW"; // 7 + const char* CK18 = "FX"; // 8 + const char* CK19 = "FY"; // 9 + + NDC N0 = NDC(CK0); + NDC N1 = NDC(CK1); + NDC N2 = NDC(CK2); + NDC N3 = NDC(CK3); + NDC N4 = NDC(CK4); + NDC N5 = NDC(CK5); + NDC N6 = NDC(CK6); + NDC N7 = NDC(CK7); + NDC N8 = NDC(CK8); + NDC N9 = NDC(CK9); + NDC N10 = NDC(CK10); + NDC N11 = NDC(CK11); + NDC N12 = NDC(CK12); + NDC N13 = NDC(CK13); + NDC N14 = NDC(CK14); + NDC N15 = NDC(CK15); + NDC N16 = NDC(CK16); + NDC N17 = NDC(CK17); + NDC N18 = NDC(CK18); + NDC N19 = NDC(CK19); std::vector initial_data; std::vector excess_data; @@ -394,6 +433,24 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data; + + data.assign(initial.begin(), initial.end()); + + DataTransparent::iterator idata; + + for (size_t i = 0UL; i < 8; ++i) + { + idata = data.find(initial[i]); + CHECK(idata != data.end()); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_value) { @@ -431,6 +488,38 @@ namespace CHECK(*idata == N11); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_value_using_transparent_comparator) + { + DataTransparent data; + + data.insert(CK0); // Inserted + data.insert(CK2); // Inserted + data.insert(CK1); // Inserted + data.insert(CK11); // Duplicate hash. Inserted + data.insert(CK3); // Inserted + + CHECK_EQUAL(5U, data.size()); + + DataTransparent::iterator idata; + + idata = data.find(CK0); + CHECK(idata != data.end()); + CHECK(*idata == CK0); + + idata = data.find(CK1); + CHECK(idata != data.end()); + CHECK(*idata == CK1); + + idata = data.find(CK2); + CHECK(idata != data.end()); + CHECK(*idata == CK2); + + idata = data.find(CK11); + CHECK(idata != data.end()); + CHECK(*idata == CK11); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_value_excess) { @@ -453,6 +542,24 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_range_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data; + + data.insert(initial.begin(), initial.end()); + + DataTransparent::iterator idata; + + for (size_t i = 0UL; i < 8; ++i) + { + idata = data.find(initial[i]); + CHECK(idata != data.end()); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_range_excess) { @@ -505,6 +612,21 @@ namespace CHECK(idata == data.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_key_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data(initial.begin(), initial.end()); + + size_t count = data.erase("CC"); + + CHECK_EQUAL(1U, count); + + DataTransparent::iterator idata = data.find("CC"); + CHECK(idata == data.end()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { @@ -665,6 +787,20 @@ namespace CHECK_EQUAL(0U, count); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_count_key_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data(initial.begin(), initial.end()); + + size_t count = data.count("CC"); + CHECK_EQUAL(1U, count); + + count = data.count("II"); + CHECK_EQUAL(0U, count); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_const) { diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index e8641155b..4336b4a79 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -135,6 +135,22 @@ namespace } }; + //************************************************************************* + struct transparent_hash + { + typedef int is_transparent; + + size_t operator ()(const char* s) const + { + return std::accumulate(s, s + etl::strlen(s), 0); + } + + size_t operator ()(const std::string& s) const + { + return std::accumulate(s.begin(), s.end(), 0); + } + }; + //*************************************************************************** SUITE(test_unordered_set) { @@ -165,27 +181,49 @@ namespace typedef etl::unordered_set DataDC; typedef etl::unordered_set DataNDC; typedef etl::iunordered_set IDataNDC; - - NDC N0 = NDC("FF"); - NDC N1 = NDC("FG"); - NDC N2 = NDC("FH"); - NDC N3 = NDC("FI"); - NDC N4 = NDC("FJ"); - NDC N5 = NDC("FK"); - NDC N6 = NDC("FL"); - NDC N7 = NDC("FM"); - NDC N8 = NDC("FN"); - NDC N9 = NDC("FO"); - NDC N10 = NDC("FP"); - NDC N11 = NDC("FQ"); - NDC N12 = NDC("FR"); - NDC N13 = NDC("FS"); - NDC N14 = NDC("FT"); - NDC N15 = NDC("FU"); - NDC N16 = NDC("FV"); - NDC N17 = NDC("FW"); - NDC N18 = NDC("FX"); - NDC N19 = NDC("FY"); + typedef etl::unordered_set> DataTransparent; + + const char* CK0 = "FF"; // 0 + const char* CK1 = "FG"; // 1 + const char* CK2 = "FH"; // 2 + const char* CK3 = "FI"; // 3 + const char* CK4 = "FJ"; // 4 + const char* CK5 = "FK"; // 5 + const char* CK6 = "FL"; // 6 + const char* CK7 = "FM"; // 7 + const char* CK8 = "FN"; // 8 + const char* CK9 = "FO"; // 9 + const char* CK10 = "FP"; // 0 + const char* CK11 = "FQ"; // 1 + const char* CK12 = "FR"; // 2 + const char* CK13 = "FS"; // 3 + const char* CK14 = "FT"; // 4 + const char* CK15 = "FU"; // 5 + const char* CK16 = "FV"; // 6 + const char* CK17 = "FW"; // 7 + const char* CK18 = "FX"; // 8 + const char* CK19 = "FY"; // 9 + + NDC N0 = NDC(CK0); + NDC N1 = NDC(CK1); + NDC N2 = NDC(CK2); + NDC N3 = NDC(CK3); + NDC N4 = NDC(CK4); + NDC N5 = NDC(CK5); + NDC N6 = NDC(CK6); + NDC N7 = NDC(CK7); + NDC N8 = NDC(CK8); + NDC N9 = NDC(CK9); + NDC N10 = NDC(CK10); + NDC N11 = NDC(CK11); + NDC N12 = NDC(CK12); + NDC N13 = NDC(CK13); + NDC N14 = NDC(CK14); + NDC N15 = NDC(CK15); + NDC N16 = NDC(CK16); + NDC N17 = NDC(CK17); + NDC N18 = NDC(CK18); + NDC N19 = NDC(CK19); std::vector initial_data; std::vector excess_data; @@ -378,6 +416,24 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data; + + data.assign(initial.begin(), initial.end()); + + DataTransparent::iterator idata; + + for (size_t i = 0UL; i < 8; ++i) + { + idata = data.find(initial[i]); + CHECK(idata != data.end()); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_value) { @@ -409,6 +465,38 @@ namespace CHECK(idata != data.end()); CHECK(*idata == N11); } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_value_using_transparent_comparator) + { + DataTransparent data; + + data.insert(CK0); // Inserted + data.insert(CK2); // Inserted + data.insert(CK1); // Inserted + data.insert(CK11); // Duplicate hash. Inserted + data.insert(CK3); // Inserted + + CHECK_EQUAL(5U, data.size()); + + DataTransparent::iterator idata; + + idata = data.find(CK0); + CHECK(idata != data.end()); + CHECK(*idata == CK0); + + idata = data.find(CK1); + CHECK(idata != data.end()); + CHECK(*idata == CK1); + + idata = data.find(CK2); + CHECK(idata != data.end()); + CHECK(*idata == CK2); + + idata = data.find(CK11); + CHECK(idata != data.end()); + CHECK(*idata == CK11); + } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_value_excess) @@ -432,6 +520,24 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_range_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data; + + data.insert(initial.begin(), initial.end()); + + DataTransparent::iterator idata; + + for (size_t i = 0UL; i < 8; ++i) + { + idata = data.find(initial[i]); + CHECK(idata != data.end()); + } + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_range_excess) { @@ -508,6 +614,21 @@ namespace CHECK(idata == data.end()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_erase_key_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data(initial.begin(), initial.end()); + + size_t count = data.erase("CC"); + + CHECK_EQUAL(1U, count); + + DataTransparent::iterator idata = data.find("CC"); + CHECK(idata == data.end()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { @@ -665,6 +786,20 @@ namespace CHECK_EQUAL(0U, count); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_count_key_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data(initial.begin(), initial.end()); + + size_t count = data.count("CC"); + CHECK_EQUAL(1U, count); + + count = data.count("II"); + CHECK_EQUAL(0U, count); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_equal) { From 20989a187a9e6c41feaf2c76030bab7b70b3d007 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 11:55:53 +0000 Subject: [PATCH 11/55] Added new C++17 function wrappers etl::function_as_functor etl::function_ptr_as_functor etl::functor_as_static etl::member_function_as_static etl::member_function_as_functor --- include/etl/utility.h | 133 +++++++++++++++++++++++++++++++++++++----- test/test_utility.cpp | 56 +++++++++++++++++- 2 files changed, 170 insertions(+), 19 deletions(-) diff --git a/include/etl/utility.h b/include/etl/utility.h index 52cf0d37c..b98ca3d70 100644 --- a/include/etl/utility.h +++ b/include/etl/utility.h @@ -496,7 +496,7 @@ namespace etl ETL_STATIC_ASSERT(etl::is_integral::value, "Integral types only"); - typedef T value_type; + using value_type = T; static ETL_CONSTEXPR size_t size() ETL_NOEXCEPT { @@ -504,7 +504,7 @@ namespace etl } }; - namespace private_integer_sequence + namespace private_index_sequence { template struct make_index_sequence; @@ -512,19 +512,19 @@ namespace etl template struct make_index_sequence> { - typedef typename make_index_sequence>::type type; + using type = typename make_index_sequence>::type; }; template struct make_index_sequence<0, etl::integer_sequence> { - typedef etl::integer_sequence type; + using type = etl::integer_sequence; }; } //*********************************** template - using make_index_sequence = typename private_integer_sequence::make_index_sequence>::type; + using make_index_sequence = typename private_index_sequence::make_index_sequence>::type; //*********************************** template @@ -601,10 +601,13 @@ namespace etl #if ETL_USING_CPP11 //************************************************************************* - /// A function wrapper for free/global functions. + // A function wrapper for free/global functions. + // Deprecated. + // See etl::function_ptr_as_functor for a runtime time wrapper option. + // See etl::function_as_functor for a compile time wrapper option. //************************************************************************* template - class functor + class ETL_DEPRECATED functor { public: @@ -618,7 +621,7 @@ namespace etl //********************************* /// Const function operator. - //********************************* + //********************************* constexpr TReturn operator()(TParams... args) const { return ptr(etl::forward(args)...); @@ -629,18 +632,18 @@ namespace etl /// The pointer to the function. TReturn(*ptr)(TParams...); }; -#endif -#if ETL_USING_CPP11 //***************************************************************************** - // A wrapper for a member function + // Wrap a member function with a static free function. // Creates a static member function that calls the specified member function. + // Deprecated + // See etl::member_function_as_static //***************************************************************************** template - class member_function_wrapper; + class ETL_DEPRECATED member_function_wrapper; template - class member_function_wrapper + class ETL_DEPRECATED member_function_wrapper { public: @@ -650,12 +653,12 @@ namespace etl return (Instance.*Method)(etl::forward(params)...); } }; -#endif -#if ETL_USING_CPP11 //***************************************************************************** - // A wrapper for a functor + // Wrap a functor with a static free function. // Creates a static member function that calls the specified functor. + // Deprecated + // See etl::functor_as_static //***************************************************************************** template class functor_wrapper; @@ -672,6 +675,104 @@ namespace etl } }; #endif + +#if ETL_USING_CPP17 + //***************************************************************************** + // Wraps a functor with a static free function at compile time. + // Creates a static member 'function' that calls the specified functor. + //***************************************************************************** + template + struct functor_as_static + { + template + static constexpr auto call(TArgs&&... args) + { + return (Instance.operator())(etl::forward(args)...); + } + }; + + //***************************************************************************** + // Wraps a member function with a static free function at compile time. + // Creates a static member function that calls the specified member function. + //***************************************************************************** + template + struct member_function_as_static + { + template + static constexpr auto call(TArgs&&... args) + { + return (Instance.*Method)(etl::forward(args)...); + } + }; + + //***************************************************************************** + // Wraps a member function with a functor at compile time. + // Creates a functor that calls the specified member function. + //***************************************************************************** + template + class member_function_as_functor + { + public: + + template + constexpr auto operator()(TArgs&&... args) const -> decltype((Instance.*Method)(etl::forward(args)...)) + { + return (Instance.*Method)(etl::forward(args)...); + } + }; + + //***************************************************************************** + // Wraps a function with a functor at compile time. + // Creates a functor that calls the specified free function. + //***************************************************************************** + template + class function_as_functor + { + public: + + template + constexpr auto operator()(TArgs&&... args) const -> decltype(Function(etl::forward(args)...)) + { + return Function(etl::forward(args)...); + } + }; +#endif + +#if ETL_USING_CPP11 + //***************************************************************************** + // Wraps a function pointer with a functor at run time. + // Creates a functor that calls the specified free function. + //***************************************************************************** + template + class function_ptr_as_functor; + + template + class function_ptr_as_functor + { + public: + + //********************************* + /// Constructor. + //********************************* + constexpr function_ptr_as_functor(TReturn(*ptr_)(TArgs...)) + : ptr(ptr_) + { + } + + //********************************* + /// Const function operator. + //********************************* + constexpr TReturn operator()(TArgs... args) const + { + return ptr(etl::forward(args)...); + } + + private: + + /// The pointer to the function. + TReturn(*ptr)(TArgs...); + }; +#endif } #endif diff --git a/test/test_utility.cpp b/test/test_utility.cpp index a1f28e950..07a2818e3 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -412,14 +412,14 @@ namespace } //************************************************************************* - TEST(test_functor) + TEST(test_functor_deprecated) { constexpr etl::functor fw1(TestGlobal); CHECK_EQUAL(2, fw1(1)); } //************************************************************************* - TEST(test_member_function_wrapper) + TEST(test_member_function_wrapper_deprecated) { constexpr int(*pf)(int) = &etl::member_function_wrapper::function; @@ -427,13 +427,63 @@ namespace } //************************************************************************* - TEST(test_functor_wrapper) + TEST(test_functor_wrapper_deprecated) { constexpr int(*pf)(int) = &etl::functor_wrapper::function; CHECK_EQUAL(2, pf(1)); } + //************************************************************************* +#if ETL_USING_CPP17 + TEST(test_function_as_functor) + { + constexpr etl::function_as_functor faf; + + CHECK_EQUAL(2, faf(1)); + } +#endif + + //************************************************************************* + TEST(test_function_ptr_as_functor) + { + constexpr decltype(TestGlobal)* fptr = TestGlobal; + + constexpr etl::function_ptr_as_functor fpaf(fptr); + + CHECK_EQUAL(2, fpaf(1)); + } + + //************************************************************************* +#if ETL_USING_CPP17 + TEST(test_functor_as_static) + { + using fas_t = etl::functor_as_static; + + CHECK_EQUAL(2, fas_t::call(1)); + } +#endif + + //************************************************************************* +#if ETL_USING_CPP17 + TEST(test_member_function_as_static) + { + using mfas_t = etl::member_function_as_static<&TestClass::MemberFunction, test>; + + CHECK_EQUAL(2, mfas_t::call(1)); + } +#endif + +#if ETL_USING_CPP17 + //************************************************************************* + TEST(test_member_function_as_functor) + { + constexpr etl::member_function_as_functor<&TestClass::MemberFunction, test> mfaf; + + CHECK_EQUAL(2, mfaf(1)); + } +#endif + //************************************************************************* struct SF { From 4513be3aae508bf1a208f78701bf5b480cb1c388 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 16:13:44 +0000 Subject: [PATCH 12/55] Updated version and release notes --- arduino/library-arduino.json | 2 +- arduino/library-arduino.properties | 2 +- support/Release notes.txt | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/arduino/library-arduino.json b/arduino/library-arduino.json index 842498193..60a5d5617 100644 --- a/arduino/library-arduino.json +++ b/arduino/library-arduino.json @@ -1,6 +1,6 @@ { "name": "Embedded Template Library ETL", - "version": "20.39.0", + "version": "20.39.5", "authors": { "name": "John Wellbelove", "email": "john.wellbelove@etlcpp.com" diff --git a/arduino/library-arduino.properties b/arduino/library-arduino.properties index 9689dd754..f077e3ec3 100644 --- a/arduino/library-arduino.properties +++ b/arduino/library-arduino.properties @@ -1,5 +1,5 @@ name=Embedded Template Library ETL -version=20.39.0 +version=20.39.5 author= John Wellbelove maintainer=John Wellbelove license=MIT diff --git a/support/Release notes.txt b/support/Release notes.txt index e45c4ea3b..6cc8d9df8 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -1,8 +1,22 @@ =============================================================================== 20.39.5 +Updates: +Added new C++17 function wrappers +Simplified definition of is_base_of +Fixed static definition for etl::string +Redefined ETL_DEPRECATED +Updated nth_type to handle a type list of zero length +Updated Github Actions to checkout@v4 + Fixes: #956 Fix build error (etl::circular_buffer) +#957 Support heterogenous lookup for maps +#959 Treat bitset with size_type + +Pull Requests: +#947 Remove unused git submodule config +#965 Fix accident creation of a delegate to an rvalue delegate when copying/assigning from delegate with mismatching signature =============================================================================== 20.39.4 From 54dc48de022527e6fa6d66e0caf5e68bdbf80590 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 17:58:43 +0000 Subject: [PATCH 13/55] Changed comment Simplified unit test --- include/etl/utility.h | 4 ++-- test/test_utility.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/etl/utility.h b/include/etl/utility.h index b98ca3d70..3e371b40d 100644 --- a/include/etl/utility.h +++ b/include/etl/utility.h @@ -679,7 +679,7 @@ namespace etl #if ETL_USING_CPP17 //***************************************************************************** // Wraps a functor with a static free function at compile time. - // Creates a static member 'function' that calls the specified functor. + // Creates a static member 'call' that calls the specified functor. //***************************************************************************** template struct functor_as_static @@ -693,7 +693,7 @@ namespace etl //***************************************************************************** // Wraps a member function with a static free function at compile time. - // Creates a static member function that calls the specified member function. + // Creates a static member 'call' that calls the specified member function. //***************************************************************************** template struct member_function_as_static diff --git a/test/test_utility.cpp b/test/test_utility.cpp index 07a2818e3..223058547 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -447,9 +447,11 @@ namespace //************************************************************************* TEST(test_function_ptr_as_functor) { - constexpr decltype(TestGlobal)* fptr = TestGlobal; + using function_type = decltype(TestGlobal); - constexpr etl::function_ptr_as_functor fpaf(fptr); + constexpr function_type* fptr = TestGlobal; + + constexpr etl::function_ptr_as_functor fpaf(fptr); CHECK_EQUAL(2, fpaf(1)); } From 01f0cc17fa3a253656d321189a649881fcb6c8ef Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 17:59:03 +0000 Subject: [PATCH 14/55] Updated release notes --- support/Release notes.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/support/Release notes.txt b/support/Release notes.txt index 6cc8d9df8..a4240486a 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -8,6 +8,7 @@ Fixed static definition for etl::string Redefined ETL_DEPRECATED Updated nth_type to handle a type list of zero length Updated Github Actions to checkout@v4 +Added make_delegate for C++17 Fixes: #956 Fix build error (etl::circular_buffer) From 290f8d3f6491229167cd531534e3799dbd7edc91 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 10 Nov 2024 18:34:18 +0000 Subject: [PATCH 15/55] Replaced ETL_OR_STD::size with ETL_OR_STD17::size in unit tests --- test/test_bitset_legacy.cpp | 2 +- test/test_bitset_new_default_element_type.cpp | 2 +- test/test_bitset_new_explicit_single_element_type.cpp | 2 +- test/test_bitset_new_ext_default_element_type.cpp | 2 +- test/test_bitset_new_ext_explicit_single_element_type.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/test/test_bitset_legacy.cpp b/test/test_bitset_legacy.cpp index 88bb30174..7723b1726 100644 --- a/test/test_bitset_legacy.cpp +++ b/test/test_bitset_legacy.cpp @@ -1498,7 +1498,7 @@ namespace { etl::bitset<32> b(0x12345678UL); - CHECK_EQUAL(32, ETL_OR_STD::size(b)); + CHECK_EQUAL(32, ETL_OR_STD17::size(b)); } //************************************************************************* diff --git a/test/test_bitset_new_default_element_type.cpp b/test/test_bitset_new_default_element_type.cpp index 682cd2b8e..0722524ea 100644 --- a/test/test_bitset_new_default_element_type.cpp +++ b/test/test_bitset_new_default_element_type.cpp @@ -2728,7 +2728,7 @@ namespace { etl::bitset<32> b(0x12345678UL); - CHECK_EQUAL(32, ETL_OR_STD::size(b)); + CHECK_EQUAL(32, ETL_OR_STD17::size(b)); } }; } diff --git a/test/test_bitset_new_explicit_single_element_type.cpp b/test/test_bitset_new_explicit_single_element_type.cpp index f6db16a9b..f06d4d42d 100644 --- a/test/test_bitset_new_explicit_single_element_type.cpp +++ b/test/test_bitset_new_explicit_single_element_type.cpp @@ -2821,7 +2821,7 @@ namespace { etl::bitset<32, uint32_t> b(0x12345678UL); - CHECK_EQUAL(32, ETL_OR_STD::size(b)); + CHECK_EQUAL(32, ETL_OR_STD17::size(b)); } }; } diff --git a/test/test_bitset_new_ext_default_element_type.cpp b/test/test_bitset_new_ext_default_element_type.cpp index d944087d4..6e606c0f0 100644 --- a/test/test_bitset_new_ext_default_element_type.cpp +++ b/test/test_bitset_new_ext_default_element_type.cpp @@ -2477,7 +2477,7 @@ namespace { etl::bitset<32> b(0x12345678UL); - CHECK_EQUAL(32, ETL_OR_STD::size(b)); + CHECK_EQUAL(32, ETL_OR_STD17::size(b)); } }; } diff --git a/test/test_bitset_new_ext_explicit_single_element_type.cpp b/test/test_bitset_new_ext_explicit_single_element_type.cpp index e34ffe663..75c18a5fc 100644 --- a/test/test_bitset_new_ext_explicit_single_element_type.cpp +++ b/test/test_bitset_new_ext_explicit_single_element_type.cpp @@ -2625,7 +2625,7 @@ namespace { etl::bitset<32, uint32_t> b(0x12345678UL); - CHECK_EQUAL(32, ETL_OR_STD::size(b)); + CHECK_EQUAL(32, ETL_OR_STD17::size(b)); } }; } From e4a6bc9c44eb95907d6fadddb6a5d54929114927 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 11 Nov 2024 13:19:59 +0000 Subject: [PATCH 16/55] Fixed missing conditional macros around transparent comparator C++11 functions --- include/etl/unordered_map.h | 18 +++++++++--------- include/etl/unordered_multimap.h | 16 ++++++++++++++++ include/etl/unordered_multiset.h | 14 ++++++++++++++ include/etl/unordered_set.h | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/include/etl/unordered_map.h b/include/etl/unordered_map.h index 359218de1..b9d73d2f4 100644 --- a/include/etl/unordered_map.h +++ b/include/etl/unordered_map.h @@ -744,12 +744,12 @@ namespace etl return pbucket->begin()->key_value_pair.second; } +#if ETL_USING_CPP11 //********************************************************************* /// Returns a reference to the value at index 'key' ///\param key The key. ///\return A reference to the value at index 'key' //********************************************************************* -#if ETL_USING_CPP11 template ::value, int> = 0> mapped_reference operator [](const K& key) { @@ -773,7 +773,6 @@ namespace etl ++inode; } } -#endif // Doesn't exist, so add a new one. // Get a new node. @@ -789,6 +788,7 @@ namespace etl return pbucket->begin()->key_value_pair.second; } +#endif //********************************************************************* /// Returns a reference to the value at index 'key' @@ -860,13 +860,13 @@ namespace etl return begin()->second; } +#if ETL_USING_CPP11 //********************************************************************* /// Returns a reference to the value at index 'key' /// If asserts or exceptions are enabled, emits an etl::unordered_map_out_of_range if the key is not in the range. ///\param key The key. ///\return A reference to the value at index 'key' //********************************************************************* -#if ETL_USING_CPP11 template ::value, int> = 0> mapped_reference at(const K& key) { @@ -1190,12 +1190,12 @@ namespace etl return n; } +#if ETL_USING_CPP11 //********************************************************************* /// Erases an element. ///\param key The key to erase. ///\return The number of elements erased. 0 or 1. //********************************************************************* -#if ETL_USING_CPP11 template ::value, int> = 0> size_t erase(const K& key) { @@ -1326,12 +1326,12 @@ namespace etl return (find(key) == end()) ? 0 : 1; } +#if ETL_USING_CPP11 //********************************************************************* /// Counts an element. ///\param key The key to search for. ///\return 1 if the key exists, otherwise 0. //********************************************************************* -#if ETL_USING_CPP11 template ::value, int> = 0> size_t count(const K& key) const { @@ -1407,12 +1407,12 @@ namespace etl return end(); } +#if ETL_USING_CPP11 //********************************************************************* /// Finds an element. ///\param key The key to search for. ///\return An iterator to the element if the key exists, otherwise end(). //********************************************************************* -#if ETL_USING_CPP11 template ::value, int> = 0> iterator find(const K& key) { @@ -1444,12 +1444,12 @@ namespace etl } #endif +#if ETL_USING_CPP11 //********************************************************************* /// Finds an element. ///\param key The key to search for. ///\return An iterator to the element if the key exists, otherwise end(). //********************************************************************* -#if ETL_USING_CPP11 template ::value, int> = 0> const_iterator find(const K& key) const { @@ -1523,6 +1523,7 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#if ETL_USING_CPP11 //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1531,7 +1532,6 @@ namespace etl ///\param key The key to search for. ///\return An iterator pair to the range of elements if the key exists, otherwise end(). //********************************************************************* -#if ETL_USING_CPP11 template ::value, int> = 0> ETL_OR_STD::pair equal_range(const K& key) { @@ -1547,6 +1547,7 @@ namespace etl } #endif +#if ETL_USING_CPP11 //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1555,7 +1556,6 @@ namespace etl ///\param key The key to search for. ///\return A const iterator pair to the range of elements if the key exists, otherwise end(). //********************************************************************* -#if ETL_USING_CPP11 template ::value, int> = 0> ETL_OR_STD::pair equal_range(const K& key) const { diff --git a/include/etl/unordered_multimap.h b/include/etl/unordered_multimap.h index c4eaff6b9..b75eb84b3 100644 --- a/include/etl/unordered_multimap.h +++ b/include/etl/unordered_multimap.h @@ -599,6 +599,7 @@ namespace etl return key_hash_function(key) % number_of_buckets; } +#if ETL_USING_CPP11 //********************************************************************* /// Returns the bucket index for the key. ///\return The bucket index for the key. @@ -608,6 +609,7 @@ namespace etl { return key_hash_function(key) % number_of_buckets; } +#endif //********************************************************************* /// Returns the size of the bucket key. @@ -620,6 +622,7 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } +#if ETL_USING_CPP11 //********************************************************************* /// Returns the size of the bucket key. ///\return The bucket size of the bucket key. @@ -631,6 +634,7 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } +#endif //********************************************************************* /// Returns the maximum number of the buckets the container can hold. @@ -892,6 +896,7 @@ namespace etl return n; } +#if ETL_USING_CPP11 //********************************************************************* /// Erases an element. ///\param key The key to erase. @@ -926,6 +931,7 @@ namespace etl return n; } +#endif //********************************************************************* /// Erases an element. @@ -1044,6 +1050,7 @@ namespace etl return n; } +#if ETL_USING_CPP11 //********************************************************************* /// Counts an element. ///\param key The key to search for. @@ -1070,6 +1077,7 @@ namespace etl return n; } +#endif //********************************************************************* /// Finds an element. @@ -1139,6 +1147,7 @@ namespace etl return end(); } +#if ETL_USING_CPP11 //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1173,7 +1182,9 @@ namespace etl return end(); } +#endif +#if ETL_USING_CPP11 //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1208,6 +1219,7 @@ namespace etl return end(); } +#endif //********************************************************************* /// Returns a range containing all elements with key key in the container. @@ -1261,6 +1273,7 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#if ETL_USING_CPP11 //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1287,7 +1300,9 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#endif +#if ETL_USING_CPP11 //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1314,6 +1329,7 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#endif //************************************************************************* /// Gets the size of the unordered_multimap. diff --git a/include/etl/unordered_multiset.h b/include/etl/unordered_multiset.h index ea2fba385..9a91a16e3 100644 --- a/include/etl/unordered_multiset.h +++ b/include/etl/unordered_multiset.h @@ -590,6 +590,7 @@ namespace etl return key_hash_function(key) % number_of_buckets; } +#if ETL_USING_CPP11 //********************************************************************* /// Returns the bucket index for the key. ///\return The bucket index for the key. @@ -599,6 +600,7 @@ namespace etl { return key_hash_function(key) % number_of_buckets; } +#endif //********************************************************************* /// Returns the size of the bucket key. @@ -611,6 +613,7 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } +#if ETL_USING_CPP11 //********************************************************************* /// Returns the size of the bucket key. ///\return The bucket size of the bucket key. @@ -622,6 +625,7 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } +#endif //********************************************************************* /// Returns the maximum number of the buckets the container can hold. @@ -736,6 +740,7 @@ namespace etl return result; } +#if ETL_USING_CPP11 //********************************************************************* /// Inserts a value to the unordered_multiset. /// If asserts or exceptions are enabled, emits unordered_multiset_full if the unordered_multiset is already full. @@ -806,6 +811,7 @@ namespace etl return result; } +#endif #if ETL_USING_CPP11 //********************************************************************* @@ -941,6 +947,7 @@ namespace etl return n; } +#if ETL_USING_CPP11 //********************************************************************* /// Erases an element. ///\param key The key to erase. @@ -975,6 +982,7 @@ namespace etl return n; } +#endif //********************************************************************* /// Erases an element. @@ -1093,6 +1101,7 @@ namespace etl return n; } +#if ETL_USING_CPP11 //********************************************************************* /// Counts an element. ///\param key The key to search for. @@ -1119,6 +1128,7 @@ namespace etl return n; } +#endif //********************************************************************* /// Finds an element. @@ -1188,6 +1198,7 @@ namespace etl return end(); } +#if ETL_USING_CPP11 //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1222,7 +1233,9 @@ namespace etl return end(); } +#endif +#if ETL_USING_CPP11 //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1257,6 +1270,7 @@ namespace etl return end(); } +#endif //********************************************************************* /// Returns a range containing all elements with key key in the container. diff --git a/include/etl/unordered_set.h b/include/etl/unordered_set.h index ec983b3a1..fd365102b 100644 --- a/include/etl/unordered_set.h +++ b/include/etl/unordered_set.h @@ -591,6 +591,7 @@ namespace etl return key_hash_function(key) % number_of_buckets; } +#if ETL_USING_CPP11 //********************************************************************* /// Returns the bucket index for the key. ///\return The bucket index for the key. @@ -600,6 +601,7 @@ namespace etl { return key_hash_function(key) % number_of_buckets; } +#endif //********************************************************************* /// Returns the size of the bucket key. @@ -612,6 +614,7 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } +#if ETL_USING_CPP11 //********************************************************************* /// Returns the size of the bucket key. ///\return The bucket size of the bucket key. @@ -623,6 +626,7 @@ namespace etl return etl::distance(pbuckets[index].begin(), pbuckets[index].end()); } +#endif //********************************************************************* /// Returns the maximum number of the buckets the container can hold. @@ -754,6 +758,7 @@ namespace etl return result; } +#if ETL_USING_CPP11 //********************************************************************* /// Inserts a value to the unordered_set. /// If asserts or exceptions are enabled, emits unordered_set_full if the unordered_set is already full. @@ -841,6 +846,7 @@ namespace etl return result; } +#endif #if ETL_USING_CPP11 //********************************************************************* @@ -1004,6 +1010,7 @@ namespace etl return n; } +#if ETL_USING_CPP11 //********************************************************************* /// Erases an element. ///\param key The key to erase. @@ -1036,6 +1043,7 @@ namespace etl return n; } +#endif //********************************************************************* /// Erases an element. @@ -1138,6 +1146,7 @@ namespace etl return (find(key) == end()) ? 0 : 1; } +#if ETL_USING_CPP11 //********************************************************************* /// Counts an element. ///\param key The key to search for. @@ -1148,6 +1157,7 @@ namespace etl { return (find(key) == end()) ? 0 : 1; } +#endif //********************************************************************* /// Finds an element. @@ -1217,6 +1227,7 @@ namespace etl return end(); } +#if ETL_USING_CPP11 //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1251,7 +1262,9 @@ namespace etl return end(); } +#endif +#if ETL_USING_CPP11 //********************************************************************* /// Finds an element. ///\param key The key to search for. @@ -1286,6 +1299,7 @@ namespace etl return end(); } +#endif //********************************************************************* /// Returns a range containing all elements with key 'key' in the container. @@ -1329,6 +1343,7 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#if ETL_USING_CPP11 //********************************************************************* /// Returns a range containing all elements with key 'key' in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1350,7 +1365,9 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#endif +#if ETL_USING_CPP11 //********************************************************************* /// Returns a range containing all elements with key 'key' in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1372,6 +1389,7 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#endif //************************************************************************* /// Gets the size of the unordered_set. From 0a41693271a2d775753c7eea66e30685ff1775e8 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 11 Nov 2024 13:20:47 +0000 Subject: [PATCH 17/55] Fixed syntax issue between GCC and Clang/Visual Studio --- include/etl/parameter_pack.h | 14 +++++++------- test/test_parameter_pack.cpp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/etl/parameter_pack.h b/include/etl/parameter_pack.h index a5e5ee7f2..270d0ff75 100644 --- a/include/etl/parameter_pack.h +++ b/include/etl/parameter_pack.h @@ -134,17 +134,17 @@ namespace etl inline constexpr size_t parameter_pack_v = etl::parameter_pack::template index_of_type::value; #endif -#if ETL_USING_CPP17 && (!ETL_USING_GCC_COMPILER || (__GNUC__ > 7)) - //*********************************** - template - template - constexpr size_t parameter_pack::template index_of_type::value; -#else +//#if ETL_USING_CPP17 && !ETL_USING_GCC_COMPILER +// //*********************************** +// template +// template +// constexpr size_t parameter_pack::template index_of_type::value; +//#else //*********************************** template template constexpr size_t parameter_pack::index_of_type::value; -#endif +//#endif } #endif #endif diff --git a/test/test_parameter_pack.cpp b/test/test_parameter_pack.cpp index 4c8adf8b6..83aa08d66 100644 --- a/test/test_parameter_pack.cpp +++ b/test/test_parameter_pack.cpp @@ -34,7 +34,7 @@ namespace { using Pack = etl::parameter_pack; - SUITE(test_type_lookup) + SUITE(test_parameter_pack) { //************************************************************************* TEST(test_index_of_type) From 223f1cee6e70b11831508fa8b64fc5ea97e938c4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 11 Nov 2024 13:20:47 +0000 Subject: [PATCH 18/55] Fixed syntax issue between GCC and Clang/Visual Studio --- include/etl/parameter_pack.h | 16 ++++++++-------- support/Release notes.txt | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/include/etl/parameter_pack.h b/include/etl/parameter_pack.h index 270d0ff75..cc8edd4d0 100644 --- a/include/etl/parameter_pack.h +++ b/include/etl/parameter_pack.h @@ -134,17 +134,17 @@ namespace etl inline constexpr size_t parameter_pack_v = etl::parameter_pack::template index_of_type::value; #endif -//#if ETL_USING_CPP17 && !ETL_USING_GCC_COMPILER -// //*********************************** -// template -// template -// constexpr size_t parameter_pack::template index_of_type::value; -//#else +#if ETL_USING_CPP17 && !ETL_USING_GCC_COMPILER + //*********************************** + template + template + constexpr size_t parameter_pack::template index_of_type::value; +#else //*********************************** template template constexpr size_t parameter_pack::index_of_type::value; -//#endif -} #endif +} #endif +#endif \ No newline at end of file diff --git a/support/Release notes.txt b/support/Release notes.txt index a4240486a..476ff0e13 100644 --- a/support/Release notes.txt +++ b/support/Release notes.txt @@ -14,6 +14,7 @@ Fixes: #956 Fix build error (etl::circular_buffer) #957 Support heterogenous lookup for maps #959 Treat bitset with size_type +#972 template not allowed warning in parameter pack Pull Requests: #947 Remove unused git submodule config From 21ab37f773fff5269702e6a0ad60b2af100d1d10 Mon Sep 17 00:00:00 2001 From: mike919192 <91038685+mike919192@users.noreply.github.com> Date: Wed, 13 Nov 2024 16:26:04 -0500 Subject: [PATCH 19/55] Add at method to span (#975) * Update README.md * Add at method to span --------- Co-authored-by: John Wellbelove --- include/etl/span.h | 40 +++++++++++++++++++++++++++++++ test/test_span_dynamic_extent.cpp | 16 +++++++++++++ test/test_span_fixed_extent.cpp | 16 +++++++++++++ 3 files changed, 72 insertions(+) diff --git a/include/etl/span.h b/include/etl/span.h index f1077ea77..7aa11c960 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -272,6 +272,26 @@ namespace etl { pbegin = other.pbegin; return *this; + } + + //************************************************************************* + /// Returns a reference to the value at index 'i'. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 reference at(size_t i) + { + ETL_ASSERT(i < size(), ETL_ERROR(array_out_of_range)); + + return pbegin[i]; + } + + //************************************************************************* + /// Returns a const reference to the value at index 'i'. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 const_reference at(size_t i) const + { + ETL_ASSERT(i < size(), ETL_ERROR(array_out_of_range)); + + return pbegin[i]; } //************************************************************************* @@ -614,6 +634,26 @@ namespace etl return *this; } + //************************************************************************* + /// Returns a reference to the value at index 'i'. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 reference at(size_t i) + { + ETL_ASSERT(i < size(), ETL_ERROR(array_out_of_range)); + + return pbegin[i]; + } + + //************************************************************************* + /// Returns a const reference to the value at index 'i'. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR14 const_reference at(size_t i) const + { + ETL_ASSERT(i < size(), ETL_ERROR(array_out_of_range)); + + return pbegin[i]; + } + //************************************************************************* /// Returns a reference to the indexed value. //************************************************************************* diff --git a/test/test_span_dynamic_extent.cpp b/test/test_span_dynamic_extent.cpp index 3d7df1ec0..300ee58c5 100644 --- a/test/test_span_dynamic_extent.cpp +++ b/test/test_span_dynamic_extent.cpp @@ -445,6 +445,22 @@ namespace CHECK_EQUAL(etldata.data(), cview.data()); } + //************************************************************************* + TEST(test_at) + { + View view(etldata.begin(), etldata.end()); + CView cview(etldata.begin(), etldata.end()); + + for (size_t i = 0UL; i < etldata.size(); ++i) + { + CHECK_EQUAL(etldata.at(i), view.at(i)); + CHECK_EQUAL(etldata.at(i), cview.at(i)); + } + + CHECK_THROW({ int d = view.at(view.size()); (void)d; }, etl::array_out_of_range); + CHECK_THROW({ int d = cview.at(cview.size()); (void)d; }, etl::array_out_of_range); + } + //************************************************************************* TEST(test_index_operator) { diff --git a/test/test_span_fixed_extent.cpp b/test/test_span_fixed_extent.cpp index 157170a09..2c760783a 100644 --- a/test/test_span_fixed_extent.cpp +++ b/test/test_span_fixed_extent.cpp @@ -433,6 +433,22 @@ namespace CHECK_EQUAL(etldata.data(), cview.data()); } + //************************************************************************* + TEST(test_at) + { + View view(etldata.begin(), etldata.end()); + CView cview(etldata.begin(), etldata.end()); + + for (size_t i = 0UL; i < etldata.size(); ++i) + { + CHECK_EQUAL(etldata.at(i), view.at(i)); + CHECK_EQUAL(etldata.at(i), cview.at(i)); + } + + CHECK_THROW({ int d = view.at(view.size()); (void)d; }, etl::array_out_of_range); + CHECK_THROW({ int d = cview.at(cview.size()); (void)d; }, etl::array_out_of_range); + } + //************************************************************************* TEST(test_index_operator) { From 328a685cee25c99175377d1a87e76d613cd3139f Mon Sep 17 00:00:00 2001 From: David Hebbeker Date: Sun, 24 Nov 2024 16:09:57 +0100 Subject: [PATCH 20/55] Added basic guidelines for contributing code (#976) * Update README.md * Apply instructions for pull requests from Slack to new CONTRIBUTING guideline file. I copied the [message in Slack](https://etlcpp.slack.com/archives/C7SJ45VFB/p1729596737002559) from @jwellbelove into a new file for [contributing guidelines](https://docs.github.com/en/communities/setting-up-your-project-for-healthy-contributions/setting-guidelines-for-repository-contributors). This way a starting point for potential contributors is delivered next to the source code. * Added hint for the starting point for contributing commits. I derived this rule from https://github.com/ETLCPP/etl/issues/802#issuecomment-2323530862 --------- Co-authored-by: John Wellbelove --- CONTRIBUTING.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 000000000..56ce976d6 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,10 @@ +# How to contribute + +If your are considering creating a pull request, please observe the following: + +- If you are adding or modifying a feature, add *new* unit tests that test that feature. +- If you are fixing a bug, add a unit test that *fails* before the bug fix is implemented. +- Do not initiate a pull request until all of the units tests pass. +- Branches should be based on the branch `master`. + +There is a project file for VS2022 for C++14, 17, 20, and bash scripts that run the tests for C++11, 14, 17, 20 under Linux with GCC and Clang. From 05ed5ff77c4703eae39013a09d1662eaed62ebac Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 13 Nov 2024 11:15:01 +0000 Subject: [PATCH 21/55] Change internal constants from all-caps snake case to initial-caps snake case --- include/etl/bip_buffer_spsc_atomic.h | 42 ++++++++--------- include/etl/queue_spsc_atomic.h | 70 ++++++++++++++-------------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/include/etl/bip_buffer_spsc_atomic.h b/include/etl/bip_buffer_spsc_atomic.h index 5333dc68a..f8c0eff15 100644 --- a/include/etl/bip_buffer_spsc_atomic.h +++ b/include/etl/bip_buffer_spsc_atomic.h @@ -86,13 +86,13 @@ namespace etl //*************************************************************************** /// The common base for a bip_buffer_spsc_atomic_base. //*************************************************************************** - template + template class bip_buffer_spsc_atomic_base { public: /// The type used for determining the size of buffer. - typedef typename etl::size_type_lookup::type size_type; + typedef typename etl::size_type_lookup::type size_type; //************************************************************************* /// Returns true if the buffer is empty. @@ -168,7 +168,7 @@ namespace etl //************************************************************************* size_type capacity() const { - return RESERVED; + return Reserved; } //************************************************************************* @@ -176,7 +176,7 @@ namespace etl //************************************************************************* size_type max_size() const { - return RESERVED; + return Reserved; } protected: @@ -188,7 +188,7 @@ namespace etl : read(0) , write(0) , last(0) - , RESERVED(reserved_) + , Reserved(reserved_) { } @@ -341,7 +341,7 @@ namespace etl etl::atomic read; etl::atomic write; etl::atomic last; - const size_type RESERVED; + const size_type Reserved; #if defined(ETL_POLYMORPHIC_SPSC_BIP_BUFFER_ATOMIC) || defined(ETL_POLYMORPHIC_CONTAINERS) public: @@ -361,12 +361,12 @@ namespace etl //*************************************************************************** /// A fixed capacity bipartite buffer. //*************************************************************************** - template - class ibip_buffer_spsc_atomic : public bip_buffer_spsc_atomic_base + template + class ibip_buffer_spsc_atomic : public bip_buffer_spsc_atomic_base { private: - typedef typename etl::bip_buffer_spsc_atomic_base base_t; + typedef typename etl::bip_buffer_spsc_atomic_base base_t; using base_t::reset; using base_t::get_read_reserve; using base_t::apply_read_reserve; @@ -486,15 +486,15 @@ namespace etl /// A fixed capacity bipartite buffer. /// This buffer supports concurrent access by one producer and one consumer. /// \tparam T The type this buffer should support. - /// \tparam SIZE The maximum capacity of the buffer. - /// \tparam MEMORY_MODEL The memory model for the buffer. Determines the type of the internal counter variables. + /// \tparam Size The maximum capacity of the buffer. + /// \tparam Memory_Model The memory model for the buffer. Determines the type of the internal counter variables. //*************************************************************************** - template - class bip_buffer_spsc_atomic : public ibip_buffer_spsc_atomic + template + class bip_buffer_spsc_atomic : public ibip_buffer_spsc_atomic { private: - typedef typename etl::ibip_buffer_spsc_atomic base_t; + typedef typename etl::ibip_buffer_spsc_atomic base_t; public: @@ -502,19 +502,19 @@ namespace etl private: - static ETL_CONSTANT size_type RESERVED_SIZE = size_type(SIZE); + static ETL_CONSTANT size_type Reserved_Size = size_type(Size); public: - ETL_STATIC_ASSERT((SIZE <= (etl::integral_limits::max)), "Size too large for memory model"); + ETL_STATIC_ASSERT((Size <= (etl::integral_limits::max)), "Size too large for memory model"); - static ETL_CONSTANT size_type MAX_SIZE = size_type(SIZE); + static ETL_CONSTANT size_type MAX_SIZE = size_type(Size); //************************************************************************* /// Default constructor. //************************************************************************* bip_buffer_spsc_atomic() - : base_t(reinterpret_cast(buffer.raw), RESERVED_SIZE) + : base_t(reinterpret_cast(buffer.raw), Reserved_Size) { } @@ -529,11 +529,11 @@ namespace etl private: /// The uninitialised buffer of T used in the bip_buffer_spsc. - etl::uninitialized_buffer_of buffer; + etl::uninitialized_buffer_of buffer; }; - template - ETL_CONSTANT typename bip_buffer_spsc_atomic::size_type bip_buffer_spsc_atomic::RESERVED_SIZE; + template + ETL_CONSTANT typename bip_buffer_spsc_atomic::size_type bip_buffer_spsc_atomic::Reserved_Size; } #endif /* ETL_HAS_ATOMIC && ETL_USING_CPP11 */ diff --git a/include/etl/queue_spsc_atomic.h b/include/etl/queue_spsc_atomic.h index d06dce2d9..d79299193 100644 --- a/include/etl/queue_spsc_atomic.h +++ b/include/etl/queue_spsc_atomic.h @@ -47,13 +47,13 @@ SOFTWARE. namespace etl { - template + template class queue_spsc_atomic_base { public: /// The type used for determining the size of queue. - typedef typename etl::size_type_lookup::type size_type; + typedef typename etl::size_type_lookup::type size_type; //************************************************************************* /// Is the queue empty? @@ -72,7 +72,7 @@ namespace etl //************************************************************************* bool full() const { - size_type next_index = get_next_index(write.load(etl::memory_order_acquire), RESERVED); + size_type next_index = get_next_index(write.load(etl::memory_order_acquire), Reserved); return (next_index == read.load(etl::memory_order_acquire)); } @@ -94,7 +94,7 @@ namespace etl } else { - n = RESERVED - read_index + write_index; + n = Reserved - read_index + write_index; } return n; @@ -106,7 +106,7 @@ namespace etl //************************************************************************* size_type available() const { - return RESERVED - size() - 1; + return Reserved - size() - 1; } //************************************************************************* @@ -114,7 +114,7 @@ namespace etl //************************************************************************* size_type capacity() const { - return RESERVED - 1; + return Reserved - 1; } //************************************************************************* @@ -122,7 +122,7 @@ namespace etl //************************************************************************* size_type max_size() const { - return RESERVED - 1; + return Reserved - 1; } protected: @@ -130,7 +130,7 @@ namespace etl queue_spsc_atomic_base(size_type reserved_) : write(0), read(0), - RESERVED(reserved_) + Reserved(reserved_) { } @@ -151,7 +151,7 @@ namespace etl etl::atomic write; ///< Where to input new data. etl::atomic read; ///< Where to get the oldest data. - const size_type RESERVED; ///< The maximum number of items in the queue. + const size_type Reserved; ///< The maximum number of items in the queue. private: @@ -182,12 +182,12 @@ namespace etl /// This queue supports concurrent access by one producer and one consumer. /// \tparam T The type of value that the queue_spsc_atomic holds. //*************************************************************************** - template - class iqueue_spsc_atomic : public queue_spsc_atomic_base + template + class iqueue_spsc_atomic : public queue_spsc_atomic_base { private: - typedef typename etl::queue_spsc_atomic_base base_t; + typedef typename etl::queue_spsc_atomic_base base_t; public: @@ -201,7 +201,7 @@ namespace etl using base_t::write; using base_t::read; - using base_t::RESERVED; + using base_t::Reserved; using base_t::get_next_index; //************************************************************************* @@ -210,7 +210,7 @@ namespace etl bool push(const_reference value) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -232,7 +232,7 @@ namespace etl bool push(rvalue_reference value) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -257,7 +257,7 @@ namespace etl bool emplace(Args&&... args) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -279,7 +279,7 @@ namespace etl bool emplace() { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -302,7 +302,7 @@ namespace etl bool emplace(const T1& value1) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -325,7 +325,7 @@ namespace etl bool emplace(const T1& value1, const T2& value2) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -348,7 +348,7 @@ namespace etl bool emplace(const T1& value1, const T2& value2, const T3& value3) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -371,7 +371,7 @@ namespace etl bool emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { size_type write_index = write.load(etl::memory_order_relaxed); - size_type next_index = get_next_index(write_index, RESERVED); + size_type next_index = get_next_index(write_index, Reserved); if (next_index != read.load(etl::memory_order_acquire)) { @@ -418,7 +418,7 @@ namespace etl return false; } - size_type next_index = get_next_index(read_index, RESERVED); + size_type next_index = get_next_index(read_index, Reserved); #if ETL_USING_CPP11 && ETL_NOT_USING_STLPORT && !defined(ETL_QUEUE_LOCKABLE_FORCE_CPP03_IMPLEMENTATION) value = etl::move(p_buffer[read_index]); @@ -446,7 +446,7 @@ namespace etl return false; } - size_type next_index = get_next_index(read_index, RESERVED); + size_type next_index = get_next_index(read_index, Reserved); p_buffer[read_index].~T(); @@ -518,15 +518,15 @@ namespace etl /// A fixed capacity spsc queue. /// This queue supports concurrent access by one producer and one consumer. /// \tparam T The type this queue should support. - /// \tparam SIZE The maximum capacity of the queue. - /// \tparam MEMORY_MODEL The memory model for the queue. Determines the type of the internal counter variables. + /// \tparam Size The maximum capacity of the queue. + /// \tparam Memory_Model The memory model for the queue. Determines the type of the internal counter variables. //*************************************************************************** - template - class queue_spsc_atomic : public iqueue_spsc_atomic + template + class queue_spsc_atomic : public iqueue_spsc_atomic { private: - typedef typename etl::iqueue_spsc_atomic base_t; + typedef typename etl::iqueue_spsc_atomic base_t; public: @@ -534,19 +534,19 @@ namespace etl private: - static ETL_CONSTANT size_type RESERVED_SIZE = size_type(SIZE + 1); + static ETL_CONSTANT size_type Reserved_Size = size_type(Size + 1); public: - ETL_STATIC_ASSERT((SIZE <= (etl::integral_limits::max - 1)), "Size too large for memory model"); + ETL_STATIC_ASSERT((Size <= (etl::integral_limits::max - 1)), "Size too large for memory model"); - static ETL_CONSTANT size_type MAX_SIZE = size_type(SIZE); + static ETL_CONSTANT size_type MAX_SIZE = size_type(Size); //************************************************************************* /// Default constructor. //************************************************************************* queue_spsc_atomic() - : base_t(reinterpret_cast(&buffer[0]), RESERVED_SIZE) + : base_t(reinterpret_cast(&buffer[0]), Reserved_Size) { } @@ -561,11 +561,11 @@ namespace etl private: /// The uninitialised buffer of T used in the queue_spsc. - typename etl::aligned_storage::value>::type buffer[RESERVED_SIZE]; + typename etl::aligned_storage::value>::type buffer[Reserved_Size]; }; - template - ETL_CONSTANT typename queue_spsc_atomic::size_type queue_spsc_atomic::MAX_SIZE; + template + ETL_CONSTANT typename queue_spsc_atomic::size_type queue_spsc_atomic::MAX_SIZE; } #endif From 12b46728abdce02a47f83300d91e6098b2bd4df8 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 16 Nov 2024 12:37:29 +0000 Subject: [PATCH 22/55] Added string_view API. Created common implementations for member algorithms. --- include/etl/basic_string.h | 807 +++++++++++++++++++++++++++---------- 1 file changed, 594 insertions(+), 213 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 1371e80a6..1bf290022 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -52,6 +52,10 @@ SOFTWARE. #include #include +#if ETL_USING_STL && ETL_USING_CPP17 + #include +#endif + #include "private/minmax_push.h" //***************************************************************************** @@ -60,6 +64,13 @@ SOFTWARE. ///\ingroup containers //***************************************************************************** +// Forward declaration of string_view +namespace etl +{ + template + class basic_string_view; +} + namespace etl { //*************************************************************************** @@ -635,27 +646,7 @@ namespace etl //********************************************************************* void assign(const etl::ibasic_string& other) { - assign(other.begin(), other.end()); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - if (other.is_truncated()) - { - set_truncated(true); - -#if ETL_HAS_ERROR_ON_STRING_TRUNCATION - ETL_ASSERT_FAIL(ETL_ERROR(string_truncation)); -#endif - } -#endif - -#if ETL_HAS_STRING_CLEAR_AFTER_USE - if (other.is_secure()) - { - set_secure(); - } -#endif - - cleanup(); + assign_impl(other.begin(), other.end(), other.is_truncated(), other.is_secure()); } //********************************************************************* @@ -674,25 +665,20 @@ namespace etl ETL_ASSERT(subposition <= other.size(), ETL_ERROR(string_out_of_bounds)); - assign(other.begin() + subposition, sublength); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - if (other.is_truncated()) - { - this->set_truncated(true); - -#if ETL_HAS_ERROR_ON_STRING_TRUNCATION - ETL_ASSERT_FAIL(ETL_ERROR(string_truncation)); -#endif - } -#endif + assign_impl(other.begin() + subposition, other.begin() + subposition + sublength, other.is_truncated(), other.is_secure()); + } -#if ETL_HAS_STRING_CLEAR_AFTER_USE - if (other.is_secure()) - { - set_secure(); - } -#endif + //********************************************************************* + /// Assigns values to the string. + /// If asserts or exceptions are enabled, emits string_iterator if the iterators are reversed. + /// Truncates if the string does not have enough free space. + ///\param first The iterator to the first element. + ///\param last The iterator to the last element + 1. + //********************************************************************* + template + void assign(TIterator first, TIterator last) + { + assign_impl(first, last, false, false); } //********************************************************************* @@ -702,22 +688,7 @@ namespace etl //********************************************************************* void assign(const_pointer other) { - initialise(); - - while ((*other != 0) && (current_size < CAPACITY)) - { - p_buffer[current_size++] = *other++; - } - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - set_truncated(*other != 0); - -#if ETL_HAS_ERROR_ON_STRING_TRUNCATION - ETL_ASSERT(flags.test() == false, ETL_ERROR(string_truncation)); -#endif -#endif - - p_buffer[current_size] = 0; + assign(other, other + etl::strlen(other)); } //********************************************************************* @@ -728,56 +699,28 @@ namespace etl //********************************************************************* void assign(const_pointer other, size_type length_) { - initialise(); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - set_truncated(length_ > CAPACITY); - -#if ETL_HAS_ERROR_ON_STRING_TRUNCATION - ETL_ASSERT(flags.test() == false, ETL_ERROR(string_truncation)); -#endif -#endif - - length_ = etl::min(length_, CAPACITY); - - etl::copy_n(other, length_, begin()); - - current_size = length_; - p_buffer[current_size] = 0; + assign(other, other + length_); } //********************************************************************* - /// Assigns values to the string. - /// If asserts or exceptions are enabled, emits string_iterator if the iterators are reversed. - /// Truncates if the string does not have enough free space. - ///\param first The iterator to the first element. - ///\param last The iterator to the last element + 1. + /// Assigns values to the string from a view. //********************************************************************* - template - void assign(TIterator first, TIterator last) + template + void assign(const etl::basic_string_view& view) { -#if ETL_IS_DEBUG_BUILD - difference_type d = etl::distance(first, last); - ETL_ASSERT(d >= 0, ETL_ERROR(string_iterator)); -#endif - - initialise(); - - while ((first != last) && (current_size != CAPACITY)) - { - p_buffer[current_size++] = *first++; - } - - p_buffer[current_size] = 0; - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - set_truncated(first != last); + assign(view.begin(), view.end()); + } -#if ETL_HAS_ERROR_ON_STRING_TRUNCATION - ETL_ASSERT(flags.test() == false, ETL_ERROR(string_truncation)); -#endif -#endif +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Assigns values to the string from a view. + //********************************************************************* + template + void assign(const std::basic_string_view& view) + { + assign(view.begin(), view.end()); } +#endif //********************************************************************* /// Assigns values to the string. @@ -929,6 +872,30 @@ namespace etl return *this; } + //********************************************************************* + /// Appends to the string. + ///\param view An etl::string_view. + //********************************************************************* + template + ibasic_string& append(const etl::basic_string_view& view) + { + insert(end(), view.begin(), view.end()); + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Appends to the string. + ///\param view A std::string_view. + //********************************************************************* + template + ibasic_string& append(const std::basic_string_view& view) + { + insert(end(), view.begin(), view.end()); + return *this; + } +#endif + //********************************************************************* /// Inserts a value to the string. ///\param position The position to insert before. @@ -1159,6 +1126,32 @@ namespace etl return position_; } + //********************************************************************* + /// Inserts a view to the string. + /// If asserts or exceptions are enabled, emits string_full if the string does not have enough free space. + ///\param position The position to insert before. + ///\param view The view element to add. + //********************************************************************* + template + iterator insert(const_iterator position, const etl::basic_string_view& view) + { + return insert(position, view.begin(), view.end()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Inserts a view to the string. + /// If asserts or exceptions are enabled, emits string_full if the string does not have enough free space. + ///\param position The position to insert before. + ///\param view The view element to add. + //********************************************************************* + template + iterator insert(const_iterator position, const std::basic_string_view& view) + { + return insert(position, view.begin(), view.end()); + } +#endif + //********************************************************************* /// Inserts a string at the specified position. ///\param position The position to insert before. @@ -1374,22 +1367,32 @@ namespace etl //********************************************************************* size_type find(const ibasic_string& str, size_type pos = 0) const { - if ((pos + str.size()) > size()) - { - return npos; - } + return find_impl(str.begin(), str.end(), str.size(), pos); + } - const_iterator iposition = etl::search(begin() + pos, end(), str.begin(), str.end()); + //********************************************************************* + /// Find content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type find(const etl::basic_string_view& view, size_type pos = 0) const + { + return find_impl(view.begin(), view.end(), view.size(), pos); + } - if (iposition == end()) - { - return npos; - } - else - { - return etl::distance(begin(), iposition); - } +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Find content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type find(const std::basic_string_view& view, size_type pos = 0) const + { + return find_impl(view.begin(), view.end(), view.size(), pos); } +#endif //********************************************************************* /// Find content within the string @@ -1398,23 +1401,9 @@ namespace etl //********************************************************************* size_type find(const_pointer s, size_type pos = 0) const { -#if ETL_IS_DEBUG_BUILD - if ((pos + etl::strlen(s)) > size()) - { - return npos; - } -#endif - - const_iterator iposition = etl::search(begin() + pos, end(), s, s + etl::strlen(s)); + size_t sz = etl::strlen(s); - if (iposition == end()) - { - return npos; - } - else - { - return etl::distance(begin(), iposition); - } + return find_impl(s, s + sz, sz, pos); } //********************************************************************* @@ -1425,23 +1414,9 @@ namespace etl //********************************************************************* size_type find(const_pointer s, size_type pos, size_type n) const { -#if ETL_IS_DEBUG_BUILD - if ((pos + etl::strlen(s) - n) > size()) - { - return npos; - } -#endif - - const_iterator iposition = etl::search(begin() + pos, end(), s, s + n); + size_t sz = etl::strlen(s); - if (iposition == end()) - { - return npos; - } - else - { - return etl::distance(begin(), iposition); - } + return find_impl(s, s + n, sz, pos); } //********************************************************************* @@ -1470,29 +1445,32 @@ namespace etl //********************************************************************* size_type rfind(const ibasic_string& str, size_type position = npos) const { - if ((str.size()) > size()) - { - return npos; - } - - if (position >= size()) - { - position = size(); - } - - position = size() - position; + return rfind_impl(str.rbegin(), str.rend(), str.size(), position); + } - const_reverse_iterator iposition = etl::search(rbegin() + position, rend(), str.rbegin(), str.rend()); + //********************************************************************* + /// Find content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type rfind(const etl::basic_string_view& view, size_type pos = 0) const + { + return rfind_impl(view.rbegin(), view.rend(), view.size(), pos); + } - if (iposition == rend()) - { - return npos; - } - else - { - return size() - str.size() - etl::distance(rbegin(), iposition); - } +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Find content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type rfind(const std::basic_string_view& view, size_type pos = 0) const + { + return rfind_impl(view.rbegin(), view.rend(), view.size(), pos); } +#endif //********************************************************************* /// Find content within the string @@ -1503,31 +1481,10 @@ namespace etl { size_type len = etl::strlen(s); - if (len > size()) - { - return npos; - } - - if (position >= size()) - { - position = size(); - } - - position = size() - position; - const_reverse_iterator srbegin(s + len); const_reverse_iterator srend(s); - const_reverse_iterator iposition = etl::search(rbegin() + position, rend(), srbegin, srend); - - if (iposition == rend()) - { - return npos; - } - else - { - return size() - len - etl::distance(rbegin(), iposition); - } + return rfind_impl(srbegin, srend, len, position); } //********************************************************************* @@ -1537,31 +1494,10 @@ namespace etl //********************************************************************* size_type rfind(const_pointer s, size_type position, size_type length_) const { - if (length_ > size()) - { - return npos; - } - - if (position >= size()) - { - position = size(); - } - - position = size() - position; - const_reverse_iterator srbegin(s + length_); const_reverse_iterator srend(s); - const_reverse_iterator iposition = etl::search(rbegin() + position, rend(), srbegin, srend); - - if (iposition == rend()) - { - return npos; - } - else - { - return size() - length_ - etl::distance(rbegin(), iposition); - } + return rfind_impl(srbegin, srend, length_, position); } //********************************************************************* @@ -1613,16 +1549,64 @@ namespace etl } //********************************************************************* - /// Replace characters from 'first' to one before 'last' with 'str'. - ///\param first The position to start from. - ///\param last The one after the position to end at. - ///\param str The string to replace it with. + /// Replace 'length' characters from 'position' with 'view'. + ///\param position The position to start from. + ///\param length The number of characters to replace. + ///\param view The string to replace it with. + //********************************************************************* + template + ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + + // Limit the length. + length_ = etl::min(length_, size() - position); + + // Erase the bit we want to replace. + erase(position, length_); + + // Insert the new stuff. + insert(position, view); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Replace 'length' characters from 'position' with 'view'. + ///\param position The position to start from. + ///\param length The number of characters to replace. + ///\param view The string to replace it with. + //********************************************************************* + template + ibasic_string& replace(size_type position, size_type length_, const std::basic_string_view& view) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + + // Limit the length. + length_ = etl::min(length_, size() - position); + + // Erase the bit we want to replace. + erase(position, length_); + + // Insert the new stuff. + insert(position, view); + + return *this; + } +#endif + + //********************************************************************* + /// Replace characters from 'first' to one before 'last' with 'str'. + ///\param first The position to start from. + ///\param last The one after the position to end at. + ///\param str The string to replace it with. //********************************************************************* ibasic_string& replace(const_iterator first, const_iterator last, const ibasic_string& str) { // Quick hack, as iterators are pointers. iterator first_ = to_iterator(first); - iterator last_ = to_iterator(last); + iterator last_ = to_iterator(last); // Erase the bit we want to replace. erase(first_, last_); @@ -1644,6 +1628,52 @@ namespace etl return *this; } + //********************************************************************* + /// Replace characters from 'first' to one before 'last' with 'view'. + ///\param first The position to start from. + ///\param last The one after the position to end at. + ///\param view The string view to replace it with. + //********************************************************************* + template + ibasic_string& replace(const_iterator first, const_iterator last, const etl::basic_string_view& view) + { + // Quick hack, as iterators are pointers. + iterator first_ = to_iterator(first); + iterator last_ = to_iterator(last); + + // Erase the bit we want to replace. + erase(first_, last_); + + // Insert the new stuff. + insert(first_, view.begin(), view.end()); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Replace characters from 'first' to one before 'last' with 'view'. + ///\param first The position to start from. + ///\param last The one after the position to end at. + ///\param view The string view to replace it with. + //********************************************************************* + template + ibasic_string& replace(const_iterator first, const_iterator last, const std::basic_string_view& view) + { + // Quick hack, as iterators are pointers. + iterator first_ = to_iterator(first); + iterator last_ = to_iterator(last); + + // Erase the bit we want to replace. + erase(first_, last_); + + // Insert the new stuff. + insert(first_, view.begin(), view.end()); + + return *this; + } +#endif + //********************************************************************* /// Replace characters from 'position' of 'length' with 'str' from 'subposition' of 'sublength'. //********************************************************************* @@ -1653,7 +1683,7 @@ namespace etl ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); // Limit the lengths. - length_ = etl::min(length_, size() - position); + length_ = etl::min(length_, size() - position); sublength = etl::min(sublength, str.size() - subposition); // Erase the bit we want to replace. @@ -1676,6 +1706,52 @@ namespace etl return *this; } + //********************************************************************* + /// Replace characters from 'position' of 'length' with 'view' from 'subposition' of 'sublength'. + //********************************************************************* + template + ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); + + // Limit the lengths. + length_ = etl::min(length_, size() - position); + sublength = etl::min(sublength, view.size() - subposition); + + // Erase the bit we want to replace. + erase(position, length_); + + // Insert the new stuff. + insert(position, view, subposition, sublength); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Replace characters from 'position' of 'length' with 'view' from 'subposition' of 'sublength'. + //********************************************************************* + template + ibasic_string& replace(size_type position, size_type length_, const std::basic_string_view& view, size_type subposition, size_type sublength) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); + + // Limit the lengths. + length_ = etl::min(length_, size() - position); + sublength = etl::min(sublength, view.size() - subposition); + + // Erase the bit we want to replace. + erase(position, length_); + + // Insert the new stuff. + insert(position, view, subposition, sublength); + + return *this; + } +#endif + //********************************************************************* /// Replace characters from 'position' of 'length' with pointed to string. //********************************************************************* @@ -1817,6 +1893,32 @@ namespace etl str.p_buffer + str.size()); } + //************************************************************************* + /// Compare with etl::basic_string_view. + //************************************************************************* + template + int compare(const etl::basic_string_view& view) const + { + return compare(p_buffer, + p_buffer + view.size(), + view.data(), + view.size()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Compare with std::basic_string_view. + //************************************************************************* + template + int compare(const std::basic_string_view& view) const + { + return compare(p_buffer, + p_buffer + view.size(), + view.data(), + view.size()); + } +#endif + //************************************************************************* /// Compare position / length with string. //************************************************************************* @@ -1833,6 +1935,32 @@ namespace etl str.p_buffer + str.size()); } + //************************************************************************* + /// Compare position / length with etl::basic_string_view. + //************************************************************************* + template + int compare(size_type position, size_type length_, const etl::basic_string_view& view) const + { + return compare(p_buffer + position, + p_buffer + position + length_, + view.p_buffer, + view.p_buffer + view.size()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Compare position / length with std::basic_string_view. + //************************************************************************* + template + int compare(size_type position, size_type length_, const std::basic_string_view& view) const + { + return compare(p_buffer + position, + p_buffer + position + length_, + view.p_buffer, + view.p_buffer + view.size()); + } +#endif + //************************************************************************* /// Compare position / length with string / subposition / sublength. //************************************************************************* @@ -1851,6 +1979,46 @@ namespace etl str.p_buffer + subposition + sublength); } + //************************************************************************* + /// Compare position / length with etl::basic_string_view. / subposition / sublength. + //************************************************************************* + template + int compare(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) const + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); + + // Limit the lengths. + length_ = etl::min(length_, size() - position); + sublength = etl::min(sublength, view.size() - subposition); + + return compare(p_buffer + position, + p_buffer + position + length_, + view.p_buffer + subposition, + view.p_buffer + subposition + sublength); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Compare position / length with std::basic_string_view. / subposition / sublength. + //************************************************************************* + template + int compare(size_type position, size_type length_, const std::basic_string_view& view, size_type subposition, size_type sublength) const + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); + + // Limit the lengths. + length_ = etl::min(length_, size() - position); + sublength = etl::min(sublength, view.size() - subposition); + + return compare(p_buffer + position, + p_buffer + position + length_, + view.p_buffer + subposition, + view.p_buffer + subposition + sublength); + } +#endif + //************************************************************************* /// Compare with C string //************************************************************************* @@ -1904,6 +2072,30 @@ namespace etl return find_first_of(s, position, etl::strlen(s)); } + //********************************************************************* + /// Find first of any of content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const + { + return find_first_of(view.data(), position, view.size()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Find first of any of content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type find_first_of(const std::basic_string_view& view, size_type position = 0) const + { + return find_first_of(view.data(), position, view.size()); + } +#endif + //********************************************************************* /// Find first of any of content within the string ///\param s Pointer to the content to find @@ -1970,6 +2162,30 @@ namespace etl return find_last_of(s, position, etl::strlen(s)); } + //********************************************************************* + /// Find last of any of content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type find_last_of(const etl::basic_string_view& view, size_type position = 0) const + { + return find_last_of(view.data(), position, view.size()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Find last of any of content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type find_last_of(const std::basic_string_view& view, size_type position = 0) const + { + return find_last_of(view.data(), position, view.size()); + } +#endif + //********************************************************************* /// Find last of any of content within the string ///\param s Pointer to the content to find @@ -2054,6 +2270,30 @@ namespace etl return find_first_not_of(s, position, etl::strlen(s)); } + //********************************************************************* + /// Find first not of any of content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const + { + return find_first_not_of(view.data(), position, view.size()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Find first not of any of content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type find_first_not_of(const std::basic_string_view& view, size_type position = 0) const + { + return find_first_not_of(view.data(), position, view.size()); + } +#endif + //********************************************************************* /// Find first not of any of content within the string ///\param s Pointer to the content to not find @@ -2127,6 +2367,30 @@ namespace etl return find_last_not_of(s, position, etl::strlen(s)); } + //********************************************************************* + /// Find last not of any of content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type find_last_not_of(const etl::basic_string_view& view, size_type position = 0) const + { + return find_last_not_of(view.data(), position, view.size()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Find last not of any of content within the string + ///\param view The content to find + ///\param pos The position to start searching from. + //********************************************************************* + template + size_type find_last_not_of(const std::basic_string_view& view, size_type position = 0) const + { + return find_last_not_of(view.data(), position, view.size()); + } +#endif + //********************************************************************* /// Find last not of any of content within the string ///\param s The pointer to the content to find @@ -2229,6 +2493,30 @@ namespace etl return *this; } + //************************************************************************* + /// += operator. + //************************************************************************* + template + ibasic_string& operator += (const etl::basic_string_view& rhs) + { + append(rhs); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// += operator. + //************************************************************************* + template + ibasic_string& operator += (const std::basic_string_view& rhs) + { + append(rhs); + + return *this; + } +#endif + //************************************************************************* /// += operator. //************************************************************************* @@ -2407,6 +2695,99 @@ namespace etl { return const_cast(itr); } + + private: + + //********************************************************************* + /// Common implementation for 'assign'. + //********************************************************************* + template + void assign_impl(TIterator first, TIterator last, bool truncated, bool secure) + { +#if ETL_IS_DEBUG_BUILD + difference_type d = etl::distance(first, last); + ETL_ASSERT(d >= 0, ETL_ERROR(string_iterator)); +#endif + + initialise(); + + while ((first != last) && (current_size != CAPACITY)) + { + p_buffer[current_size++] = *first++; + } + + p_buffer[current_size] = 0; + +#if ETL_HAS_STRING_TRUNCATION_CHECKS + set_truncated((first != last) || truncated); + +#if ETL_HAS_ERROR_ON_STRING_TRUNCATION + ETL_ASSERT(flags.test() == false, ETL_ERROR(string_truncation)); +#endif +#endif + +#if ETL_HAS_STRING_CLEAR_AFTER_USE + if (secure) + { + set_secure(); + } +#endif + + cleanup(); + } + + //************************************************************************* + /// Common implementation for 'find'. + //************************************************************************* + template + size_type find_impl(TIterator first, TIterator last, size_type sz, size_type pos = 0) const + { + if ((pos + sz) > size()) + { + return npos; + } + + const_iterator iposition = etl::search(begin() + pos, end(), first, last); + + if (iposition == end()) + { + return npos; + } + else + { + return etl::distance(begin(), iposition); + } + } + + //************************************************************************* + /// Common implementation for 'rfind'. + //************************************************************************* + template + size_type rfind_impl(TIterator rfirst, TIterator rlast, size_type sz, size_type pos = 0) const + { + if (sz > size()) + { + return npos; + } + + if (pos >= size()) + { + pos = size(); + } + + pos = size() - pos; + + const_reverse_iterator iposition = etl::search(rbegin() + pos, rend(), rfirst, rlast); + + if (iposition == rend()) + { + return npos; + } + else + { + return size() - sz - etl::distance(rbegin(), iposition); + } + } }; //*************************************************************************** From 08ab27a90a52557fb02b86efb025db8718ec3a17 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 24 Nov 2024 15:33:21 +0000 Subject: [PATCH 23/55] Added CONTRIBUTING.md to the VS2022 project files. --- test/vs2022/etl.vcxproj | 1 + test/vs2022/etl.vcxproj.filters | 3 +++ 2 files changed, 4 insertions(+) diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index 7506cfa14..daac6aeae 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -9031,6 +9031,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 2da095b94..8344c20b1 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -3541,6 +3541,9 @@ Tests\Scripts + + Resource Files + From a87498e125e21585b7a9cf5035325105be98fa69 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 29 Nov 2024 18:53:44 +0000 Subject: [PATCH 24/55] Removed using directive in derived message router classes. --- .gitignore | 3 + .../QueuedMessageRouter.cpp | 2 - .../QueuedMessageRouter.sln | 0 .../QueuedMessageRouter.vcxproj | 8 +- test/test_message_router.cpp | 93 +++++++++++++++++++ 5 files changed, 100 insertions(+), 6 deletions(-) rename examples/QueuedMessageRouter/{vs2019 => vs2022}/QueuedMessageRouter.sln (100%) rename examples/QueuedMessageRouter/{vs2019 => vs2022}/QueuedMessageRouter.vcxproj (97%) diff --git a/.gitignore b/.gitignore index 8f313ddbc..6ca19e113 100644 --- a/.gitignore +++ b/.gitignore @@ -388,3 +388,6 @@ support/time remaining test.xlsx test/vs2022/Debug MSVC C++20 - Force C++03 test/vs2022/Release MSVC C++20 - No STL - Optimised -O2 - Sanitiser test/test_file_list.txt +examples/QueuedMessageRouter/vs2022/.vs/QueuedMessageRouter/CopilotIndices +examples/QueuedMessageRouter/vs2022/.vs/QueuedMessageRouter/FileContentIndex +examples/QueuedMessageRouter/vs2022/.vs/QueuedMessageRouter/v17 diff --git a/examples/QueuedMessageRouter/QueuedMessageRouter.cpp b/examples/QueuedMessageRouter/QueuedMessageRouter.cpp index d4f78f772..f4348e5e2 100644 --- a/examples/QueuedMessageRouter/QueuedMessageRouter.cpp +++ b/examples/QueuedMessageRouter/QueuedMessageRouter.cpp @@ -52,8 +52,6 @@ class Router : public etl::message_router typedef etl::message_router Base_t; - using Base_t::receive; - //*************************************************************************** Router() : message_router(1) diff --git a/examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.sln b/examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.sln similarity index 100% rename from examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.sln rename to examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.sln diff --git a/examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.vcxproj b/examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.vcxproj similarity index 97% rename from examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.vcxproj rename to examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.vcxproj index 65dad150f..eaacbe964 100644 --- a/examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.vcxproj +++ b/examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.vcxproj @@ -29,26 +29,26 @@ Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode diff --git a/test/test_message_router.cpp b/test/test_message_router.cpp index b5936d629..a4e600fd0 100644 --- a/test/test_message_router.cpp +++ b/test/test_message_router.cpp @@ -253,6 +253,77 @@ namespace int sender_id; }; + //*************************************************************************** + // Router that handles messages 1, 2, 3. + // 'receive' is overridden. + //*************************************************************************** + class Router3 : public etl::message_router + { + public: + + using base = etl::message_router; + + Router3() + : message_router(ROUTER3) + , message1_received(false) + , message2_received(false) + , message3_received(false) + , unknown_message_received(false) + { + } + + void receive(const etl::imessage& msg) override + { + switch (msg.get_message_id()) + { + case MESSAGE1: + { + message1_received = true; + break; + } + + case MESSAGE2: + { + message2_received = true; + break; + } + + case MESSAGE3: + { + message3_received = true; + break; + } + + default: + { + unknown_message_received = true; + break; + } + } + } + + void on_receive(const Message1& msg) + { + } + + void on_receive(const Message2& msg) + { + } + + void on_receive(const Message3& msg) + { + } + + void on_receive_unknown(const etl::imessage&) + { + } + + bool message1_received; + bool message2_received; + bool message3_received; + bool unknown_message_received; + }; + etl::imessage_router* p_router; SUITE(test_message_router) @@ -641,5 +712,27 @@ namespace CHECK_EQUAL(0, r1.message4_count); CHECK_EQUAL(0, r1.message_unknown_count); } + + //************************************************************************* + TEST(message_router_with_overloaded_receive) + { + Router3 router; + etl::imessage_router& irouter = router; + + Message1 message1(router); + Message2 message2(router); + Message3 message3(router); + + router.receive(message1); + CHECK_TRUE(router.message1_received); + + router.receive(message2); + CHECK_TRUE(router.message2_received); + + router.receive(message3); + CHECK_TRUE(router.message3_received); + + CHECK_FALSE(router.unknown_message_received); + } }; } From 6195aa5f08a04de51fc762c2dccdfdf8e0bbb707 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 29 Nov 2024 18:53:44 +0000 Subject: [PATCH 25/55] Removed using directive in derived message router classes. --- test/test_message_router.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/test/test_message_router.cpp b/test/test_message_router.cpp index a4e600fd0..938a0854f 100644 --- a/test/test_message_router.cpp +++ b/test/test_message_router.cpp @@ -717,7 +717,6 @@ namespace TEST(message_router_with_overloaded_receive) { Router3 router; - etl::imessage_router& irouter = router; Message1 message1(router); Message2 message2(router); From b1c6489ac5b5ce1dc608b68e24f9d2e5b274109b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 18 Nov 2024 20:20:38 +0000 Subject: [PATCH 26/55] Added construction from std::basic_string_view --- include/etl/string_view.h | 16 ++++++++++ test/test_string_view.cpp | 64 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 7ddce5034..4078bc4ff 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -43,6 +43,10 @@ SOFTWARE. #include "algorithm.h" #include "private/minmax_push.h" +#if ETL_USING_STL && ETL_USING_CPP17 + #include +#endif + #include namespace etl @@ -163,6 +167,18 @@ namespace etl { } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Constructor from std::basic string_view + //************************************************************************* + template + ETL_CONSTEXPR basic_string_view(const std::basic_string_view& other) ETL_NOEXCEPT + : mbegin(other.data()) + , mend(other.data() + other.size()) + { + } +#endif + //************************************************************************* /// Returns a const reference to the first element. //************************************************************************* diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index 08c28a555..bff4c2116 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -162,6 +162,70 @@ namespace CHECK(isEqual); } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST(test_constructor_from_std_string_view) + { + std::string_view stdview(etltext.begin(), etltext.end()); + + View view(stdview); + + CHECK(stdview.size() == view.size()); + CHECK(stdview.size() == view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); + CHECK(isEqual); + } +#endif + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST(test_constructor_from_std_wstring_view) + { + std::wstring_view stdview(wtext.begin(), wtext.end()); + + WView view(stdview); + + CHECK(stdview.size() == view.size()); + CHECK(stdview.size() == view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); + CHECK(isEqual); + } +#endif + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST(test_constructor_from_std_u16string_view) + { + std::u16string_view stdview(u16text.begin(), u16text.end()); + + U16View view(stdview); + + CHECK(stdview.size() == view.size()); + CHECK(stdview.size() == view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); + CHECK(isEqual); + } +#endif + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST(test_constructor_from_std_u32string_view) + { + std::u32string_view stdview(u32text.begin(), u32text.end()); + + U32View view(stdview); + + CHECK(stdview.size() == view.size()); + CHECK(stdview.size() == view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); + CHECK(isEqual); + } +#endif + //************************************************************************* TEST(test_constructor_pointer_size) { From cbe4d5abe0df9059180ac067c94721cc814da0f6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 20 Nov 2024 09:51:02 +0000 Subject: [PATCH 27/55] Added string_view API. For all string types except _ext --- include/etl/basic_string.h | 140 ++- include/etl/string.h | 34 + include/etl/string_view.h | 2 +- include/etl/u16string.h | 34 + include/etl/u32string.h | 34 + include/etl/u8string.h | 34 + include/etl/wstring.h | 34 + test/test_string_char.cpp | 1771 +++++++++++++++++++++++++++++---- test/test_string_u16.cpp | 1784 +++++++++++++++++++++++++++++---- test/test_string_u32.cpp | 1818 +++++++++++++++++++++++++++++----- test/test_string_u8.cpp | 1784 +++++++++++++++++++++++++++++---- test/test_string_wchar_t.cpp | 1804 +++++++++++++++++++++++++++++---- 12 files changed, 8216 insertions(+), 1057 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 1bf290022..344e7d3b0 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -1177,6 +1177,38 @@ namespace etl return *this; } + //********************************************************************* + /// Inserts a string at the specified position. + ///\param position The position to insert before. + ///\param view The view to insert. + //********************************************************************* + template + etl::ibasic_string& insert(size_type position, const etl::basic_string_view& view) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + + insert(begin() + position, view.cbegin(), view.cend()); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Inserts a string at the specified position. + ///\param position The position to insert before. + ///\param view The view to insert. + //********************************************************************* + template + etl::ibasic_string& insert(size_type position, const std::basic_string_view& view) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + + insert(begin() + position, view.cbegin(), view.cend()); + + return *this; + } +#endif + //********************************************************************* /// Inserts a string at the specified position from subposition for sublength. ///\param position The position to insert before. @@ -1186,7 +1218,7 @@ namespace etl //********************************************************************* etl::ibasic_string& insert(size_type position, const etl::ibasic_string& str, size_type subposition, size_type sublength) { - ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); if ((sublength == npos) || (subposition + sublength > str.size())) @@ -1210,6 +1242,54 @@ namespace etl return *this; } + //********************************************************************* + /// Inserts a view at the specified position from subposition for sublength. + ///\param position The position to insert before. + ///\param view The view to insert. + ///\param subposition The subposition to start from. + ///\param sublength The number of characters to insert. + //********************************************************************* + template + etl::ibasic_string& insert(size_type position, const etl::basic_string_view& view, size_type subposition, size_type sublength) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); + + if ((sublength == npos) || (subposition + sublength > view.size())) + { + sublength = view.size() - subposition; + } + + insert(begin() + position, view.cbegin() + subposition, view.cbegin() + subposition + sublength); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //********************************************************************* + /// Inserts a view at the specified position from subposition for sublength. + ///\param position The position to insert before. + ///\param view The view to insert. + ///\param subposition The subposition to start from. + ///\param sublength The number of characters to insert. + //********************************************************************* + template + etl::ibasic_string& insert(size_type position, const std::basic_string_view& view, size_type subposition, size_type sublength) + { + ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); + ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); + + if ((sublength == npos) || (subposition + sublength > view.size())) + { + sublength = view.size() - subposition; + } + + insert(begin() + position, view.cbegin() + subposition, view.cbegin() + subposition + sublength); + + return *this; + } +#endif + //********************************************************************* /// Inserts a string at the specified position from pointer. ///\param position The position to insert before. @@ -1900,9 +1980,9 @@ namespace etl int compare(const etl::basic_string_view& view) const { return compare(p_buffer, - p_buffer + view.size(), + p_buffer + size(), view.data(), - view.size()); + view.data() + view.size()); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -1913,9 +1993,9 @@ namespace etl int compare(const std::basic_string_view& view) const { return compare(p_buffer, - p_buffer + view.size(), + p_buffer + size(), view.data(), - view.size()); + view.data() + view.size()); } #endif @@ -1943,8 +2023,8 @@ namespace etl { return compare(p_buffer + position, p_buffer + position + length_, - view.p_buffer, - view.p_buffer + view.size()); + view.data(), + view.data() + view.size()); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -1956,8 +2036,8 @@ namespace etl { return compare(p_buffer + position, p_buffer + position + length_, - view.p_buffer, - view.p_buffer + view.size()); + view.data(), + view.data() + view.size()); } #endif @@ -1994,8 +2074,8 @@ namespace etl return compare(p_buffer + position, p_buffer + position + length_, - view.p_buffer + subposition, - view.p_buffer + subposition + sublength); + view.data() + subposition, + view.data() + subposition + sublength); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -2014,8 +2094,8 @@ namespace etl return compare(p_buffer + position, p_buffer + position + length_, - view.p_buffer + subposition, - view.p_buffer + subposition + sublength); + view.data() + subposition, + view.data() + subposition + sublength); } #endif @@ -2168,7 +2248,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find_last_of(const etl::basic_string_view& view, size_type position = 0) const + size_type find_last_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_of(view.data(), position, view.size()); } @@ -2180,7 +2260,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find_last_of(const std::basic_string_view& view, size_type position = 0) const + size_type find_last_of(const std::basic_string_view& view, size_type position = npos) const { return find_last_of(view.data(), position, view.size()); } @@ -2373,7 +2453,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find_last_not_of(const etl::basic_string_view& view, size_type position = 0) const + size_type find_last_not_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_not_of(view.data(), position, view.size()); } @@ -2385,7 +2465,7 @@ namespace etl ///\param pos The position to start searching from. //********************************************************************* template - size_type find_last_not_of(const std::basic_string_view& view, size_type position = 0) const + size_type find_last_not_of(const std::basic_string_view& view, size_type position = npos) const { return find_last_not_of(view.data(), position, view.size()); } @@ -2483,6 +2563,30 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + template + ibasic_string& operator = (const etl::basic_string_view& view) + { + assign(view); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Assignment operator. + //************************************************************************* + template + ibasic_string& operator = (const std::basic_string_view& view) + { + assign(view); + + return *this; + } +#endif + //************************************************************************* /// += operator. //************************************************************************* @@ -2607,7 +2711,7 @@ namespace etl //************************************************************************* /// Compare helper function //************************************************************************* - int compare(const_pointer first1, const_pointer last1, const_pointer first2, const_pointer last2) const + int compare(const_pointer first1, const_pointer last1, const_pointer first2, const_pointer last2) const { while ((first1 != last1) && (first2 != last2)) { diff --git a/include/etl/string.h b/include/etl/string.h index 50b3bf624..74942df43 100644 --- a/include/etl/string.h +++ b/include/etl/string.h @@ -186,6 +186,18 @@ namespace etl this->assign(view.begin(), view.end()); } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit string(const std::string_view& view) + : istring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(view.begin(), view.end()); + } +#endif + //************************************************************************* /// Returns a sub-string. ///\param position The position of the first character. Default = 0. @@ -244,6 +256,28 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const etl::string_view& view) + { + this->assign(view); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string& operator = (const std::string_view& view) + { + this->assign(view); + + return *this; + } +#endif + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 4078bc4ff..3558d2ef9 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -172,7 +172,7 @@ namespace etl /// Constructor from std::basic string_view //************************************************************************* template - ETL_CONSTEXPR basic_string_view(const std::basic_string_view& other) ETL_NOEXCEPT + ETL_CONSTEXPR basic_string_view(const std::basic_string_view& other) ETL_NOEXCEPT : mbegin(other.data()) , mend(other.data() + other.size()) { diff --git a/include/etl/u16string.h b/include/etl/u16string.h index c0fea3a21..8e317dfb7 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -183,6 +183,18 @@ namespace etl this->assign(view.begin(), view.end()); } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit u16string(const std::u16string_view& view) + : iu16string(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(view.begin(), view.end()); + } +#endif + //************************************************************************* /// Returns a sub-string. ///\param position The position of the first character. Default = 0. @@ -227,6 +239,28 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u16string& operator = (const etl::u16string_view& view) + { + this->assign(view); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u16string& operator = (const std::u16string_view& view) + { + this->assign(view); + + return *this; + } +#endif + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 766a0cbc3..c22924fa4 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -183,6 +183,18 @@ namespace etl this->assign(view.begin(), view.end()); } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit u32string(const std::u32string_view& view) + : iu32string(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(view.begin(), view.end()); + } +#endif + //************************************************************************* /// Returns a sub-string. ///\param position The position of the first character. Default = 0. @@ -227,6 +239,28 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u32string& operator = (const etl::u32string_view& view) + { + this->assign(view); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u32string& operator = (const std::u32string_view& view) + { + this->assign(view); + + return *this; + } +#endif + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/u8string.h b/include/etl/u8string.h index 015ef3c15..fc5eefa02 100644 --- a/include/etl/u8string.h +++ b/include/etl/u8string.h @@ -186,6 +186,18 @@ namespace etl this->assign(view.begin(), view.end()); } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit u8string(const std::u8string_view& view) + : iu8string(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(view.begin(), view.end()); + } +#endif + //************************************************************************* /// Returns a sub-u8string. ///\param position The position of the first character. Default = 0. @@ -244,6 +256,28 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u8string& operator = (const etl::u8string_view& view) + { + this->assign(view); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u8string& operator = (const std::u8string_view& view) + { + this->assign(view); + + return *this; + } +#endif + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 683359de2..5409d1668 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -183,6 +183,18 @@ namespace etl this->assign(view.begin(), view.end()); } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit wstring(const std::wstring_view& view) + : iwstring(reinterpret_cast(&buffer), MAX_SIZE) + { + this->assign(view.begin(), view.end()); + } +#endif + //************************************************************************* /// Returns a sub-string. ///\param position The position of the first character. Default = 0. @@ -227,6 +239,28 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + wstring& operator = (const etl::wstring_view& view) + { + this->assign(view); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Assignment operator. + //************************************************************************* + wstring& operator = (const std::wstring_view& view) + { + this->assign(view); + + return *this; + } +#endif + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index b49e88147..913ce0dd2 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -33,8 +33,13 @@ SOFTWARE. #include #include "etl/string.h" +#include "etl/string_view.h" #include "etl/fnv_1.h" +#if ETL_USING_STL && ETL_USING_CPP17 + #include +#endif + #undef STR #define STR(x) x @@ -57,6 +62,10 @@ namespace using value_t = Text::value_type; using TextL = etl::string<52>; using TextS = etl::string<4>; + using ViewETL = etl::string_view; +#if ETL_USING_STL && ETL_USING_CPP17 + using ViewSTD = std::string_view; +#endif CompareText initial_text; CompareText less_text; @@ -288,9 +297,22 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) + { + ViewETL view(initial_text.data(), initial_text.size()); + Text text(view); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK(text.size() == SIZE); + CHECK(!text.empty()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) { - etl::string_view view(initial_text.data(), initial_text.size()); + ViewSTD view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -298,6 +320,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -575,6 +598,36 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) + { + Text text; + + text = ViewETL(STR("Hello World")); + + bool is_equal = Equal(std::string(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + { + Text text; + + text = ViewSTD(STR("Hello World")); + + bool is_equal = Equal(std::string(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -1008,6 +1061,48 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_etl_view) + { + CompareText compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + ViewETL view(input); + + CompareText compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_std_view) + { + CompareText compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + ViewSTD view(input.data(), input.data_end()); + + CompareText compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { @@ -1525,6 +1620,50 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + CompareText compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + CompareText compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + ViewSTD view(insert_text.data(), insert_text.data() + insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { @@ -1648,6 +1787,74 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_etl_view) + { + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.data() + initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_std_view) + { + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + ViewSTD append(insert_text.data(), insert_text.data() + insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(append); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + append = ViewSTD(initial_text.data(), initial_text.data() + initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(append); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1959,15 +2166,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { - // Non-overflow short text. + // Non-overflow short text, npos. CompareText compare_text(short_text.c_str()); - Text text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + text.replace(2, Text::npos, ViewETL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1975,13 +2182,41 @@ namespace CHECK(!text.is_truncated()); #endif + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1993,9 +2228,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(2, 7, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + text.replace(2, 7, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2007,9 +2242,23 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2018,16 +2267,17 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { - // Non-overflow short text. + // Non-overflow short text, npos. CompareText compare_text(short_text.c_str()); - Text text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")), 1, 5); + text.replace(2, Text::npos, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2035,13 +2285,13 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2053,9 +2303,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2067,9 +2317,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2081,9 +2331,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")), 1, 5); + text.replace(2, 7, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2091,41 +2341,27 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow, npos. + // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow. + // Overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2133,17 +2369,18 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2151,97 +2388,101 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif + } - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - is_equal = Equal(compare_text, text); + bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); #endif - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow. + // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); + text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Overflow, npos. + // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2250,16 +2491,17 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2271,9 +2513,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2285,9 +2527,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2299,9 +2541,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2309,17 +2551,18 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) + TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); + text.replace(2, 4, TextL(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2331,9 +2574,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2345,9 +2588,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2359,9 +2602,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2373,9 +2616,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); + text.replace(2, 7, TextL(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2387,9 +2630,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2401,9 +2644,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2415,9 +2658,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2427,15 +2670,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); + text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2443,31 +2686,69 @@ namespace CHECK(!text.is_truncated()); #endif -#include "etl/private/diagnostic_array_bounds_push.h" -#include "etl/private/diagnostic_stringop_overread_push.h" + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" -#include "etl/private/diagnostic_pop.h" // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); + text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2475,35 +2756,46 @@ namespace CHECK(!text.is_truncated()); #endif -#include "etl/private/diagnostic_array_bounds_push.h" -#include "etl/private/diagnostic_stringop_overread_push.h" // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" -#include "etl/private/diagnostic_pop.h" } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, 7, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 7, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2515,9 +2807,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 7, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2529,9 +2821,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, 15, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 15, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2543,9 +2835,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 15, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2557,9 +2849,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, 7, STR('A')); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, 7, STR('A')); + text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2571,9 +2863,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 7, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2585,9 +2877,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, 15, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 15, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2599,9 +2891,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 15, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2609,17 +2901,18 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2627,25 +2920,501 @@ namespace CHECK(!text.is_truncated()); #endif - // Overflow short text. + // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, CompareText(STR("Replace")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, TextL(STR("Replace")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, CompareText(STR("Replace")).c_str(), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + +#include "etl/private/diagnostic_array_bounds_push.h" +#include "etl/private/diagnostic_stringop_overread_push.h" + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif +#include "etl/private/diagnostic_pop.h" +#include "etl/private/diagnostic_pop.h" + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + +#include "etl/private/diagnostic_array_bounds_push.h" +#include "etl/private/diagnostic_stringop_overread_push.h" + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif +#include "etl/private/diagnostic_pop.h" +#include "etl/private/diagnostic_pop.h" + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 7, STR('A')); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); @@ -3104,24 +3873,88 @@ namespace size_t length2 = text.copy(buffer2, SIZE, 2); buffer2[length2] = STR('\0'); - CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_EQUAL(length1, length2); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + bool is_equal = std::equal(buffer1, + buffer1 + length1, + buffer2); + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_string) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::string compare_needle(STR("needle")); + etl::string<50> needle(STR("needle")); + + std::string compare_haystack(the_haystack); + etl::string<50> haystack(the_haystack); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle, position2 + 1); + CHECK_EQUAL(etl::string<50>::npos, position2); + + etl::string<50> pin(STR("pin")); + position2 = haystack.find(pin); + CHECK_EQUAL(etl::istring::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::string compare_needle(STR("needle")); + etl::string<50> needle(STR("needle")); + ViewETL needle_view(needle); + + std::string compare_haystack(the_haystack); + etl::string<50> haystack(the_haystack); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); - bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); - CHECK(is_equal); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(etl::string<50>::npos, position2); + + etl::string<50> pin(STR("pin")); + ViewETL pin_view(pin); + position2 = haystack.find(pin_view); + CHECK_EQUAL(etl::istring::npos, position2); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_string) + TEST_FIXTURE(SetupFixture, test_find_std_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); std::string compare_needle(STR("needle")); - etl::string<50> needle(STR("needle")); + std::string needle(STR("needle")); + ViewSTD needle_view(needle); std::string compare_haystack(the_haystack); etl::string<50> haystack(the_haystack); @@ -3130,20 +3963,22 @@ namespace size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle, position2); + position2 = haystack.find(needle_view, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle, position2 + 1); + position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(position1, position2); - position2 = haystack.find(needle, position2 + 1); + position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(etl::string<50>::npos, position2); - etl::string<50> pin(STR("pin")); - position2 = haystack.find(pin); + std::string pin(STR("pin")); + ViewSTD pin_view(pin); + position2 = haystack.find(pin_view); CHECK_EQUAL(etl::istring::npos, position2); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -3230,6 +4065,66 @@ namespace CHECK_EQUAL(etl::istring::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::string compare_needle(STR("needle")); + etl::string<50> needle(STR("needle")); + ViewETL needle_view(needle); + + std::string compare_haystack(the_haystack); + etl::string<50> haystack(the_haystack); + + size_t position1 = std::string::npos; + size_t position2 = etl::string<50>::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + etl::string<50> pin(STR("pin")); + ViewETL pin_view(pin); + position2 = haystack.rfind(pin); + CHECK_EQUAL(etl::istring::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_std_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::string compare_needle(STR("needle")); + std::string needle(STR("needle")); + ViewSTD needle_view(needle); + + std::string compare_haystack(the_haystack); + etl::string<50> haystack(the_haystack); + + size_t position1 = std::string::npos; + size_t position2 = etl::string<50>::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + std::string pin(STR("pin")); + ViewSTD pin_view(pin); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(etl::istring::npos, position2); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { @@ -3362,23 +4257,237 @@ namespace CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); - result = text.compare(Text(STR("ABCDEG"))); + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(Text(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(Text(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(Text(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_etl_view) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + result = text.compare(ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + result = text.compare(ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_std_view) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + result = text.compare(ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + result = text.compare(ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, Text(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, Text(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, Text(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, Text(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, Text(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); - result = text.compare(Text(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); - result = text.compare(Text(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { CompareText compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -3387,33 +4496,34 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); - result = text.compare(3, 6, Text(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); - result = text.compare(3, 6, Text(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); - result = text.compare(3, 6, Text(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); - result = text.compare(3, 6, Text(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); - result = text.compare(3, 6, Text(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { CompareText compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -3423,29 +4533,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) @@ -3581,6 +4692,66 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position2 = text.find_first_of(ViewETL(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { @@ -3717,6 +4888,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { @@ -3866,6 +5107,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -4012,6 +5323,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index 7d529521d..20671aa50 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -66,12 +66,12 @@ namespace { static const size_t SIZE = 11; - using Text = etl::u16string; - using IText = etl::iu16string; + using Text = etl::u16string; + using IText = etl::iu16string; using CompareText = std::u16string; - using value_t = Text::value_type; - using TextL = etl::u16string<52>; - using TextS = etl::u16string<4>; + using value_t = Text::value_type; + using TextL = etl::u16string<52>; + using TextS = etl::u16string<4>; CompareText initial_text; CompareText less_text; @@ -81,6 +81,10 @@ namespace CompareText insert_text; CompareText longer_text; CompareText short_text; + using ViewETL = etl::u16string_view; +#if ETL_USING_STL && ETL_USING_CPP17 + using ViewSTD = std::u16string_view; +#endif const value_t* pinitial_text = STR("Hello World"); @@ -304,9 +308,22 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) + { + ViewETL view(initial_text.data(), initial_text.size()); + Text text(view); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK(text.size() == SIZE); + CHECK(!text.empty()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) { - etl::u16string_view view(initial_text.data(), initial_text.size()); + ViewSTD view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -314,6 +331,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -591,6 +609,36 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) + { + Text text; + + text = ViewETL(STR("Hello World")); + + bool is_equal = Equal(std::u16string(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + { + Text text; + + text = ViewSTD(STR("Hello World")); + + bool is_equal = Equal(std::u16string(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -1023,6 +1071,48 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_etl_view) + { + CompareText compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + ViewETL view(input); + + CompareText compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_std_view) + { + CompareText compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + ViewSTD view(input.data(), input.data_end()); + + CompareText compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { @@ -1540,6 +1630,50 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + CompareText compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + CompareText compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + ViewSTD view(insert_text.data(), insert_text.data() + insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { @@ -1663,6 +1797,74 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_etl_view) + { + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.data() + initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_std_view) + { + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + ViewSTD append(insert_text.data(), insert_text.data() + insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(append); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + append = ViewSTD(initial_text.data(), initial_text.data() + initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(append); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1974,15 +2176,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { - // Non-overflow short text. + // Non-overflow short text, npos. CompareText compare_text(short_text.c_str()); - Text text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + text.replace(2, Text::npos, ViewETL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1990,13 +2192,41 @@ namespace CHECK(!text.is_truncated()); #endif + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2008,9 +2238,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(2, 7, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + text.replace(2, 7, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2022,9 +2252,23 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2033,16 +2277,17 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { - // Non-overflow short text. + // Non-overflow short text, npos. CompareText compare_text(short_text.c_str()); - Text text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")), 1, 5); + text.replace(2, Text::npos, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2050,13 +2295,13 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2068,9 +2313,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2082,9 +2327,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2096,9 +2341,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")), 1, 5); + text.replace(2, 7, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2106,59 +2351,46 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow, npos. + // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow. + // Overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } + } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2166,97 +2398,101 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif + } - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(2, 7, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - is_equal = Equal(compare_text, text); + bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); #endif - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow. + // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Overflow, npos. + // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2265,16 +2501,17 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2286,9 +2523,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2300,9 +2537,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2314,9 +2551,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2324,17 +2561,18 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) + TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + text.replace(2, 4, TextL(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2346,9 +2584,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2360,9 +2598,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2374,9 +2612,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2388,9 +2626,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + text.replace(2, 7, TextL(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2402,9 +2640,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2416,9 +2654,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2430,9 +2668,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2442,15 +2680,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2458,31 +2696,69 @@ namespace CHECK(!text.is_truncated()); #endif -#include "etl/private/diagnostic_array_bounds_push.h" -#include "etl/private/diagnostic_stringop_overread_push.h" + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" -#include "etl/private/diagnostic_pop.h" // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2490,35 +2766,46 @@ namespace CHECK(!text.is_truncated()); #endif -#include "etl/private/diagnostic_array_bounds_push.h" -#include "etl/private/diagnostic_stringop_overread_push.h" // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" -#include "etl/private/diagnostic_pop.h" } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, 7, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 7, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2530,9 +2817,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 7, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2544,9 +2831,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, 15, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 15, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2558,9 +2845,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 15, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2572,9 +2859,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, 7, STR('A')); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, 7, STR('A')); + text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2586,9 +2873,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 7, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2600,9 +2887,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, 15, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 15, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2614,9 +2901,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 15, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2624,17 +2911,18 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.replace(2, 4, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + text.replace(2, 4, STR("Replace")); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2642,32 +2930,508 @@ namespace CHECK(!text.is_truncated()); #endif - // Overflow short text. + // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); + compare_text.replace(2, CompareText::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); + text.replace(2, Text::npos, STR("Replace")); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); + compare_text.replace(2, 4, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); + text.replace(2, 4, STR("Replace with some text")); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, STR("Replace")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, STR("Replace")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace"), 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace"), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, STR("Replace"), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace"), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + +#include "etl/private/diagnostic_array_bounds_push.h" +#include "etl/private/diagnostic_stringop_overread_push.h" + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif +#include "etl/private/diagnostic_pop.h" +#include "etl/private/diagnostic_pop.h" + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + +#include "etl/private/diagnostic_array_bounds_push.h" +#include "etl/private/diagnostic_stringop_overread_push.h" + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif +#include "etl/private/diagnostic_pop.h" +#include "etl/private/diagnostic_pop.h" + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 7, STR('A')); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); #endif // Overflow. @@ -3119,46 +3883,112 @@ namespace size_t length2 = text.copy(buffer2, SIZE, 2); buffer2[length2] = STR('\0'); - CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_EQUAL(length1, length2); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + bool is_equal = std::equal(buffer1, + buffer1 + length1, + buffer2); + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_string) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::u16string compare_needle(STR("needle")); + etl::u16string<50> needle(STR("needle")); + + std::u16string compare_haystack(the_haystack); + etl::u16string<50> haystack(the_haystack); + + size_t position1 = 0; + size_t position2 = 0; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle, position2 + 1); + CHECK_EQUAL(etl::u16string<50>::npos, position2); + + etl::u16string<50> pin(STR("pin")); + position2 = haystack.find(pin); + CHECK_EQUAL(etl::iu16string::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::u16string compare_needle(STR("needle")); + etl::u16string<50> needle(STR("needle")); + ViewETL needle_view(needle); + + std::u16string compare_haystack(the_haystack); + etl::u16string<50> haystack(the_haystack); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(etl::u16string<50>::npos, position2); - bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); - CHECK(is_equal); + etl::u16string<50> pin(STR("pin")); + ViewETL pin_view(pin); + position2 = haystack.find(pin_view); + CHECK_EQUAL(etl::iu16string::npos, position2); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_string) + TEST_FIXTURE(SetupFixture, test_find_std_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); std::u16string compare_needle(STR("needle")); - etl::u16string<50> needle(STR("needle")); + std::u16string needle(STR("needle")); + ViewSTD needle_view(needle); std::u16string compare_haystack(the_haystack); etl::u16string<50> haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle, position2); + position2 = haystack.find(needle_view, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle, position2 + 1); + position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(position1, position2); - position2 = haystack.find(needle, position2 + 1); + position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(etl::u16string<50>::npos, position2); - etl::u16string<50> pin(STR("pin")); - position2 = haystack.find(pin); + std::u16string pin(STR("pin")); + ViewSTD pin_view(pin); + position2 = haystack.find(pin_view); CHECK_EQUAL(etl::iu16string::npos, position2); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -3245,6 +4075,66 @@ namespace CHECK_EQUAL(etl::iu16string::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::u16string compare_needle(STR("needle")); + etl::u16string<50> needle(STR("needle")); + ViewETL needle_view(needle); + + std::u16string compare_haystack(the_haystack); + etl::u16string<50> haystack(the_haystack); + + size_t position1 = std::u16string::npos; + size_t position2 = etl::u16string<50>::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + etl::u16string<50> pin(STR("pin")); + ViewETL pin_view(pin); + position2 = haystack.rfind(pin); + CHECK_EQUAL(etl::iu16string::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_std_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::u16string compare_needle(STR("needle")); + std::u16string needle(STR("needle")); + ViewSTD needle_view(needle); + + std::u16string compare_haystack(the_haystack); + etl::u16string<50> haystack(the_haystack); + + size_t position1 = std::u16string::npos; + size_t position2 = etl::u16string<50>::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + std::u16string pin(STR("pin")); + ViewSTD pin_view(pin); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(etl::iu16string::npos, position2); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { @@ -3377,23 +4267,237 @@ namespace CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); - result = text.compare(Text(STR("ABCDEG"))); + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(Text(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(Text(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(Text(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_etl_view) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + result = text.compare(ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + result = text.compare(ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_std_view) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + result = text.compare(ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + result = text.compare(ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, Text(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, Text(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, Text(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, Text(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, Text(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); - result = text.compare(Text(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); - result = text.compare(Text(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { CompareText compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -3402,33 +4506,34 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); - result = text.compare(3, 6, Text(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); - result = text.compare(3, 6, Text(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); - result = text.compare(3, 6, Text(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); - result = text.compare(3, 6, Text(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); - result = text.compare(3, 6, Text(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { CompareText compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -3438,29 +4543,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) @@ -3596,6 +4702,66 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position2 = text.find_first_of(ViewETL(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { @@ -3732,6 +4898,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { @@ -3881,6 +5117,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -4027,6 +5333,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index fa1c199c1..31f9fdad6 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -66,12 +66,12 @@ namespace { static const size_t SIZE = 11; - using Text = etl::u32string; - using IText = etl::iu32string; + using Text = etl::u32string; + using IText = etl::iu32string; using CompareText = std::u32string; - using value_t = Text::value_type; - using TextL = etl::u32string<52>; - using TextS = etl::u32string<4>; + using value_t = Text::value_type; + using TextL = etl::u32string<52>; + using TextS = etl::u32string<4>; CompareText initial_text; CompareText less_text; @@ -81,6 +81,10 @@ namespace CompareText insert_text; CompareText longer_text; CompareText short_text; + using ViewETL = etl::u32string_view; +#if ETL_USING_STL && ETL_USING_CPP17 + using ViewSTD = std::u32string_view; +#endif const value_t* pinitial_text = STR("Hello World"); @@ -96,15 +100,15 @@ namespace { SetupFixture() { - initial_text = STR("Hello World"); - initial_text = STR("Hello World"); - insert_text = STR("Insert"); - less_text = STR("Hello Vorld"); - greater_text = STR("Hello Xorld"); - shorter_text = STR("Hello Worl"); + initial_text = STR("Hello World"); + initial_text = STR("Hello World"); + insert_text = STR("Insert"); + less_text = STR("Hello Vorld"); + greater_text = STR("Hello Xorld"); + shorter_text = STR("Hello Worl"); different_text = STR("Byee Planet"); - longer_text = STR("Hello World There"); - short_text = STR("Hello"); + longer_text = STR("Hello World There"); + short_text = STR("Hello"); } }; @@ -304,9 +308,22 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) + { + ViewETL view(initial_text.data(), initial_text.size()); + Text text(view); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK(text.size() == SIZE); + CHECK(!text.empty()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) { - etl::u32string_view view(initial_text.data(), initial_text.size()); + ViewSTD view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -314,6 +331,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -410,10 +428,10 @@ namespace TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -591,13 +609,43 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) + { + Text text; + + text = ViewETL(STR("Hello World")); + + bool is_equal = Equal(std::u32string(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + { + Text text; + + text = ViewSTD(STR("Hello World")); + + bool is_equal = Equal(std::u32string(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { Text text(initial_text.c_str()); - const Text constText(initial_text.c_str()); + const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[0], text.begin()); + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } @@ -607,7 +655,7 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); + CHECK_EQUAL(&text[initial_text.size()], text.end()); CHECK_EQUAL(&constText[initial_text.size()], constText.end()); } @@ -1023,6 +1071,48 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_etl_view) + { + CompareText compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + ViewETL view(input); + + CompareText compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_std_view) + { + CompareText compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + ViewSTD view(input.data(), input.data_end()); + + CompareText compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { @@ -1540,6 +1630,50 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + CompareText compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + CompareText compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + ViewSTD view(insert_text.data(), insert_text.data() + insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { @@ -1663,6 +1797,74 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_etl_view) + { + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.data() + initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_std_view) + { + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + ViewSTD append(insert_text.data(), insert_text.data() + insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(append); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + append = ViewSTD(initial_text.data(), initial_text.data() + initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(append); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1974,15 +2176,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { - // Non-overflow short text. + // Non-overflow short text, npos. CompareText compare_text(short_text.c_str()); - Text text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + text.replace(2, Text::npos, ViewETL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1990,13 +2192,41 @@ namespace CHECK(!text.is_truncated()); #endif + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2008,9 +2238,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(2, 7, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + text.replace(2, 7, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2022,9 +2252,23 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2033,16 +2277,17 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { - // Non-overflow short text. + // Non-overflow short text, npos. CompareText compare_text(short_text.c_str()); - Text text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")), 1, 5); + text.replace(2, Text::npos, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2050,13 +2295,13 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2068,9 +2313,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2082,9 +2327,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2096,9 +2341,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")), 1, 5); + text.replace(2, 7, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2106,59 +2351,46 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow, npos. + // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow. + // Overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif + } +#endif - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2166,97 +2398,101 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif + } - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(2, 7, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - is_equal = Equal(compare_text, text); + bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); #endif - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow. + // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Overflow, npos. + // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2265,16 +2501,17 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2286,9 +2523,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2300,9 +2537,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2314,9 +2551,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2324,17 +2561,18 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) + TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + text.replace(2, 4, TextL(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2346,9 +2584,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2360,9 +2598,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2374,9 +2612,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2388,9 +2626,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + text.replace(2, 7, TextL(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2402,9 +2640,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2416,9 +2654,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2430,9 +2668,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2442,15 +2680,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2458,31 +2696,69 @@ namespace CHECK(!text.is_truncated()); #endif -#include "etl/private/diagnostic_array_bounds_push.h" -#include "etl/private/diagnostic_stringop_overread_push.h" + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" -#include "etl/private/diagnostic_pop.h" // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2490,35 +2766,46 @@ namespace CHECK(!text.is_truncated()); #endif -#include "etl/private/diagnostic_array_bounds_push.h" -#include "etl/private/diagnostic_stringop_overread_push.h" // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" -#include "etl/private/diagnostic_pop.h" } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, 7, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 7, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2530,9 +2817,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 7, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2544,9 +2831,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, 15, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 15, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2558,9 +2845,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 15, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2572,9 +2859,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, 7, STR('A')); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, 7, STR('A')); + text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2586,9 +2873,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 7, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2600,9 +2887,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, 15, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 15, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2614,9 +2901,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 15, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2624,17 +2911,18 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.replace(2, 4, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + text.replace(2, 4, STR("Replace")); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2642,27 +2930,503 @@ namespace CHECK(!text.is_truncated()); #endif - // Overflow short text. + // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); + compare_text.replace(2, CompareText::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); + text.replace(2, Text::npos, STR("Replace")); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); + compare_text.replace(2, 4, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); + text.replace(2, 4, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, STR("Replace")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, STR("Replace")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace"), 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace"), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, STR("Replace"), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace"), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + +#include "etl/private/diagnostic_array_bounds_push.h" +#include "etl/private/diagnostic_stringop_overread_push.h" + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif +#include "etl/private/diagnostic_pop.h" +#include "etl/private/diagnostic_pop.h" + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + +#include "etl/private/diagnostic_array_bounds_push.h" +#include "etl/private/diagnostic_stringop_overread_push.h" + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif +#include "etl/private/diagnostic_pop.h" +#include "etl/private/diagnostic_pop.h" + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 7, STR('A')); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3058,8 +3822,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3099,8 +3863,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3119,46 +3883,112 @@ namespace size_t length2 = text.copy(buffer2, SIZE, 2); buffer2[length2] = STR('\0'); - CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_EQUAL(length1, length2); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + bool is_equal = std::equal(buffer1, + buffer1 + length1, + buffer2); + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_string) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::u32string compare_needle(STR("needle")); + etl::u32string<50> needle(STR("needle")); + + std::u32string compare_haystack(the_haystack); + etl::u32string<50> haystack(the_haystack); + + size_t position1 = 0; + size_t position2 = 0; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle, position2 + 1); + CHECK_EQUAL(etl::u32string<50>::npos, position2); + + etl::u32string<50> pin(STR("pin")); + position2 = haystack.find(pin); + CHECK_EQUAL(etl::iu32string::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::u32string compare_needle(STR("needle")); + etl::u32string<50> needle(STR("needle")); + ViewETL needle_view(needle); + + std::u32string compare_haystack(the_haystack); + etl::u32string<50> haystack(the_haystack); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); - bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); - CHECK(is_equal); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(etl::u32string<50>::npos, position2); + + etl::u32string<50> pin(STR("pin")); + ViewETL pin_view(pin); + position2 = haystack.find(pin_view); + CHECK_EQUAL(etl::iu32string::npos, position2); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_string) + TEST_FIXTURE(SetupFixture, test_find_std_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); std::u32string compare_needle(STR("needle")); - etl::u32string<50> needle(STR("needle")); + std::u32string needle(STR("needle")); + ViewSTD needle_view(needle); std::u32string compare_haystack(the_haystack); etl::u32string<50> haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle, position2); + position2 = haystack.find(needle_view, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle, position2 + 1); + position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(position1, position2); - position2 = haystack.find(needle, position2 + 1); + position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(etl::u32string<50>::npos, position2); - etl::u32string<50> pin(STR("pin")); - position2 = haystack.find(pin); + std::u32string pin(STR("pin")); + ViewSTD pin_view(pin); + position2 = haystack.find(pin_view); CHECK_EQUAL(etl::iu32string::npos, position2); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -3245,6 +4075,66 @@ namespace CHECK_EQUAL(etl::iu32string::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::u32string compare_needle(STR("needle")); + etl::u32string<50> needle(STR("needle")); + ViewETL needle_view(needle); + + std::u32string compare_haystack(the_haystack); + etl::u32string<50> haystack(the_haystack); + + size_t position1 = std::u32string::npos; + size_t position2 = etl::u32string<50>::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + etl::u32string<50> pin(STR("pin")); + ViewETL pin_view(pin); + position2 = haystack.rfind(pin); + CHECK_EQUAL(etl::iu32string::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_std_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::u32string compare_needle(STR("needle")); + std::u32string needle(STR("needle")); + ViewSTD needle_view(needle); + + std::u32string compare_haystack(the_haystack); + etl::u32string<50> haystack(the_haystack); + + size_t position1 = std::u32string::npos; + size_t position2 = etl::u32string<50>::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + std::u32string pin(STR("pin")); + ViewSTD pin_view(pin); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(etl::iu32string::npos, position2); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { @@ -3377,23 +4267,237 @@ namespace CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); - result = text.compare(Text(STR("ABCDEG"))); + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(Text(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(Text(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(Text(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_etl_view) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + result = text.compare(ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + result = text.compare(ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_std_view) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + result = text.compare(ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + result = text.compare(ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, Text(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, Text(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, Text(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, Text(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, Text(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); - result = text.compare(Text(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); - result = text.compare(Text(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { CompareText compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -3402,33 +4506,34 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); - result = text.compare(3, 6, Text(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); - result = text.compare(3, 6, Text(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); - result = text.compare(3, 6, Text(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); - result = text.compare(3, 6, Text(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); - result = text.compare(3, 6, Text(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { CompareText compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -3438,29 +4543,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) @@ -3596,6 +4702,66 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position2 = text.find_first_of(ViewETL(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { @@ -3732,6 +4898,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { @@ -3881,6 +5117,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -4027,6 +5333,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_u8.cpp b/test/test_string_u8.cpp index 2165231fe..361ae40d0 100644 --- a/test/test_string_u8.cpp +++ b/test/test_string_u8.cpp @@ -69,12 +69,16 @@ namespace { static const size_t SIZE = 11; - using Text = etl::u8string; - using IText = etl::iu8string; + using Text = etl::u8string; + using IText = etl::iu8string; using CompareText = std::u8string; - using value_t = Text::value_type; - using TextL = etl::u8string<52>; - using TextS = etl::u8string<4>; + using value_t = Text::value_type; + using TextL = etl::u8string<52>; + using TextS = etl::u8string<4>; + using ViewETL = etl::u8string_view; +#if ETL_USING_STL && ETL_USING_CPP17 + using ViewSTD = std::u8string_view; +#endif CompareText initial_text; CompareText less_text; @@ -307,9 +311,22 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) + { + ViewETL view(initial_text.data(), initial_text.size()); + Text text(view); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK(text.size() == SIZE); + CHECK(!text.empty()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) { - etl::u8string_view view(initial_text.data(), initial_text.size()); + ViewSTD view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -317,6 +334,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -594,6 +612,36 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) + { + Text text; + + text = ViewETL(STR("Hello World")); + + bool is_equal = Equal(std::u8string(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + { + Text text; + + text = ViewSTD(STR("Hello World")); + + bool is_equal = Equal(std::u8string(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -1026,6 +1074,48 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_etl_view) + { + CompareText compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + ViewETL view(input); + + CompareText compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_std_view) + { + CompareText compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + ViewSTD view(input.data(), input.data_end()); + + CompareText compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { @@ -1543,6 +1633,50 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + CompareText compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + CompareText compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + ViewSTD view(insert_text.data(), insert_text.data() + insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { @@ -1666,6 +1800,74 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_etl_view) + { + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.data() + initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_std_view) + { + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + ViewSTD append(insert_text.data(), insert_text.data() + insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(append); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + append = ViewSTD(initial_text.data(), initial_text.data() + initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(append); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1977,15 +2179,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { - // Non-overflow short text. + // Non-overflow short text, npos. CompareText compare_text(short_text.c_str()); - Text text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + text.replace(2, Text::npos, ViewETL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1993,13 +2195,41 @@ namespace CHECK(!text.is_truncated()); #endif + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2011,9 +2241,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(2, 7, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + text.replace(2, 7, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2025,9 +2255,23 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2036,16 +2280,17 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { - // Non-overflow short text. + // Non-overflow short text, npos. CompareText compare_text(short_text.c_str()); - Text text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")), 1, 5); + text.replace(2, Text::npos, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2053,13 +2298,13 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2071,9 +2316,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2085,9 +2330,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2099,9 +2344,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")), 1, 5); + text.replace(2, 7, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2109,59 +2354,46 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow, npos. + // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow. + // Overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } + } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2169,97 +2401,101 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif + } - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - is_equal = Equal(compare_text, text); + bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); #endif - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow. + // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); + text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Overflow, npos. + // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2268,16 +2504,17 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2289,9 +2526,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2303,9 +2540,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2317,9 +2554,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2327,17 +2564,18 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) + TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); + text.replace(2, 4, TextL(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2349,9 +2587,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2363,9 +2601,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2377,9 +2615,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2391,9 +2629,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); + text.replace(2, 7, TextL(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2405,9 +2643,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2419,9 +2657,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2433,9 +2671,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2445,15 +2683,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); + text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2461,31 +2699,69 @@ namespace CHECK(!text.is_truncated()); #endif -#include "etl/private/diagnostic_array_bounds_push.h" -#include "etl/private/diagnostic_stringop_overread_push.h" + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" -#include "etl/private/diagnostic_pop.h" // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); + text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2493,35 +2769,46 @@ namespace CHECK(!text.is_truncated()); #endif -#include "etl/private/diagnostic_array_bounds_push.h" -#include "etl/private/diagnostic_stringop_overread_push.h" // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" -#include "etl/private/diagnostic_pop.h" } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, 7, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 7, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2533,9 +2820,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 7, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2547,9 +2834,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, 15, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 15, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2561,9 +2848,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 15, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2575,9 +2862,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, 7, STR('A')); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, 7, STR('A')); + text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2589,9 +2876,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 7, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2603,9 +2890,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, 15, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 15, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2617,9 +2904,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 15, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2627,17 +2914,18 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2645,32 +2933,508 @@ namespace CHECK(!text.is_truncated()); #endif - // Overflow short text. + // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, CompareText(STR("Replace")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, TextL(STR("Replace")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, CompareText(STR("Replace")).c_str(), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + +#include "etl/private/diagnostic_array_bounds_push.h" +#include "etl/private/diagnostic_stringop_overread_push.h" + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif +#include "etl/private/diagnostic_pop.h" +#include "etl/private/diagnostic_pop.h" + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + +#include "etl/private/diagnostic_array_bounds_push.h" +#include "etl/private/diagnostic_stringop_overread_push.h" + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif +#include "etl/private/diagnostic_pop.h" +#include "etl/private/diagnostic_pop.h" + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 7, STR('A')); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); #endif // Overflow. @@ -3122,46 +3886,112 @@ namespace size_t length2 = text.copy(buffer2, SIZE, 2); buffer2[length2] = STR('\0'); - CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_EQUAL(length1, length2); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + bool is_equal = std::equal(buffer1, + buffer1 + length1, + buffer2); + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_string) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::u8string compare_needle(STR("needle")); + etl::u8string<50> needle(STR("needle")); + + std::u8string compare_haystack(the_haystack); + etl::u8string<50> haystack(the_haystack); + + size_t position1 = 0; + size_t position2 = 0; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle, position2 + 1); + CHECK_EQUAL(etl::u8string<50>::npos, position2); + + etl::u8string<50> pin(STR("pin")); + position2 = haystack.find(pin); + CHECK_EQUAL(etl::iu8string::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::u8string compare_needle(STR("needle")); + etl::u8string<50> needle(STR("needle")); + ViewETL needle_view(needle); + + std::u8string compare_haystack(the_haystack); + etl::u8string<50> haystack(the_haystack); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(etl::u8string<50>::npos, position2); - bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); - CHECK(is_equal); + etl::u8string<50> pin(STR("pin")); + ViewETL pin_view(pin); + position2 = haystack.find(pin_view); + CHECK_EQUAL(etl::iu8string::npos, position2); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_string) + TEST_FIXTURE(SetupFixture, test_find_std_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); std::u8string compare_needle(STR("needle")); - etl::u8string<50> needle(STR("needle")); + std::u8string needle(STR("needle")); + ViewSTD needle_view(needle); std::u8string compare_haystack(the_haystack); etl::u8string<50> haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle, position2); + position2 = haystack.find(needle_view, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle, position2 + 1); + position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(position1, position2); - position2 = haystack.find(needle, position2 + 1); + position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(etl::u8string<50>::npos, position2); - etl::u8string<50> pin(STR("pin")); - position2 = haystack.find(pin); + std::u8string pin(STR("pin")); + ViewSTD pin_view(pin); + position2 = haystack.find(pin_view); CHECK_EQUAL(etl::iu8string::npos, position2); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -3248,6 +4078,66 @@ namespace CHECK_EQUAL(etl::iu8string::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::u8string compare_needle(STR("needle")); + etl::u8string<50> needle(STR("needle")); + ViewETL needle_view(needle); + + std::u8string compare_haystack(the_haystack); + etl::u8string<50> haystack(the_haystack); + + size_t position1 = std::u8string::npos; + size_t position2 = etl::u8string<50>::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + etl::u8string<50> pin(STR("pin")); + ViewETL pin_view(pin); + position2 = haystack.rfind(pin); + CHECK_EQUAL(etl::iu8string::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_std_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::u8string compare_needle(STR("needle")); + std::u8string needle(STR("needle")); + ViewSTD needle_view(needle); + + std::u8string compare_haystack(the_haystack); + etl::u8string<50> haystack(the_haystack); + + size_t position1 = std::u8string::npos; + size_t position2 = etl::u8string<50>::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + std::u8string pin(STR("pin")); + ViewSTD pin_view(pin); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(etl::iu8string::npos, position2); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { @@ -3380,23 +4270,237 @@ namespace CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); - result = text.compare(Text(STR("ABCDEG"))); + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(Text(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(Text(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(Text(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_etl_view) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + result = text.compare(ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + result = text.compare(ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_std_view) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + result = text.compare(ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + result = text.compare(ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, Text(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, Text(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, Text(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, Text(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, Text(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); - result = text.compare(Text(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); - result = text.compare(Text(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { CompareText compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -3405,33 +4509,34 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); - result = text.compare(3, 6, Text(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); - result = text.compare(3, 6, Text(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); - result = text.compare(3, 6, Text(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); - result = text.compare(3, 6, Text(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); - result = text.compare(3, 6, Text(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { CompareText compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -3441,29 +4546,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) @@ -3599,6 +4705,66 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position2 = text.find_first_of(ViewETL(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { @@ -3735,6 +4901,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { @@ -3884,6 +5120,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -4030,6 +5336,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index f3e852b7d..862565c0e 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -66,12 +66,12 @@ namespace { static const size_t SIZE = 11; - using Text = etl::wstring; - using IText = etl::iwstring; + using Text = etl::wstring; + using IText = etl::iwstring; using CompareText = std::wstring; - using value_t = Text::value_type; - using TextL = etl::wstring<52>; - using TextS = etl::wstring<4>; + using value_t = Text::value_type; + using TextL = etl::wstring<52>; + using TextS = etl::wstring<4>; CompareText initial_text; CompareText less_text; @@ -79,10 +79,14 @@ namespace CompareText shorter_text; CompareText different_text; CompareText insert_text; - CompareText short_text; CompareText longer_text; + CompareText short_text; + using ViewETL = etl::wstring_view; +#if ETL_USING_STL && ETL_USING_CPP17 + using ViewSTD = std::wstring_view; +#endif - const Text::value_type* pinitial_text = STR("Hello World"); + const value_t* pinitial_text = STR("Hello World"); //************************************************************************* template @@ -304,9 +308,22 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) + { + ViewETL view(initial_text.data(), initial_text.size()); + Text text(view); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK(text.size() == SIZE); + CHECK(!text.empty()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) { - etl::wstring_view view(initial_text.data(), initial_text.size()); + ViewSTD view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -314,6 +331,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -410,10 +428,10 @@ namespace TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -591,13 +609,43 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) + { + Text text; + + text = ViewETL(STR("Hello World")); + + bool is_equal = Equal(std::wstring(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + { + Text text; + + text = ViewSTD(STR("Hello World")); + + bool is_equal = Equal(std::wstring(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - - CHECK_EQUAL(&text[0], text.begin()); + + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } @@ -607,7 +655,7 @@ namespace Text text(initial_text.c_str()); const Text constText(initial_text.c_str()); - CHECK_EQUAL(&text[initial_text.size()], text.end()); + CHECK_EQUAL(&text[initial_text.size()], text.end()); CHECK_EQUAL(&constText[initial_text.size()], constText.end()); } @@ -1023,6 +1071,48 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_etl_view) + { + CompareText compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + ViewETL view(input); + + CompareText compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_std_view) + { + CompareText compare_input(initial_text.c_str()); + Text input(initial_text.c_str()); + ViewSTD view(input.data(), input.data_end()); + + CompareText compare_text; + Text text; + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { @@ -1540,6 +1630,50 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + CompareText compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + CompareText compare_text(short_text.cbegin(), short_text.cend()); + Text text(short_text.cbegin(), short_text.cend()); + ViewSTD view(insert_text.data(), insert_text.data() + insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { @@ -1663,6 +1797,74 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_etl_view) + { + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.data() + initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_std_view) + { + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + ViewSTD append(insert_text.data(), insert_text.data() + insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(append); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + append = ViewSTD(initial_text.data(), initial_text.data() + initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(append); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1974,15 +2176,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { - // Non-overflow short text. + // Non-overflow short text, npos. CompareText compare_text(short_text.c_str()); - Text text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + text.replace(2, Text::npos, ViewETL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -1990,13 +2192,41 @@ namespace CHECK(!text.is_truncated()); #endif + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2008,9 +2238,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(2, 7, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + text.replace(2, 7, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2022,9 +2252,23 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2033,16 +2277,17 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { - // Non-overflow short text. + // Non-overflow short text, npos. CompareText compare_text(short_text.c_str()); - Text text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")), 1, 5); + text.replace(2, Text::npos, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2050,13 +2295,13 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2068,9 +2313,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2082,9 +2327,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2096,9 +2341,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")), 1, 5); + text.replace(2, 7, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2106,59 +2351,46 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow, npos. + // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow. + // Overflow, npos. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif + } +#endif - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2166,97 +2398,101 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif + } - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); - compare_text.replace(2, 7, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - is_equal = Equal(compare_text, text); + bool is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); #endif - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow. + // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Overflow, npos. + // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2265,16 +2501,17 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2286,9 +2523,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2300,9 +2537,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2314,9 +2551,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2324,17 +2561,18 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) + TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + text.replace(2, 4, TextL(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2346,9 +2584,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2360,9 +2598,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2374,9 +2612,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2388,9 +2626,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + text.replace(2, 7, TextL(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2402,9 +2640,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2416,9 +2654,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2430,9 +2668,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2442,15 +2680,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2458,31 +2696,69 @@ namespace CHECK(!text.is_truncated()); #endif -#include "etl/private/diagnostic_array_bounds_push.h" -#include "etl/private/diagnostic_stringop_overread_push.h" + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" -#include "etl/private/diagnostic_pop.h" // Non-overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2490,35 +2766,46 @@ namespace CHECK(!text.is_truncated()); #endif -#include "etl/private/diagnostic_array_bounds_push.h" -#include "etl/private/diagnostic_stringop_overread_push.h" // Overflow. compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); #endif -#include "etl/private/diagnostic_pop.h" -#include "etl/private/diagnostic_pop.h" } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, 7, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 7, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2530,9 +2817,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 7, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2544,9 +2831,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, 15, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 15, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2558,9 +2845,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 15, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2572,9 +2859,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, 7, STR('A')); + compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, 7, STR('A')); + text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2586,9 +2873,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 7, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2600,9 +2887,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, 15, STR('A')); + compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, 15, STR('A')); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2614,9 +2901,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, 15, STR('A')); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2624,17 +2911,18 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. CompareText compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.replace(2, 4, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + text.replace(2, 4, STR("Replace")); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2642,25 +2930,501 @@ namespace CHECK(!text.is_truncated()); #endif - // Overflow short text. + // Non-overflow short text, npos. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); + compare_text.replace(2, CompareText::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); + text.replace(2, Text::npos, STR("Replace")); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); + CHECK(!text.is_truncated()); #endif - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); + compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, STR("Replace")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, STR("Replace")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace"), 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace"), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, STR("Replace"), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace"), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + +#include "etl/private/diagnostic_array_bounds_push.h" +#include "etl/private/diagnostic_stringop_overread_push.h" + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif +#include "etl/private/diagnostic_pop.h" +#include "etl/private/diagnostic_pop.h" + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + +#include "etl/private/diagnostic_array_bounds_push.h" +#include "etl/private/diagnostic_stringop_overread_push.h" + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif +#include "etl/private/diagnostic_pop.h" +#include "etl/private/diagnostic_pop.h" + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(2, 4, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 7, STR('A')); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 7, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) + { + // Non-overflow short text. + CompareText compare_text(short_text.c_str()); + Text text(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A')); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A')); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A')); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A')); @@ -3058,8 +3822,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3099,8 +3863,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3119,46 +3883,112 @@ namespace size_t length2 = text.copy(buffer2, SIZE, 2); buffer2[length2] = STR('\0'); - CHECK_EQUAL(length1, length2); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif + CHECK_EQUAL(length1, length2); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + bool is_equal = std::equal(buffer1, + buffer1 + length1, + buffer2); + CHECK(is_equal); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_string) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::wstring compare_needle(STR("needle")); + etl::wstring<50> needle(STR("needle")); + + std::wstring compare_haystack(the_haystack); + etl::wstring<50> haystack(the_haystack); + + size_t position1 = 0; + size_t position2 = 0; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle, position2 + 1); + CHECK_EQUAL(etl::wstring<50>::npos, position2); + + etl::wstring<50> pin(STR("pin")); + position2 = haystack.find(pin); + CHECK_EQUAL(etl::iwstring::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::wstring compare_needle(STR("needle")); + etl::wstring<50> needle(STR("needle")); + ViewETL needle_view(needle); + + std::wstring compare_haystack(the_haystack); + etl::wstring<50> haystack(the_haystack); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); - bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); - CHECK(is_equal); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(etl::wstring<50>::npos, position2); + + etl::wstring<50> pin(STR("pin")); + ViewETL pin_view(pin); + position2 = haystack.find(pin_view); + CHECK_EQUAL(etl::iwstring::npos, position2); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_string) + TEST_FIXTURE(SetupFixture, test_find_std_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); std::wstring compare_needle(STR("needle")); - etl::wstring<50> needle(STR("needle")); + std::wstring needle(STR("needle")); + ViewSTD needle_view(needle); std::wstring compare_haystack(the_haystack); etl::wstring<50> haystack(the_haystack); - size_t position1 = 0; - size_t position2 = 0; + size_t position1 = 0UL; + size_t position2 = 0UL; position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle, position2); + position2 = haystack.find(needle_view, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle, position2 + 1); + position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(position1, position2); - position2 = haystack.find(needle, position2 + 1); + position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(etl::wstring<50>::npos, position2); - etl::wstring<50> pin(STR("pin")); - position2 = haystack.find(pin); + std::wstring pin(STR("pin")); + ViewSTD pin_view(pin); + position2 = haystack.find(pin_view); CHECK_EQUAL(etl::iwstring::npos, position2); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -3245,6 +4075,66 @@ namespace CHECK_EQUAL(etl::iwstring::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::wstring compare_needle(STR("needle")); + etl::wstring<50> needle(STR("needle")); + ViewETL needle_view(needle); + + std::wstring compare_haystack(the_haystack); + etl::wstring<50> haystack(the_haystack); + + size_t position1 = std::wstring::npos; + size_t position2 = etl::wstring<50>::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + etl::wstring<50> pin(STR("pin")); + ViewETL pin_view(pin); + position2 = haystack.rfind(pin); + CHECK_EQUAL(etl::iwstring::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_std_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + std::wstring compare_needle(STR("needle")); + std::wstring needle(STR("needle")); + ViewSTD needle_view(needle); + + std::wstring compare_haystack(the_haystack); + etl::wstring<50> haystack(the_haystack); + + size_t position1 = std::wstring::npos; + size_t position2 = etl::wstring<50>::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + std::wstring pin(STR("pin")); + ViewSTD pin_view(pin); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(etl::iwstring::npos, position2); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { @@ -3377,23 +4267,237 @@ namespace CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); - result = text.compare(Text(STR("ABCDEG"))); + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(Text(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(Text(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(Text(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_etl_view) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + result = text.compare(ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + result = text.compare(ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_std_view) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + result = text.compare(ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + result = text.compare(ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + result = text.compare(ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + result = text.compare(ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + result = text.compare(ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, Text(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, Text(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, Text(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, Text(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, Text(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + { + CompareText compare_text(STR("xxxABCDEFyyy")); + Text text(STR("xxxABCDEFyyy")); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); - result = text.compare(Text(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); - result = text.compare(Text(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { CompareText compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -3402,33 +4506,34 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); - result = text.compare(3, 6, Text(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); - result = text.compare(3, 6, Text(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); - result = text.compare(3, 6, Text(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); - result = text.compare(3, 6, Text(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); - result = text.compare(3, 6, Text(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { CompareText compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -3438,29 +4543,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) @@ -3596,6 +4702,66 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position2 = text.find_first_of(ViewETL(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { @@ -3732,6 +4898,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { @@ -3881,6 +5117,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) + { + CompareText compare_text(STR("ABCDEF")); + Text text(STR("ABCDEF")); + + size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -4027,6 +5333,76 @@ namespace #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) + { + CompareText compare_text(STR("ABCDEFABCDE")); + Text text(STR("ABCDEFABCDE")); + + size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { From 9311819fa45f50242696520a634e71fe76e697f7 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 22 Nov 2024 12:25:02 +0000 Subject: [PATCH 28/55] Fixed C++ standard compatibility issues --- include/etl/string.h | 55 +- include/etl/u16string.h | 39 +- include/etl/u32string.h | 39 +- include/etl/u8string.h | 39 +- include/etl/wstring.h | 39 +- test/test_string_char.cpp | 840 ++++--- test/test_string_char_external_buffer.cpp | 2002 +++++++++++++--- test/test_string_u16.cpp | 808 ++++--- test/test_string_u16_external_buffer.cpp | 2206 +++++++++++++---- test/test_string_u32.cpp | 794 ++++--- test/test_string_u32_external_buffer.cpp | 2193 +++++++++++++---- test/test_string_u8.cpp | 828 ++++--- test/test_string_u8_external_buffer.cpp | 2158 +++++++++++++---- test/test_string_view.cpp | 31 +- test/test_string_wchar_t.cpp | 794 ++++--- test/test_string_wchar_t_external_buffer.cpp | 2209 ++++++++++++++---- 16 files changed, 11076 insertions(+), 3998 deletions(-) diff --git a/include/etl/string.h b/include/etl/string.h index 74942df43..55bfa4524 100644 --- a/include/etl/string.h +++ b/include/etl/string.h @@ -396,6 +396,28 @@ namespace etl this->resize(count, c); } + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit string_ext(const etl::string_view& view, value_type* buffer, size_type buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(view.begin(), view.end()); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit string_ext(const std::string_view& view, value_type* buffer, size_type buffer_size) + : istring(buffer, buffer_size - 1U) + { + this->assign(view.begin(), view.end()); + } +#endif + //************************************************************************* /// Constructor, from an iterator range. ///\tparam TIterator The iterator type. @@ -420,16 +442,6 @@ namespace etl } #endif - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit string_ext(const etl::string_view& view, value_type* buffer, size_type buffer_size) - : istring(buffer, buffer_size - 1U) - { - this->assign(view.begin(), view.end()); - } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -443,7 +455,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -467,6 +478,28 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string_ext& operator = (const etl::string_view& view) + { + this->assign(view); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Assignment operator. + //************************************************************************* + string_ext& operator = (const std::string_view& view) + { + this->assign(view); + + return *this; + } +#endif + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/u16string.h b/include/etl/u16string.h index 8e317dfb7..b18bc07d4 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -400,8 +400,8 @@ namespace etl #endif //************************************************************************* - /// From u16string_view. - ///\param view The u16string_view. + /// From string_view. + ///\param view The string_view. //************************************************************************* explicit u16string_ext(const etl::u16string_view& view, value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) @@ -409,6 +409,18 @@ namespace etl this->assign(view.begin(), view.end()); } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit u16string_ext(const std::u16string_view& view, value_type* buffer, size_type buffer_size) + : iu16string(buffer, buffer_size - 1U) + { + this->assign(view.begin(), view.end()); + } +#endif + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -422,7 +434,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -446,6 +457,28 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u16string_ext& operator = (const etl::u16string_view& view) + { + this->assign(view); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u16string_ext& operator = (const std::u16string_view& view) + { + this->assign(view); + + return *this; + } +#endif + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/u32string.h b/include/etl/u32string.h index c22924fa4..068e9e3c1 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -400,8 +400,8 @@ namespace etl #endif //************************************************************************* - /// From u32string_view. - ///\param view The u32string_view. + /// From string_view. + ///\param view The string_view. //************************************************************************* explicit u32string_ext(const etl::u32string_view& view, value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) @@ -409,6 +409,18 @@ namespace etl this->assign(view.begin(), view.end()); } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit u32string_ext(const std::u32string_view& view, value_type* buffer, size_type buffer_size) + : iu32string(buffer, buffer_size - 1U) + { + this->assign(view.begin(), view.end()); + } +#endif + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -422,7 +434,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -446,6 +457,28 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u32string_ext& operator = (const etl::u32string_view& view) + { + this->assign(view); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u32string_ext& operator = (const std::u32string_view& view) + { + this->assign(view); + + return *this; + } +#endif + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/u8string.h b/include/etl/u8string.h index fc5eefa02..7cc1964f6 100644 --- a/include/etl/u8string.h +++ b/include/etl/u8string.h @@ -186,7 +186,7 @@ namespace etl this->assign(view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP17 +#if ETL_USING_STL && ETL_USING_CPP20 //************************************************************************* /// From string_view. ///\param view The string_view. @@ -266,7 +266,7 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 +#if ETL_USING_STL && ETL_USING_CPP20 //************************************************************************* /// Assignment operator. //************************************************************************* @@ -430,6 +430,18 @@ namespace etl this->assign(view.begin(), view.end()); } +#if ETL_USING_STL && ETL_USING_CPP20 + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit u8string_ext(const std::u8string_view& view, value_type* buffer, size_type buffer_size) + : iu8string(buffer, buffer_size - 1U) + { + this->assign(view.begin(), view.end()); + } +#endif + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -443,7 +455,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -467,6 +478,28 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u8string_ext& operator = (const etl::u8string_view& view) + { + this->assign(view); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP20 + //************************************************************************* + /// Assignment operator. + //************************************************************************* + u8string_ext& operator = (const std::u8string_view& view) + { + this->assign(view); + + return *this; + } +#endif + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 5409d1668..939646386 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -400,8 +400,8 @@ namespace etl #endif //************************************************************************* - /// From wstring_view. - ///\param view The wstring_view. + /// From string_view. + ///\param view The string_view. //************************************************************************* explicit wstring_ext(const etl::wstring_view& view, value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) @@ -409,6 +409,18 @@ namespace etl this->assign(view.begin(), view.end()); } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// From string_view. + ///\param view The string_view. + //************************************************************************* + explicit wstring_ext(const std::wstring_view& view, value_type* buffer, size_type buffer_size) + : iwstring(buffer, buffer_size - 1U) + { + this->assign(view.begin(), view.end()); + } +#endif + //************************************************************************* /// Assignment operator. //************************************************************************* @@ -422,7 +434,6 @@ namespace etl return *this; } - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -446,6 +457,28 @@ namespace etl return *this; } + //************************************************************************* + /// Assignment operator. + //************************************************************************* + wstring_ext& operator = (const etl::wstring_view& view) + { + this->assign(view); + + return *this; + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + /// Assignment operator. + //************************************************************************* + wstring_ext& operator = (const std::wstring_view& view) + { + this->assign(view); + + return *this; + } +#endif + //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 913ce0dd2..cb3de4633 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -56,25 +56,25 @@ namespace { static const size_t SIZE = 11UL; - using Text = etl::string; - using IText = etl::istring; - using CompareText = std::string; - using value_t = Text::value_type; - using TextL = etl::string<52>; - using TextS = etl::string<4>; - using ViewETL = etl::string_view; + using Text = etl::string; + using IText = etl::istring; + using TextSTD = std::string; + using value_t = Text::value_type; + using TextL = etl::string<52>; + using TextS = etl::string<4>; + using ViewETL = etl::string_view; #if ETL_USING_STL && ETL_USING_CPP17 using ViewSTD = std::string_view; #endif - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -136,7 +136,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -164,7 +164,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -180,7 +180,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -196,7 +196,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -212,7 +212,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -228,7 +228,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -244,7 +244,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -260,7 +260,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); @@ -370,8 +370,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); Text text(initial_text.c_str()); Text text2(text, 2, 4); @@ -386,8 +386,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextL textl(longer_text.c_str()); Text text2(textl, 2, 12); @@ -403,7 +403,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; bool is_equal = Equal(compare_text, text); @@ -416,7 +416,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), @@ -547,7 +547,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -561,7 +561,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -576,7 +576,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -591,7 +591,7 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); @@ -605,7 +605,7 @@ namespace text = ViewETL(STR("Hello World")); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -620,7 +620,7 @@ namespace text = ViewSTD(STR("Hello World")); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -895,7 +895,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -911,7 +911,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -927,7 +927,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -945,7 +945,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -963,7 +963,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -975,7 +975,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -987,7 +987,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -999,7 +999,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -1011,7 +1011,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); @@ -1028,7 +1028,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); const Text text(compare_text.begin(), compare_text.end()); @@ -1045,10 +1045,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1064,11 +1064,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_etl_view) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); ViewETL view(input); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1085,11 +1085,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_std_view) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - ViewSTD view(input.data(), input.data_end()); + ViewSTD view(input.data(), input.size()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1106,10 +1106,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1125,7 +1125,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str()); @@ -1140,7 +1140,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1155,7 +1155,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str(), initial_text.size()); @@ -1170,7 +1170,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1187,7 +1187,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1259,7 +1259,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1285,7 +1285,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1316,7 +1316,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1340,7 +1340,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1360,7 +1360,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); const value_t INITIAL_VALUE = STR('A'); @@ -1405,7 +1405,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INITIAL_SIZE = 5UL; @@ -1431,7 +1431,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INSERT_SIZE = 4UL; @@ -1504,7 +1504,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.cbegin(), initial_text.cbegin() + INITIAL_SIZE); @@ -1527,7 +1527,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; size_t offset = 0UL; @@ -1585,7 +1585,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); text.insert(text.cbegin() + offset, text.cbegin() + 5, text.cbegin() + 10); @@ -1604,7 +1604,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); Text insert(insert_text.cbegin(), insert_text.cend()); @@ -1625,9 +1625,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewETL view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1647,9 +1647,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewSTD view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewSTD view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1669,7 +1669,7 @@ namespace { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); Text text(initial_text.cbegin(), initial_text.cend()); Text insert(insert_text.cbegin(), insert_text.cend()); @@ -1690,7 +1690,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); Text insert(longer_text.cbegin(), longer_text.cend()); insert.erase(insert.cbegin(), insert.cend()); @@ -1711,7 +1711,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); Text insert(insert_text.cbegin(), insert_text.cend()); @@ -1757,7 +1757,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1790,9 +1790,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_etl_view) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewETL view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1807,7 +1807,7 @@ namespace // Overflow. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - view.assign(initial_text.data(), initial_text.data() + initial_text.size()); + view.assign(initial_text.data(), initial_text.size()); compare_text.append(initial_text); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -1824,9 +1824,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_std_view) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewSTD append(insert_text.data(), insert_text.data() + insert_text.size()); + ViewSTD append(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1841,7 +1841,7 @@ namespace // Overflow. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.data() + initial_text.size()); + append = ViewSTD(initial_text.data(), initial_text.size()); compare_text.append(initial_text); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -1875,7 +1875,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1906,12 +1906,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); // Whole string. - compare_text.append(insert_text, 0, std::string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -1970,7 +1970,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -2002,7 +2002,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -2034,7 +2034,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -2067,10 +2067,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2084,7 +2084,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2098,7 +2098,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2112,7 +2112,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2126,7 +2126,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2140,7 +2140,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2154,7 +2154,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2169,10 +2169,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace"))); @@ -2186,7 +2186,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace"))); @@ -2200,7 +2200,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace with some text"))); @@ -2214,7 +2214,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); @@ -2228,7 +2228,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewETL(STR("Replace"))); @@ -2242,7 +2242,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace with some text"))); @@ -2256,7 +2256,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); @@ -2272,10 +2272,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace"))); @@ -2289,7 +2289,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace"))); @@ -2303,7 +2303,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace with some text"))); @@ -2317,7 +2317,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); @@ -2331,7 +2331,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewSTD(STR("Replace"))); @@ -2345,7 +2345,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace with some text"))); @@ -2359,7 +2359,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); @@ -2375,10 +2375,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -2392,7 +2392,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2406,7 +2406,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2420,7 +2420,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2435,10 +2435,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); @@ -2452,7 +2452,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); @@ -2466,7 +2466,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); @@ -2480,7 +2480,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); @@ -2496,10 +2496,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); @@ -2513,7 +2513,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); @@ -2527,7 +2527,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); @@ -2541,7 +2541,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); @@ -2557,10 +2557,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2574,7 +2574,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2588,7 +2588,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2602,7 +2602,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2616,7 +2616,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2630,7 +2630,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2644,7 +2644,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2658,7 +2658,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2673,10 +2673,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); @@ -2690,7 +2690,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); @@ -2704,7 +2704,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); @@ -2718,7 +2718,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); @@ -2732,7 +2732,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); @@ -2746,7 +2746,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); @@ -2760,7 +2760,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); @@ -2774,7 +2774,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); @@ -2790,10 +2790,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); @@ -2807,7 +2807,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); @@ -2821,7 +2821,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); @@ -2835,7 +2835,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); @@ -2849,7 +2849,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); @@ -2863,7 +2863,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); @@ -2877,7 +2877,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); @@ -2891,7 +2891,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); @@ -2907,10 +2907,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str()); @@ -2924,7 +2924,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2938,7 +2938,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2952,7 +2952,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2966,7 +2966,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str()); @@ -2980,7 +2980,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2994,7 +2994,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -3008,7 +3008,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -3023,10 +3023,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); @@ -3040,7 +3040,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -3054,7 +3054,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); @@ -3068,7 +3068,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -3083,10 +3083,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); @@ -3100,7 +3100,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -3114,7 +3114,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -3128,7 +3128,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -3142,7 +3142,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); @@ -3156,7 +3156,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -3170,7 +3170,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -3184,7 +3184,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -3199,10 +3199,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); @@ -3218,7 +3218,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -3234,7 +3234,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); @@ -3250,7 +3250,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -3267,7 +3267,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -3284,7 +3284,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -3312,7 +3312,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -3340,7 +3340,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -3368,7 +3368,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -3383,7 +3383,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); @@ -3443,11 +3443,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3505,10 +3505,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); Text::iterator ditr = text.erase(text.begin() + 2); CHECK(*citr == *ditr); @@ -3522,10 +3522,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); Text::iterator ditr = text.erase(text.cbegin() + 2); CHECK(*citr == *ditr); @@ -3539,10 +3539,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); CHECK(*citr == *ditr); @@ -3568,7 +3568,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); @@ -3581,7 +3581,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); @@ -3594,7 +3594,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); @@ -3607,7 +3607,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); @@ -3794,7 +3794,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3835,13 +3835,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3861,7 +3861,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3889,11 +3889,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); - etl::string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3907,11 +3907,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3919,12 +3919,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); - etl::string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); ViewETL needle_view(needle); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3938,12 +3938,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(etl::string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::string<50> pin(STR("pin")); - ViewETL pin_view(pin); + ViewETL pin_view(STR("pin")); position2 = haystack.find(pin_view); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -3952,12 +3951,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); - std::string needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); ViewSTD needle_view(needle); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3971,12 +3970,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(etl::string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - std::string pin(STR("pin")); - ViewSTD pin_view(pin); + ViewSTD pin_view(STR("pin")); position2 = haystack.find(pin_view); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #endif @@ -3987,8 +3985,8 @@ namespace const value_t* needle = STR("needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -4002,11 +4000,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t *pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4016,8 +4014,8 @@ namespace const value_t* needle = STR("needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -4031,11 +4029,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4043,14 +4041,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); - etl::string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -4060,9 +4058,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4070,28 +4068,27 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); - etl::string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); ViewETL needle_view(needle); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle_view, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle, haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::string<50> pin(STR("pin")); - ViewETL pin_view(pin); - position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::istring::npos, position2); + ViewETL pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -4100,15 +4097,15 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); - std::string needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); ViewSTD needle_view(needle); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle_view, position2); @@ -4118,10 +4115,9 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - std::string pin(STR("pin")); - ViewSTD pin_view(pin); + ViewSTD pin_view(STR("pin")); position2 = haystack.rfind(pin_view); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #endif @@ -4130,13 +4126,13 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -4146,9 +4142,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4156,13 +4152,13 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -4173,7 +4169,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4181,11 +4177,11 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); - etl::string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - etl::istring::size_type position1 = etl::istring::npos; - size_t position2 = etl::string<50>::npos; + etl::istring::size_type position1 = TextL::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -4196,16 +4192,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::istring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -4240,34 +4236,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4275,34 +4271,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_etl_view) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(ViewETL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(ViewETL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(ViewETL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(ViewETL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(ViewETL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4311,34 +4307,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_std_view) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(ViewSTD(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(ViewSTD(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(ViewSTD(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(ViewSTD(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(ViewSTD(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4347,34 +4343,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4382,34 +4378,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, ViewETL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4418,34 +4414,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4454,34 +4450,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4489,34 +4485,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4525,34 +4521,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4561,7 +4557,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -4596,7 +4592,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -4631,7 +4627,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -4666,26 +4662,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(Text(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(Text(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(Text(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(Text(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4695,26 +4691,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(ViewETL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4725,26 +4721,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4755,7 +4751,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -4784,7 +4780,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -4818,7 +4814,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -4857,31 +4853,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(Text(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(Text(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(Text(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4891,31 +4887,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4926,31 +4922,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4961,7 +4957,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -5000,7 +4996,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -5037,7 +5033,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -5076,31 +5072,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5110,31 +5106,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5145,31 +5141,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5180,7 +5176,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -5214,7 +5210,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -5253,7 +5249,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -5292,31 +5288,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5326,31 +5322,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5361,31 +5357,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5396,7 +5392,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -5430,7 +5426,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -5462,7 +5458,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index d934dafed..e2704e815 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -33,6 +33,7 @@ SOFTWARE. #include #include "etl/string.h" +#include "etl/string_view.h" #include "etl/fnv_1.h" #undef STR @@ -53,24 +54,29 @@ namespace static constexpr size_t SIZE_L = 52UL; static constexpr size_t SIZE_S = 4UL; - using Text = etl::string_ext; - using IText = etl::istring; - using TextL = etl::string; - using CompareText = std::string; - using value_t = Text::value_type; + using Text = etl::string_ext; + using IText = etl::istring; + using TextL = etl::string; + using TextSTD = std::string; + using value_t = Text::value_type; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using ViewETL = etl::string_view; +#if ETL_USING_STL && ETL_USING_CPP17 + using ViewSTD = std::string_view; +#endif + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -201,7 +207,7 @@ namespace const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -231,7 +237,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -247,7 +253,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -264,7 +270,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -281,7 +287,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -298,7 +304,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -315,7 +321,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -332,7 +338,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -372,10 +378,23 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::string_view view(initial_text.data(), initial_text.size()); + ViewETL view(initial_text.data(), initial_text.size()); + TextBuffer buffer{0}; + Text text(view, buffer.data(), buffer.size()); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK(text.size() == SIZE); + CHECK(!text.empty()); + } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) + { + ViewSTD view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -384,6 +403,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -448,8 +468,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -467,8 +487,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -487,7 +507,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -503,7 +523,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), @@ -656,7 +676,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -671,7 +691,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -687,7 +707,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -703,13 +723,45 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = ViewETL(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = ViewSTD(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -981,7 +1033,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -999,7 +1051,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1017,7 +1069,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1037,7 +1089,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1057,7 +1109,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1071,7 +1123,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1085,7 +1137,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1099,7 +1151,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1113,7 +1165,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1131,7 +1183,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1149,12 +1201,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1169,15 +1221,61 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_etl_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + ViewETL view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_std_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + ViewSTD view(input.data(), input.size()); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1195,7 +1293,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1211,7 +1309,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1227,7 +1325,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1243,7 +1341,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1261,7 +1359,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1337,7 +1435,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1365,7 +1463,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1398,7 +1496,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1424,7 +1522,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1446,7 +1544,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1492,7 +1590,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1519,7 +1617,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1593,7 +1691,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1617,7 +1715,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1676,7 +1774,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1697,7 +1795,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1717,12 +1815,60 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1747,7 +1893,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1773,7 +1919,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1823,7 +1969,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1857,6 +2003,76 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_etl_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_std_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + ViewSTD append(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(append); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + append = ViewSTD(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(append); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1880,7 +2096,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1913,7 +2129,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1922,7 +2138,7 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -1984,7 +2200,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2018,7 +2234,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2052,7 +2268,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2089,12 +2305,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2108,7 +2324,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2122,7 +2338,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2136,7 +2352,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2150,7 +2366,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2164,7 +2380,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2178,7 +2394,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2190,17 +2406,16 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { - // Non-overflow short text. - CompareText compare_text(short_text.c_str()); - + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + text.replace(2, Text::npos, ViewETL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2208,13 +2423,41 @@ namespace CHECK(!text.is_truncated()); #endif + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2226,9 +2469,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + text.replace(2, 7, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2240,9 +2483,23 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2251,18 +2508,18 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { - // Non-overflow short text. - CompareText compare_text(short_text.c_str()); - + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")), 1, 5); + text.replace(2, Text::npos, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2270,13 +2527,13 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2288,9 +2545,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2302,9 +2559,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2316,23 +2573,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 7, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2344,9 +2587,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2358,9 +2601,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2368,19 +2611,20 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2388,25 +2632,565 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); + CHECK(text.is_truncated()); #endif - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, TextL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace")).c_str()); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2420,7 +3204,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2434,7 +3218,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str()); @@ -2448,7 +3232,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2462,7 +3246,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2476,7 +3260,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2491,12 +3275,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); @@ -2510,7 +3294,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -2524,7 +3308,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); @@ -2538,7 +3322,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -2553,12 +3337,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); @@ -2572,7 +3356,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -2586,7 +3370,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2600,7 +3384,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -2614,7 +3398,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); @@ -2628,7 +3412,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -2642,7 +3426,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2656,7 +3440,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -2671,12 +3455,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); @@ -2692,7 +3476,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2708,7 +3492,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); @@ -2724,7 +3508,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2741,7 +3525,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2760,7 +3544,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2788,7 +3572,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2816,7 +3600,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2844,7 +3628,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2859,7 +3643,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2921,13 +3705,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -2985,7 +3769,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3003,7 +3787,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3035,7 +3819,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3050,7 +3834,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3065,7 +3849,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3080,7 +3864,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3299,7 +4083,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3343,7 +4127,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3351,7 +4135,7 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3371,7 +4155,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3401,12 +4185,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3423,13 +4207,77 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::string<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewETL needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + ViewETL pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_std_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewSTD needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + ViewSTD pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3437,7 +4285,7 @@ namespace const value_t* needle = STR("needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3468,7 +4316,7 @@ namespace const value_t* needle = STR("needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3497,18 +4345,18 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3524,20 +4372,77 @@ namespace CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewETL needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + ViewETL pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_std_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); + ViewSTD needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + ViewSTD pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3558,96 +4463,318 @@ namespace { const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::string::npos; + size_t position1 = TextSTD::npos; + + size_t position2 = Text::npos; + + position1 = compare_haystack.rfind(needle, position1, 3); + position2 = haystack.rfind(needle, position2, 3); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10, 3); + position2 = haystack.rfind(needle, haystack.size() - 10, 3); + CHECK_EQUAL(position1, position2); + + position2 = haystack.rfind(STR("pin"), 3); + CHECK_EQUAL(IText::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_c_position) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); + + TextBufferL buffer{0}; + Text haystack(the_haystack, buffer.data(), buffer.size()); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(STR('e'), position1); + position2 = haystack.rfind(STR('e'), position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); + position2 = haystack.rfind(STR('e'), haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + position2 = haystack.rfind(STR('z')); + CHECK_EQUAL(IText::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_string) + { + TextSTD compare_text(STR("ABCDEF")); + + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(TextL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(TextL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(TextL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(TextL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(TextL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_etl_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_std_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, TextL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, TextL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, TextL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, TextL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, TextL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); - size_t position2 = Text::npos; + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(needle, position1, 3); - position2 = haystack.rfind(needle, position2, 3); - CHECK_EQUAL(position1, position2); + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10, 3); - position2 = haystack.rfind(needle, haystack.size() - 10, 3); - CHECK_EQUAL(position1, position2); + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); - position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(IText::npos, position2); + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_c_position) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) { - const value_t*the_haystack = STR("A haystack with a needle and another needle"); + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - std::string compare_haystack(the_haystack); + int compare_result; + int result; - TextBufferL buffer{0}; - Text haystack(the_haystack, buffer.data(), buffer.size()); + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); - size_t position1 = std::string::npos; - size_t position2 = etl::string<50>::npos; + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(STR('e'), position1); - position2 = haystack.rfind(STR('e'), position2); - CHECK_EQUAL(position1, position2); + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); - position2 = haystack.rfind(STR('e'), haystack.size() - 10); - CHECK_EQUAL(position1, position2); + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); - position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(IText::npos, position2); + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); - result = text.compare(TextL(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); - result = text.compare(TextL(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); - result = text.compare(TextL(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); - result = text.compare(TextL(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); - result = text.compare(TextL(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); - + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3655,36 +4782,36 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); - result = text.compare(3, 6, TextL(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); - result = text.compare(3, 6, TextL(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); - result = text.compare(3, 6, TextL(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); - result = text.compare(3, 6, TextL(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); - result = text.compare(3, 6, TextL(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); - + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3692,35 +4819,36 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3757,7 +4885,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3794,7 +4922,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3831,38 +4959,100 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(ViewETL(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3893,7 +5083,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3929,7 +5119,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3970,43 +5160,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4047,7 +5309,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4088,7 +5350,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4129,43 +5391,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4201,7 +5535,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4242,7 +5576,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4283,43 +5617,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4355,7 +5761,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4389,7 +5795,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index 20671aa50..98557a8ef 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -66,21 +66,21 @@ namespace { static const size_t SIZE = 11; - using Text = etl::u16string; - using IText = etl::iu16string; - using CompareText = std::u16string; - using value_t = Text::value_type; - using TextL = etl::u16string<52>; - using TextS = etl::u16string<4>; - - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using Text = etl::u16string; + using IText = etl::iu16string; + using TextSTD = std::u16string; + using value_t = Text::value_type; + using TextL = etl::u16string<52>; + using TextS = etl::u16string<4>; + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; using ViewETL = etl::u16string_view; #if ETL_USING_STL && ETL_USING_CPP17 using ViewSTD = std::u16string_view; @@ -147,7 +147,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -175,7 +175,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -191,7 +191,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -207,7 +207,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -223,7 +223,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -239,7 +239,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -255,7 +255,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -271,7 +271,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); @@ -381,8 +381,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); Text text(initial_text.c_str()); Text text2(text, 2, 4); @@ -397,8 +397,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextL textl(longer_text.c_str()); Text text2(textl, 2, 12); @@ -414,7 +414,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; bool is_equal = Equal(compare_text, text); @@ -427,7 +427,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), @@ -558,7 +558,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -572,7 +572,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -587,7 +587,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u16string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -602,7 +602,7 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u16string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); @@ -616,7 +616,7 @@ namespace text = ViewETL(STR("Hello World")); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -631,7 +631,7 @@ namespace text = ViewSTD(STR("Hello World")); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -905,7 +905,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -921,7 +921,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -937,7 +937,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -955,7 +955,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -973,7 +973,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -985,7 +985,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -997,7 +997,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -1009,7 +1009,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -1021,7 +1021,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); @@ -1038,7 +1038,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); const Text text(compare_text.begin(), compare_text.end()); @@ -1055,10 +1055,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1074,11 +1074,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_etl_view) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); ViewETL view(input); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1095,11 +1095,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_std_view) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - ViewSTD view(input.data(), input.data_end()); + ViewSTD view(input.data(), input.size()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1116,10 +1116,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1135,7 +1135,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str()); @@ -1150,7 +1150,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1165,7 +1165,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str(), initial_text.size()); @@ -1180,7 +1180,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1197,7 +1197,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1269,7 +1269,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1295,7 +1295,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1326,7 +1326,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1350,7 +1350,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1370,7 +1370,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); const value_t INITIAL_VALUE = STR('A'); @@ -1415,7 +1415,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INITIAL_SIZE = 5; @@ -1441,7 +1441,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INSERT_SIZE = 4; @@ -1514,7 +1514,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1537,7 +1537,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; size_t offset = 0; @@ -1595,7 +1595,7 @@ namespace for (size_t offset = 10; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); @@ -1614,7 +1614,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1635,9 +1635,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewETL view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1657,9 +1657,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewSTD view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewSTD view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1679,7 +1679,7 @@ namespace { for (size_t offset = 0; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1700,7 +1700,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(longer_text.begin(), longer_text.end()); insert.erase(insert.begin(), insert.end()); @@ -1721,7 +1721,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1767,7 +1767,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1800,9 +1800,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_etl_view) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewETL view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1817,7 +1817,7 @@ namespace // Overflow. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - view.assign(initial_text.data(), initial_text.data() + initial_text.size()); + view.assign(initial_text.data(), initial_text.size()); compare_text.append(initial_text); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -1834,9 +1834,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_std_view) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewSTD append(insert_text.data(), insert_text.data() + insert_text.size()); + ViewSTD append(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1851,7 +1851,7 @@ namespace // Overflow. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.data() + initial_text.size()); + append = ViewSTD(initial_text.data(), initial_text.size()); compare_text.append(initial_text); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -1885,7 +1885,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1916,12 +1916,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); // Whole string. - compare_text.append(insert_text, 0, std::u16string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -1980,7 +1980,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -2012,7 +2012,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -2044,7 +2044,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -2077,10 +2077,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2094,7 +2094,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2108,7 +2108,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2122,7 +2122,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2136,7 +2136,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2150,7 +2150,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2164,7 +2164,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2179,10 +2179,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace"))); @@ -2196,7 +2196,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace"))); @@ -2210,7 +2210,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace with some text"))); @@ -2224,7 +2224,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); @@ -2238,7 +2238,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewETL(STR("Replace"))); @@ -2252,7 +2252,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace with some text"))); @@ -2266,7 +2266,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); @@ -2282,10 +2282,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace"))); @@ -2299,7 +2299,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace"))); @@ -2313,7 +2313,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace with some text"))); @@ -2327,7 +2327,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); @@ -2341,7 +2341,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewSTD(STR("Replace"))); @@ -2355,7 +2355,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace with some text"))); @@ -2369,7 +2369,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); @@ -2385,10 +2385,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -2402,7 +2402,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2416,7 +2416,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2430,7 +2430,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2445,10 +2445,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); @@ -2462,7 +2462,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); @@ -2476,7 +2476,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); @@ -2490,7 +2490,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); @@ -2506,10 +2506,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); @@ -2523,7 +2523,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); @@ -2537,7 +2537,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); @@ -2551,7 +2551,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); @@ -2567,10 +2567,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2584,7 +2584,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2598,7 +2598,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2612,7 +2612,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2626,7 +2626,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2640,7 +2640,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2654,7 +2654,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2668,7 +2668,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2683,10 +2683,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); @@ -2700,7 +2700,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); @@ -2714,7 +2714,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); @@ -2728,7 +2728,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); @@ -2742,7 +2742,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); @@ -2756,7 +2756,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); @@ -2770,7 +2770,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); @@ -2784,7 +2784,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); @@ -2800,10 +2800,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); @@ -2817,7 +2817,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); @@ -2831,7 +2831,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); @@ -2845,7 +2845,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); @@ -2859,7 +2859,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); @@ -2873,7 +2873,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); @@ -2887,7 +2887,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); @@ -2901,7 +2901,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); @@ -2917,7 +2917,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, STR("Replace")); @@ -2934,7 +2934,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace")); @@ -2962,7 +2962,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text")); @@ -2990,7 +2990,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace")); @@ -3018,7 +3018,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text")); @@ -3033,7 +3033,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); @@ -3093,7 +3093,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, STR("Replace"), 5); @@ -3110,7 +3110,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace"), 5); @@ -3138,7 +3138,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text"), 15); @@ -3166,7 +3166,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace"), 5); @@ -3194,7 +3194,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text"), 15); @@ -3209,7 +3209,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); @@ -3277,7 +3277,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -3294,7 +3294,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -3322,7 +3322,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -3350,7 +3350,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -3378,7 +3378,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -3393,7 +3393,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); @@ -3453,11 +3453,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3515,10 +3515,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); Text::iterator ditr = text.erase(text.begin() + 2); CHECK(*citr == *ditr); @@ -3532,10 +3532,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); Text::iterator ditr = text.erase(text.cbegin() + 2); CHECK(*citr == *ditr); @@ -3549,10 +3549,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); CHECK(*citr == *ditr); @@ -3578,7 +3578,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); @@ -3591,7 +3591,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); @@ -3604,7 +3604,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); @@ -3617,7 +3617,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); @@ -3804,7 +3804,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3845,13 +3845,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3871,7 +3871,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3899,11 +3899,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); - etl::u16string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3917,11 +3917,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u16string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u16string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3929,12 +3929,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); - etl::u16string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); ViewETL needle_view(needle); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3948,12 +3948,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(etl::u16string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u16string<50> pin(STR("pin")); - ViewETL pin_view(pin); + ViewETL pin_view(STR("pin")); position2 = haystack.find(pin_view); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -3962,12 +3961,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); - std::u16string needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); ViewSTD needle_view(needle); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3981,12 +3980,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(etl::u16string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - std::u16string pin(STR("pin")); - ViewSTD pin_view(pin); + ViewSTD pin_view(STR("pin")); position2 = haystack.find(pin_view); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #endif @@ -3997,8 +3995,8 @@ namespace const value_t* needle = STR("needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -4012,11 +4010,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4026,8 +4024,8 @@ namespace const value_t* needle = STR("needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -4041,11 +4039,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4053,14 +4051,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); - etl::u16string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -4070,9 +4068,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u16string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4080,28 +4078,27 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); - etl::u16string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); ViewETL needle_view(needle); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle_view, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle, haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u16string<50> pin(STR("pin")); - ViewETL pin_view(pin); - position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + ViewETL pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -4110,15 +4107,15 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); - std::u16string needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); ViewSTD needle_view(needle); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle_view, position2); @@ -4128,10 +4125,9 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - std::u16string pin(STR("pin")); - ViewSTD pin_view(pin); + ViewSTD pin_view(STR("pin")); position2 = haystack.rfind(pin_view); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #endif @@ -4140,13 +4136,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -4156,9 +4152,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u16string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4166,13 +4162,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -4183,7 +4179,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4191,11 +4187,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); - etl::u16string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -4206,16 +4202,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::iu16string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -4250,34 +4246,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4285,34 +4281,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_etl_view) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(ViewETL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(ViewETL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(ViewETL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(ViewETL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(ViewETL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4321,34 +4317,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_std_view) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(ViewSTD(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(ViewSTD(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(ViewSTD(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(ViewSTD(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(ViewSTD(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4357,34 +4353,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4392,34 +4388,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, ViewETL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4428,34 +4424,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4464,34 +4460,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4499,34 +4495,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4535,34 +4531,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4571,7 +4567,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -4606,7 +4602,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -4641,7 +4637,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -4676,26 +4672,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(Text(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(Text(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(Text(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(Text(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4705,26 +4701,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(ViewETL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4735,26 +4731,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4765,7 +4761,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -4794,7 +4790,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -4828,7 +4824,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -4867,31 +4863,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(Text(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(Text(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(Text(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4901,31 +4897,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4936,31 +4932,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4971,7 +4967,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -5010,7 +5006,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -5047,7 +5043,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -5086,31 +5082,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5120,31 +5116,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5155,31 +5151,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5190,7 +5186,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -5224,7 +5220,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -5263,7 +5259,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -5302,31 +5298,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5336,31 +5332,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5371,31 +5367,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5406,7 +5402,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -5440,7 +5436,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -5472,7 +5468,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index 8e271ad6b..867a799ee 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -72,20 +72,25 @@ namespace using Text = etl::u16string_ext; using IText = etl::iu16string; using TextL = etl::u16string; - using CompareText = std::u16string; + using TextSTD = std::u16string; using value_t = Text::value_type; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using ViewETL = etl::u16string_view; +#if ETL_USING_STL && ETL_USING_CPP17 + using ViewSTD = std::u16string_view; +#endif + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -200,9 +205,9 @@ namespace TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -212,11 +217,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -246,7 +251,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -262,7 +267,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -279,7 +284,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -296,7 +301,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -313,7 +318,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -330,7 +335,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -347,7 +352,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -387,10 +392,23 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u16string_view view(initial_text.data(), initial_text.size()); + ViewETL view(initial_text.data(), initial_text.size()); + TextBuffer buffer{0}; + Text text(view, buffer.data(), buffer.size()); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK(text.size() == SIZE); + CHECK(!text.empty()); + } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) + { + ViewSTD view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -399,6 +417,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -463,8 +482,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -482,8 +501,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -502,7 +521,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -518,12 +537,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; TextBuffer buffer{0}; Text text(il, buffer.data(), buffer.size()); @@ -671,7 +690,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -686,7 +705,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u16string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -702,7 +721,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u16string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -718,13 +737,45 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u16string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = ViewETL(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = ViewSTD(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -847,7 +898,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 8; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -891,7 +942,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 2; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -917,24 +968,6 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_fill) - { - TextBuffer buffer1{ 0 }; - TextBuffer buffer2{ 0 }; - Text text(11, STR('A'), buffer1.data(), buffer1.size()); - Text expected(11, STR('B'), buffer2.data(), buffer2.size()); - - text.fill(STR('B')); - - bool is_equal = Equal(expected, text); - CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_full) { @@ -1014,7 +1047,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1032,7 +1065,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1050,7 +1083,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1070,7 +1103,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1090,7 +1123,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1104,7 +1137,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1118,7 +1151,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1132,7 +1165,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1146,7 +1179,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1164,7 +1197,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1182,12 +1215,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1202,15 +1235,61 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_etl_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + ViewETL view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_std_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + ViewSTD view(input.data(), input.size()); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1228,7 +1307,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1244,7 +1323,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1260,7 +1339,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1276,7 +1355,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1294,7 +1373,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1370,7 +1449,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1398,7 +1477,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1431,7 +1510,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1453,11 +1532,11 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1479,7 +1558,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1525,7 +1604,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1552,7 +1631,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1626,7 +1705,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1650,7 +1729,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1709,7 +1788,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1728,18 +1807,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - size_t s = short_text.size(); - (void)s; - - assert(s <= 5); - - for (size_t offset = s; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1755,23 +1830,64 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_2) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } } +#endif - //************************************************************************* + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { -#include "etl/private/diagnostic_array_bounds_push.h" for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); - TextBuffer buffer{ 0 }; + TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2{ 0 }; + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1784,7 +1900,6 @@ namespace CHECK(text.is_truncated()); #endif } -#include "etl/private/diagnostic_pop.h" } //************************************************************************* @@ -1792,7 +1907,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1818,7 +1933,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1868,7 +1983,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1902,6 +2017,76 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_etl_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_std_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + ViewSTD append(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(append); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + append = ViewSTD(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(append); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1925,7 +2110,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1958,7 +2143,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1967,7 +2152,7 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::u16string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -2029,7 +2214,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2063,7 +2248,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2097,7 +2282,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2134,12 +2319,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2153,7 +2338,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2167,7 +2352,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2181,7 +2366,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2195,7 +2380,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2209,7 +2394,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2223,7 +2408,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2235,17 +2420,16 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { - // Non-overflow short text. - CompareText compare_text(short_text.c_str()); - + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + text.replace(2, Text::npos, ViewETL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2253,13 +2437,41 @@ namespace CHECK(!text.is_truncated()); #endif + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2271,9 +2483,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + text.replace(2, 7, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2285,9 +2497,23 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2296,18 +2522,18 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { - // Non-overflow short text. - CompareText compare_text(short_text.c_str()); - + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")), 1, 5); + text.replace(2, Text::npos, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2315,13 +2541,13 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2333,9 +2559,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2347,9 +2573,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2361,23 +2587,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 7, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2389,9 +2601,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2403,9 +2615,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2413,19 +2625,560 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, TextL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2437,9 +3190,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2451,9 +3204,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2465,9 +3218,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2479,9 +3232,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + text.replace(2, 7, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2493,9 +3246,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2507,9 +3260,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2521,9 +3274,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2536,14 +3289,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2555,9 +3308,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2569,9 +3322,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2583,9 +3336,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2598,14 +3351,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2617,9 +3370,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2631,9 +3384,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2645,9 +3398,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2659,9 +3412,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2673,9 +3426,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2687,9 +3440,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2701,9 +3454,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2716,14 +3469,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2737,9 +3490,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2753,9 +3506,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2769,9 +3522,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2786,7 +3539,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2805,7 +3558,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2833,7 +3586,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2861,7 +3614,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2889,7 +3642,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2904,7 +3657,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2966,13 +3719,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3028,33 +3781,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); - TextBuffer buffer{0}; - Text text(initial_text.c_str(), buffer.data(), buffer.size()); + TextSTD compare_text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); - Text::iterator ditr = text.erase(text.begin() + 2); - CHECK(*citr == *ditr); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) - { - CompareText compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); - Text::iterator ditr = text.erase(text.cbegin() + 2); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2); + text.erase(text.begin() + 2); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3066,13 +3801,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); - Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); + + text.erase(text.begin() + 2, text.begin() + 4); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3097,7 +3833,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3112,7 +3848,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3127,7 +3863,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3142,7 +3878,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3208,7 +3944,7 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); TextBuffer buffer3; @@ -3225,17 +3961,17 @@ namespace CHECK((initial < initial) == (initial_text < initial_text)); // String-Pointer Pointer-String - CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((less < pinitial_text) == (less_text < pinitial_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); - CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); - CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); - CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3248,8 +3984,8 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); TextBuffer buffer3; const Text greater(greater_text.c_str(), buffer3.data(), buffer3.size()); @@ -3265,17 +4001,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3305,17 +4041,17 @@ namespace CHECK((initial > initial) == (initial_text > initial_text)); // String-Pointer Pointer-String - CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((less > pinitial_text) == (less_text > pinitial_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); - CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); - CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); - CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3328,8 +4064,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end(), buffer2.data(), buffer2.size()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); TextBuffer buffer3; const Text greater(greater_text.begin(), greater_text.end(), buffer3.data(), buffer3.size()); @@ -3345,24 +4081,24 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); - + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3381,8 +4117,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3405,7 +4141,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3413,7 +4149,7 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3425,15 +4161,15 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3453,8 +4189,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3463,12 +4199,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3485,13 +4221,77 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u16string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u16string<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewETL needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + ViewETL pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_std_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewSTD needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + ViewSTD pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3499,7 +4299,7 @@ namespace const value_t* needle = STR("needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3518,7 +4318,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } @@ -3530,7 +4330,7 @@ namespace const value_t* needle = STR("needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3549,7 +4349,7 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(IText::npos, position2); } @@ -3559,18 +4359,18 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3587,19 +4387,76 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_pointer) + TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewETL needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + ViewETL pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_std_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); + ViewSTD needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + ViewSTD pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_pointer) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3618,98 +4475,320 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u16string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u16string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; - position1 = compare_haystack.rfind(needle, position1, 3); - position2 = haystack.rfind(needle, position2, 3); - CHECK_EQUAL(position1, position2); + position1 = compare_haystack.rfind(needle, position1, 3); + position2 = haystack.rfind(needle, position2, 3); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10, 3); + position2 = haystack.rfind(needle, haystack.size() - 10, 3); + CHECK_EQUAL(position1, position2); + + position2 = haystack.rfind(STR("pin"), 3); + CHECK_EQUAL(IText::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_c_position) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); + + TextBufferL buffer{0}; + Text haystack(the_haystack, buffer.data(), buffer.size()); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(STR('e'), position1); + position2 = haystack.rfind(STR('e'), position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); + position2 = haystack.rfind(STR('e'), haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + position2 = haystack.rfind(STR('z')); + CHECK_EQUAL(IText::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_string) + { + TextSTD compare_text(STR("ABCDEF")); + + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(TextL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(TextL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(TextL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(TextL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(TextL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_etl_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_std_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, TextL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, TextL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, TextL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, TextL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, TextL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10, 3); - position2 = haystack.rfind(needle, haystack.size() - 10, 3); - CHECK_EQUAL(position1, position2); + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); - position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(IText::npos, position2); + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_c_position) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - std::u16string compare_haystack(the_haystack); + int compare_result; + int result; - TextBufferL buffer{0}; - Text haystack(the_haystack, buffer.data(), buffer.size()); + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); - size_t position1 = std::u16string::npos; - size_t position2 = etl::u16string<50>::npos; + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(STR('e'), position1); - position2 = haystack.rfind(STR('e'), position2); - CHECK_EQUAL(position1, position2); + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); - position2 = haystack.rfind(STR('e'), haystack.size() - 10); - CHECK_EQUAL(position1, position2); + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); - position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(IText::npos, position2); + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); - result = text.compare(TextL(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); - result = text.compare(TextL(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); - result = text.compare(TextL(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); - result = text.compare(TextL(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); - result = text.compare(TextL(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); - + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3717,36 +4796,36 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); - result = text.compare(3, 6, TextL(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); - result = text.compare(3, 6, TextL(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); - result = text.compare(3, 6, TextL(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); - result = text.compare(3, 6, TextL(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); - result = text.compare(3, 6, TextL(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); - + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3754,35 +4833,36 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3819,7 +4899,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3856,7 +4936,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3893,38 +4973,100 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(ViewETL(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3955,7 +5097,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3991,7 +5133,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4032,43 +5174,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4109,7 +5323,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4139,16 +5353,18 @@ namespace CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); position2 = text.find_last_of(STR("ZCXE"), 100, 4); CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4189,43 +5405,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4261,7 +5549,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4302,7 +5590,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4343,43 +5631,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4415,7 +5775,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4449,7 +5809,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 31f9fdad6..2d9ef3229 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -66,21 +66,21 @@ namespace { static const size_t SIZE = 11; - using Text = etl::u32string; - using IText = etl::iu32string; - using CompareText = std::u32string; - using value_t = Text::value_type; - using TextL = etl::u32string<52>; - using TextS = etl::u32string<4>; - - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using Text = etl::u32string; + using IText = etl::iu32string; + using TextSTD = std::u32string; + using value_t = Text::value_type; + using TextL = etl::u32string<52>; + using TextS = etl::u32string<4>; + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; using ViewETL = etl::u32string_view; #if ETL_USING_STL && ETL_USING_CPP17 using ViewSTD = std::u32string_view; @@ -147,7 +147,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -175,7 +175,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -191,7 +191,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -207,7 +207,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -223,7 +223,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -239,7 +239,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -255,7 +255,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -271,7 +271,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); @@ -381,8 +381,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); Text text(initial_text.c_str()); Text text2(text, 2, 4); @@ -397,8 +397,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextL textl(longer_text.c_str()); Text text2(textl, 2, 12); @@ -414,7 +414,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; bool is_equal = Equal(compare_text, text); @@ -427,7 +427,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), @@ -558,7 +558,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -572,7 +572,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -587,7 +587,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u32string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -602,7 +602,7 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u32string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); @@ -616,7 +616,7 @@ namespace text = ViewETL(STR("Hello World")); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -631,7 +631,7 @@ namespace text = ViewSTD(STR("Hello World")); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -905,7 +905,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -921,7 +921,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -937,7 +937,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -955,7 +955,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -973,7 +973,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -985,7 +985,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -997,7 +997,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -1009,7 +1009,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -1021,7 +1021,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); @@ -1038,7 +1038,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); const Text text(compare_text.begin(), compare_text.end()); @@ -1055,10 +1055,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1074,11 +1074,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_etl_view) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); ViewETL view(input); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1095,11 +1095,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_std_view) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - ViewSTD view(input.data(), input.data_end()); + ViewSTD view(input.data(), input.size()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1116,10 +1116,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1135,7 +1135,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str()); @@ -1150,7 +1150,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1165,7 +1165,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str(), initial_text.size()); @@ -1180,7 +1180,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1197,7 +1197,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1269,7 +1269,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1295,7 +1295,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1326,7 +1326,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1350,7 +1350,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1370,7 +1370,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); const value_t INITIAL_VALUE = STR('A'); @@ -1415,7 +1415,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INITIAL_SIZE = 5; @@ -1441,7 +1441,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INSERT_SIZE = 4; @@ -1514,7 +1514,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1537,7 +1537,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; size_t offset = 0; @@ -1595,7 +1595,7 @@ namespace for (size_t offset = 10; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); @@ -1614,7 +1614,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1635,9 +1635,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewETL view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1657,9 +1657,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewSTD view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewSTD view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1679,7 +1679,7 @@ namespace { for (size_t offset = 0; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1700,7 +1700,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(longer_text.begin(), longer_text.end()); insert.erase(insert.begin(), insert.end()); @@ -1721,7 +1721,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1767,7 +1767,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1800,9 +1800,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_etl_view) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewETL view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1817,7 +1817,7 @@ namespace // Overflow. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - view.assign(initial_text.data(), initial_text.data() + initial_text.size()); + view.assign(initial_text.data(), initial_text.size()); compare_text.append(initial_text); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -1834,9 +1834,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_std_view) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewSTD append(insert_text.data(), insert_text.data() + insert_text.size()); + ViewSTD append(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1851,7 +1851,7 @@ namespace // Overflow. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.data() + initial_text.size()); + append = ViewSTD(initial_text.data(), initial_text.size()); compare_text.append(initial_text); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -1885,7 +1885,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1916,7 +1916,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1980,7 +1980,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -2012,7 +2012,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -2044,7 +2044,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -2077,10 +2077,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2094,7 +2094,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2108,7 +2108,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2122,7 +2122,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2136,7 +2136,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2150,7 +2150,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2164,7 +2164,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2179,10 +2179,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace"))); @@ -2196,7 +2196,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace"))); @@ -2210,7 +2210,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace with some text"))); @@ -2224,7 +2224,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); @@ -2238,7 +2238,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewETL(STR("Replace"))); @@ -2252,7 +2252,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace with some text"))); @@ -2266,7 +2266,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); @@ -2282,10 +2282,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace"))); @@ -2299,7 +2299,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace"))); @@ -2313,7 +2313,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace with some text"))); @@ -2327,7 +2327,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); @@ -2341,7 +2341,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewSTD(STR("Replace"))); @@ -2355,7 +2355,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace with some text"))); @@ -2369,7 +2369,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); @@ -2385,10 +2385,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -2402,7 +2402,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2416,7 +2416,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2430,7 +2430,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2445,10 +2445,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); @@ -2462,7 +2462,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); @@ -2476,7 +2476,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); @@ -2490,7 +2490,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); @@ -2506,10 +2506,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); @@ -2523,7 +2523,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); @@ -2537,7 +2537,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); @@ -2551,7 +2551,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); @@ -2567,10 +2567,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2584,7 +2584,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2598,7 +2598,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2612,7 +2612,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2626,7 +2626,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2640,7 +2640,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2654,7 +2654,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2668,7 +2668,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2683,10 +2683,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); @@ -2700,7 +2700,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); @@ -2714,7 +2714,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); @@ -2728,7 +2728,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); @@ -2742,7 +2742,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); @@ -2756,7 +2756,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); @@ -2770,7 +2770,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); @@ -2784,7 +2784,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); @@ -2800,10 +2800,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); @@ -2817,7 +2817,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); @@ -2831,7 +2831,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); @@ -2845,7 +2845,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); @@ -2859,7 +2859,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); @@ -2873,7 +2873,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); @@ -2887,7 +2887,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); @@ -2901,7 +2901,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); @@ -2917,7 +2917,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, STR("Replace")); @@ -2934,7 +2934,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace")); @@ -2962,7 +2962,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text")); @@ -2990,7 +2990,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace")); @@ -3018,7 +3018,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text")); @@ -3033,7 +3033,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); @@ -3093,7 +3093,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, STR("Replace"), 5); @@ -3110,7 +3110,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace"), 5); @@ -3138,7 +3138,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text"), 15); @@ -3166,7 +3166,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace"), 5); @@ -3194,7 +3194,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text"), 15); @@ -3209,7 +3209,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); @@ -3277,7 +3277,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -3294,7 +3294,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -3322,7 +3322,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -3350,7 +3350,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -3378,7 +3378,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -3393,7 +3393,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); @@ -3453,11 +3453,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3515,10 +3515,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); Text::iterator ditr = text.erase(text.begin() + 2); CHECK(*citr == *ditr); @@ -3532,10 +3532,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); Text::iterator ditr = text.erase(text.cbegin() + 2); CHECK(*citr == *ditr); @@ -3549,10 +3549,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); CHECK(*citr == *ditr); @@ -3578,7 +3578,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); @@ -3591,7 +3591,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); @@ -3604,7 +3604,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); @@ -3617,7 +3617,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); @@ -3804,7 +3804,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3845,13 +3845,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3871,7 +3871,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3899,11 +3899,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); - etl::u32string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3917,11 +3917,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u32string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u32string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3929,12 +3929,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); - etl::u32string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); ViewETL needle_view(needle); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3948,12 +3948,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(etl::u32string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u32string<50> pin(STR("pin")); - ViewETL pin_view(pin); + ViewETL pin_view(STR("pin")); position2 = haystack.find(pin_view); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -3962,12 +3961,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); - std::u32string needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); ViewSTD needle_view(needle); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3981,12 +3980,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(etl::u32string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - std::u32string pin(STR("pin")); - ViewSTD pin_view(pin); + ViewSTD pin_view(STR("pin")); position2 = haystack.find(pin_view); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #endif @@ -3997,8 +3995,8 @@ namespace const value_t* needle = STR("needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -4012,11 +4010,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4026,8 +4024,8 @@ namespace const value_t* needle = STR("needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -4041,11 +4039,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4053,14 +4051,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); - etl::u32string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -4070,9 +4068,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u32string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4080,28 +4078,27 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); - etl::u32string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); ViewETL needle_view(needle); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle_view, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle, haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u32string<50> pin(STR("pin")); - ViewETL pin_view(pin); - position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + ViewETL pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -4110,15 +4107,15 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); - std::u32string needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); ViewSTD needle_view(needle); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle_view, position2); @@ -4128,10 +4125,9 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - std::u32string pin(STR("pin")); - ViewSTD pin_view(pin); + ViewSTD pin_view(STR("pin")); position2 = haystack.rfind(pin_view); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #endif @@ -4140,13 +4136,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -4156,9 +4152,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u32string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4166,13 +4162,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -4183,7 +4179,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4191,11 +4187,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); - etl::u32string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -4206,16 +4202,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::iu32string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -4250,34 +4246,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4285,34 +4281,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_etl_view) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(ViewETL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(ViewETL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(ViewETL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(ViewETL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(ViewETL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4321,34 +4317,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_std_view) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(ViewSTD(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(ViewSTD(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(ViewSTD(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(ViewSTD(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(ViewSTD(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4357,34 +4353,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4392,34 +4388,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, ViewETL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4428,34 +4424,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4464,34 +4460,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4499,34 +4495,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4535,34 +4531,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4571,7 +4567,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -4606,7 +4602,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -4641,7 +4637,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -4676,26 +4672,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(Text(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(Text(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(Text(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(Text(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4705,26 +4701,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(ViewETL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4735,26 +4731,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4765,7 +4761,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -4794,7 +4790,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -4828,7 +4824,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -4867,31 +4863,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(Text(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(Text(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(Text(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4901,31 +4897,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4936,31 +4932,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4971,7 +4967,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -5010,7 +5006,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -5047,7 +5043,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -5086,31 +5082,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5120,31 +5116,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5155,31 +5151,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5190,7 +5186,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -5224,7 +5220,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -5263,7 +5259,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -5302,31 +5298,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5336,31 +5332,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5371,31 +5367,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5406,7 +5402,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -5440,7 +5436,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -5472,7 +5468,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 966500158..2461206b2 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -72,20 +72,25 @@ namespace using Text = etl::u32string_ext; using IText = etl::iu32string; using TextL = etl::u32string; - using CompareText = std::u32string; + using TextSTD = std::u32string; using value_t = Text::value_type; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using ViewETL = etl::u32string_view; +#if ETL_USING_STL && ETL_USING_CPP17 + using ViewSTD = std::u32string_view; +#endif + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -200,9 +205,9 @@ namespace TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -212,11 +217,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -246,7 +251,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -262,7 +267,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -279,7 +284,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -296,7 +301,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -313,7 +318,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -330,7 +335,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -347,7 +352,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -387,10 +392,23 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u32string_view view(initial_text.data(), initial_text.size()); + ViewETL view(initial_text.data(), initial_text.size()); + TextBuffer buffer{0}; + Text text(view, buffer.data(), buffer.size()); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK(text.size() == SIZE); + CHECK(!text.empty()); + } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) + { + ViewSTD view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -399,6 +417,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -463,8 +482,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -482,8 +501,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -502,7 +521,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -518,12 +537,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; TextBuffer buffer{0}; Text text(il, buffer.data(), buffer.size()); @@ -671,7 +690,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -686,7 +705,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u32string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -702,7 +721,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u32string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -718,13 +737,45 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u32string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = ViewETL(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = ViewSTD(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -738,6 +789,7 @@ namespace CHECK_EQUAL(&constText[0], constText.begin()); } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_end) { @@ -846,7 +898,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 8; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -890,7 +942,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 2; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -916,24 +968,6 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_fill) - { - TextBuffer buffer1{ 0 }; - TextBuffer buffer2{ 0 }; - Text text(11, STR('A'), buffer1.data(), buffer1.size()); - Text expected(11, STR('B'), buffer2.data(), buffer2.size()); - - text.fill(STR('B')); - - bool is_equal = Equal(expected, text); - CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_full) { @@ -1013,7 +1047,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1031,7 +1065,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1049,7 +1083,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1069,7 +1103,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1089,7 +1123,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1103,7 +1137,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1117,7 +1151,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1131,7 +1165,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1145,7 +1179,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1163,7 +1197,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1181,12 +1215,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1201,15 +1235,61 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_etl_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + ViewETL view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_std_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + ViewSTD view(input.data(), input.size()); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1227,7 +1307,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1243,7 +1323,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1259,7 +1339,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1275,7 +1355,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1293,7 +1373,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1369,7 +1449,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1397,7 +1477,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1430,7 +1510,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1452,11 +1532,11 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1478,7 +1558,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1524,7 +1604,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1551,7 +1631,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1625,7 +1705,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1649,7 +1729,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1708,7 +1788,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1729,13 +1809,12 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2; - buffer2.fill(0); + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1750,12 +1829,60 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1780,7 +1907,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1806,7 +1933,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1856,7 +1983,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1890,6 +2017,76 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_etl_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_std_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + ViewSTD append(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(append); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + append = ViewSTD(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(append); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1913,7 +2110,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1946,7 +2143,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1955,7 +2152,7 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::u32string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -2017,7 +2214,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2051,7 +2248,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2085,7 +2282,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2122,12 +2319,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2141,7 +2338,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2155,7 +2352,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2169,7 +2366,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2183,7 +2380,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2197,7 +2394,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2211,7 +2408,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2223,17 +2420,16 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { - // Non-overflow short text. - CompareText compare_text(short_text.c_str()); - + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + text.replace(2, Text::npos, ViewETL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2241,13 +2437,41 @@ namespace CHECK(!text.is_truncated()); #endif + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2259,9 +2483,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + text.replace(2, 7, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2273,9 +2497,23 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2284,18 +2522,18 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { - // Non-overflow short text. - CompareText compare_text(short_text.c_str()); - + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")), 1, 5); + text.replace(2, Text::npos, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2303,13 +2541,13 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2321,9 +2559,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2335,9 +2573,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2349,23 +2587,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 7, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2377,9 +2601,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2391,9 +2615,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2401,19 +2625,560 @@ namespace CHECK(text.is_truncated()); #endif } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, TextL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2425,9 +3190,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2439,9 +3204,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2453,9 +3218,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2467,9 +3232,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + text.replace(2, 7, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2481,9 +3246,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2495,9 +3260,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2509,9 +3274,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2524,14 +3289,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2543,9 +3308,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2557,9 +3322,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2571,9 +3336,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2586,14 +3351,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2605,9 +3370,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2619,9 +3384,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2633,9 +3398,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2647,9 +3412,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2661,9 +3426,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2675,9 +3440,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2689,9 +3454,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2704,14 +3469,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2725,9 +3490,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2741,9 +3506,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2757,9 +3522,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2774,7 +3539,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2793,7 +3558,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2821,7 +3586,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2849,7 +3614,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2877,7 +3642,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2892,7 +3657,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2954,13 +3719,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3016,33 +3781,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); - TextBuffer buffer{0}; - Text text(initial_text.c_str(), buffer.data(), buffer.size()); + TextSTD compare_text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); - Text::iterator ditr = text.erase(text.begin() + 2); - CHECK(*citr == *ditr); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) - { - CompareText compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); - Text::iterator ditr = text.erase(text.cbegin() + 2); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2); + text.erase(text.begin() + 2); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3054,13 +3801,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); - Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); + + text.erase(text.begin() + 2, text.begin() + 4); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3085,7 +3833,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3100,7 +3848,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3115,7 +3863,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3130,7 +3878,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3196,7 +3944,7 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); TextBuffer buffer3; @@ -3213,17 +3961,17 @@ namespace CHECK((initial < initial) == (initial_text < initial_text)); // String-Pointer Pointer-String - CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((less < pinitial_text) == (less_text < pinitial_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); - CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); - CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); - CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3236,8 +3984,8 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); TextBuffer buffer3; const Text greater(greater_text.c_str(), buffer3.data(), buffer3.size()); @@ -3253,17 +4001,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3293,17 +4041,17 @@ namespace CHECK((initial > initial) == (initial_text > initial_text)); // String-Pointer Pointer-String - CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((less > pinitial_text) == (less_text > pinitial_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); - CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); - CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); - CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3316,8 +4064,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end(), buffer2.data(), buffer2.size()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); TextBuffer buffer3; const Text greater(greater_text.begin(), greater_text.end(), buffer3.data(), buffer3.size()); @@ -3333,24 +4081,24 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); - + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3369,8 +4117,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3393,7 +4141,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3401,7 +4149,7 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3413,15 +4161,15 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3441,8 +4189,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3451,12 +4199,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3473,13 +4221,77 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u32string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u32string<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewETL needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + ViewETL pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_std_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewSTD needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + ViewSTD pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3487,7 +4299,7 @@ namespace const value_t* needle = STR("needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3506,7 +4318,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } @@ -3518,7 +4330,7 @@ namespace const value_t* needle = STR("needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3537,7 +4349,7 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(IText::npos, position2); } @@ -3547,18 +4359,18 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3575,19 +4387,76 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_pointer) + TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewETL needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + ViewETL pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_std_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); + ViewSTD needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + ViewSTD pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_pointer) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3606,16 +4475,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u32string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u32string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; @@ -3632,72 +4501,294 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_c_position) + TEST_FIXTURE(SetupFixture, test_rfind_c_position) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); + + TextBufferL buffer{0}; + Text haystack(the_haystack, buffer.data(), buffer.size()); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(STR('e'), position1); + position2 = haystack.rfind(STR('e'), position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); + position2 = haystack.rfind(STR('e'), haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + position2 = haystack.rfind(STR('z')); + CHECK_EQUAL(IText::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_string) + { + TextSTD compare_text(STR("ABCDEF")); + + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(TextL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(TextL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(TextL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(TextL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(TextL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_etl_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_std_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, TextL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, TextL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, TextL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, TextL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, TextL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - std::u32string compare_haystack(the_haystack); + int compare_result; + int result; - TextBufferL buffer{0}; - Text haystack(the_haystack, buffer.data(), buffer.size()); + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); - size_t position1 = std::u32string::npos; - size_t position2 = etl::u32string<50>::npos; + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(STR('e'), position1); - position2 = haystack.rfind(STR('e'), position2); - CHECK_EQUAL(position1, position2); + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); - position2 = haystack.rfind(STR('e'), haystack.size() - 10); - CHECK_EQUAL(position1, position2); + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); - position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(IText::npos, position2); + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); - result = text.compare(TextL(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); - result = text.compare(TextL(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); - result = text.compare(TextL(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); - result = text.compare(TextL(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); - result = text.compare(TextL(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); - + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3705,36 +4796,36 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); - result = text.compare(3, 6, TextL(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); - result = text.compare(3, 6, TextL(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); - result = text.compare(3, 6, TextL(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); - result = text.compare(3, 6, TextL(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); - result = text.compare(3, 6, TextL(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); - + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3742,35 +4833,36 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3807,7 +4899,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3844,7 +4936,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3881,38 +4973,100 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(ViewETL(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3943,7 +5097,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3979,7 +5133,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4020,43 +5174,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4097,7 +5323,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4127,16 +5353,18 @@ namespace CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); position2 = text.find_last_of(STR("ZCXE"), 100, 4); CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4177,43 +5405,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4249,7 +5549,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4290,7 +5590,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4331,43 +5631,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4403,7 +5775,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4437,7 +5809,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4712,6 +6084,23 @@ namespace CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_secure_after_clear) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.set_secure(); + text.assign(STR("ABCDEF")); + + Text::pointer pb = text.begin(); + Text::pointer pe = text.end(); + + text.clear(); + + // Check there no non-zero values in the remainder of the string. + CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_secure_flag_after_copy) { diff --git a/test/test_string_u8.cpp b/test/test_string_u8.cpp index 361ae40d0..84020bbd8 100644 --- a/test/test_string_u8.cpp +++ b/test/test_string_u8.cpp @@ -69,25 +69,25 @@ namespace { static const size_t SIZE = 11; - using Text = etl::u8string; - using IText = etl::iu8string; - using CompareText = std::u8string; - using value_t = Text::value_type; - using TextL = etl::u8string<52>; - using TextS = etl::u8string<4>; - using ViewETL = etl::u8string_view; + using Text = etl::u8string; + using IText = etl::iu8string; + using TextSTD = std::u8string; + using value_t = Text::value_type; + using TextL = etl::u8string<52>; + using TextS = etl::u8string<4>; + using ViewETL = etl::u8string_view; #if ETL_USING_STL && ETL_USING_CPP17 - using ViewSTD = std::u8string_view; + using ViewSTD = std::u8string_view; #endif - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -150,7 +150,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -178,7 +178,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -194,7 +194,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -210,7 +210,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -226,7 +226,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -242,7 +242,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -258,7 +258,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -274,7 +274,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); @@ -384,8 +384,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); Text text(initial_text.c_str()); Text text2(text, 2, 4); @@ -400,8 +400,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextL textl(longer_text.c_str()); Text text2(textl, 2, 12); @@ -417,7 +417,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; bool is_equal = Equal(compare_text, text); @@ -430,7 +430,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), @@ -561,7 +561,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -575,7 +575,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -590,7 +590,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u8string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -605,7 +605,7 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u8string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); @@ -619,7 +619,7 @@ namespace text = ViewETL(STR("Hello World")); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -634,7 +634,7 @@ namespace text = ViewSTD(STR("Hello World")); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -908,7 +908,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -924,7 +924,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -940,7 +940,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -958,7 +958,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -976,7 +976,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -988,7 +988,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -1000,7 +1000,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -1012,7 +1012,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -1024,7 +1024,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); @@ -1041,7 +1041,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); const Text text(compare_text.begin(), compare_text.end()); @@ -1058,10 +1058,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1077,11 +1077,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_etl_view) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); ViewETL view(input); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1098,11 +1098,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_std_view) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - ViewSTD view(input.data(), input.data_end()); + ViewSTD view(input.data(), input.size()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1119,10 +1119,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1138,7 +1138,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str()); @@ -1153,7 +1153,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1168,7 +1168,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str(), initial_text.size()); @@ -1183,7 +1183,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1200,7 +1200,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1272,7 +1272,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1298,7 +1298,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1329,7 +1329,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1353,7 +1353,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1373,7 +1373,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); const value_t INITIAL_VALUE = STR('A'); @@ -1418,7 +1418,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INITIAL_SIZE = 5; @@ -1444,7 +1444,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INSERT_SIZE = 4; @@ -1517,7 +1517,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1540,7 +1540,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; size_t offset = 0; @@ -1598,7 +1598,7 @@ namespace for (size_t offset = 10; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); @@ -1617,7 +1617,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1638,9 +1638,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewETL view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1660,9 +1660,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewSTD view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewSTD view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1682,7 +1682,7 @@ namespace { for (size_t offset = 0; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1703,7 +1703,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(longer_text.begin(), longer_text.end()); insert.erase(insert.begin(), insert.end()); @@ -1724,7 +1724,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1770,7 +1770,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1803,9 +1803,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_etl_view) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewETL view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1820,7 +1820,7 @@ namespace // Overflow. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - view.assign(initial_text.data(), initial_text.data() + initial_text.size()); + view.assign(initial_text.data(), initial_text.size()); compare_text.append(initial_text); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -1837,9 +1837,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_std_view) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewSTD append(insert_text.data(), insert_text.data() + insert_text.size()); + ViewSTD append(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1854,7 +1854,7 @@ namespace // Overflow. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.data() + initial_text.size()); + append = ViewSTD(initial_text.data(), initial_text.size()); compare_text.append(initial_text); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -1888,7 +1888,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1919,7 +1919,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1983,7 +1983,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -2015,7 +2015,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -2047,7 +2047,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -2080,10 +2080,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2097,7 +2097,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2111,7 +2111,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2125,7 +2125,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2139,7 +2139,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2153,7 +2153,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2167,7 +2167,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2182,10 +2182,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace"))); @@ -2199,7 +2199,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace"))); @@ -2213,7 +2213,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace with some text"))); @@ -2227,7 +2227,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); @@ -2241,7 +2241,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewETL(STR("Replace"))); @@ -2255,7 +2255,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace with some text"))); @@ -2269,7 +2269,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); @@ -2285,10 +2285,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace"))); @@ -2302,7 +2302,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace"))); @@ -2316,7 +2316,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace with some text"))); @@ -2330,7 +2330,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); @@ -2344,7 +2344,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewSTD(STR("Replace"))); @@ -2358,7 +2358,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace with some text"))); @@ -2372,7 +2372,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); @@ -2388,10 +2388,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -2405,7 +2405,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2419,7 +2419,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2433,7 +2433,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2448,10 +2448,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); @@ -2465,7 +2465,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); @@ -2479,7 +2479,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); @@ -2493,7 +2493,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); @@ -2509,10 +2509,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); @@ -2526,7 +2526,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); @@ -2540,7 +2540,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); @@ -2554,7 +2554,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); @@ -2570,10 +2570,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2587,7 +2587,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2601,7 +2601,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2615,7 +2615,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2629,7 +2629,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2643,7 +2643,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2657,7 +2657,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2671,7 +2671,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2686,10 +2686,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); @@ -2703,7 +2703,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); @@ -2717,7 +2717,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); @@ -2731,7 +2731,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); @@ -2745,7 +2745,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); @@ -2759,7 +2759,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); @@ -2773,7 +2773,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); @@ -2787,7 +2787,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); @@ -2803,10 +2803,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); @@ -2820,7 +2820,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); @@ -2834,7 +2834,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); @@ -2848,7 +2848,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); @@ -2862,7 +2862,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); @@ -2876,7 +2876,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); @@ -2890,7 +2890,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); @@ -2904,7 +2904,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); @@ -2920,10 +2920,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str()); @@ -2937,7 +2937,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2951,7 +2951,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2965,7 +2965,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2979,7 +2979,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str()); @@ -2993,7 +2993,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -3007,7 +3007,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -3021,7 +3021,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -3036,10 +3036,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); @@ -3053,7 +3053,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -3067,7 +3067,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); @@ -3081,7 +3081,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -3096,10 +3096,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); @@ -3113,7 +3113,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -3127,7 +3127,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -3141,7 +3141,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -3155,7 +3155,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); @@ -3169,7 +3169,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -3183,7 +3183,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -3197,7 +3197,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -3212,10 +3212,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); @@ -3231,7 +3231,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -3247,7 +3247,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); @@ -3263,7 +3263,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -3280,7 +3280,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -3297,7 +3297,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -3325,7 +3325,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -3353,7 +3353,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -3381,7 +3381,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -3396,7 +3396,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); @@ -3456,11 +3456,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3518,10 +3518,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); Text::iterator ditr = text.erase(text.begin() + 2); CHECK(*citr == *ditr); @@ -3535,10 +3535,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); Text::iterator ditr = text.erase(text.cbegin() + 2); CHECK(*citr == *ditr); @@ -3552,10 +3552,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); CHECK(*citr == *ditr); @@ -3581,7 +3581,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); @@ -3594,7 +3594,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); @@ -3607,7 +3607,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); @@ -3620,7 +3620,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); @@ -3807,7 +3807,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3848,13 +3848,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3874,7 +3874,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3902,11 +3902,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); - etl::u8string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3920,11 +3920,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u8string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u8string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3932,12 +3932,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); - etl::u8string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); ViewETL needle_view(needle); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3951,12 +3951,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(etl::u8string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u8string<50> pin(STR("pin")); - ViewETL pin_view(pin); + ViewETL pin_view(STR("pin")); position2 = haystack.find(pin_view); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -3965,12 +3964,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); - std::u8string needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); ViewSTD needle_view(needle); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3984,12 +3983,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(etl::u8string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - std::u8string pin(STR("pin")); - ViewSTD pin_view(pin); + ViewSTD pin_view(STR("pin")); position2 = haystack.find(pin_view); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #endif @@ -4000,8 +3998,8 @@ namespace const value_t* needle = STR("needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -4015,11 +4013,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4029,8 +4027,8 @@ namespace const value_t* needle = STR("needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -4044,11 +4042,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4056,14 +4054,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); - etl::u8string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -4073,9 +4071,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u8string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4083,28 +4081,27 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); - etl::u8string<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); ViewETL needle_view(needle); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle_view, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle, haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u8string<50> pin(STR("pin")); - ViewETL pin_view(pin); - position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + ViewETL pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -4113,15 +4110,15 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); - std::u8string needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); ViewSTD needle_view(needle); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle_view, position2); @@ -4131,10 +4128,9 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - std::u8string pin(STR("pin")); - ViewSTD pin_view(pin); + ViewSTD pin_view(STR("pin")); position2 = haystack.rfind(pin_view); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #endif @@ -4143,13 +4139,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -4159,9 +4155,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::u8string<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4169,13 +4165,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -4186,7 +4182,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4194,11 +4190,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); - etl::u8string<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -4209,16 +4205,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::iu8string::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -4253,34 +4249,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4288,34 +4284,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_etl_view) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(ViewETL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(ViewETL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(ViewETL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(ViewETL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(ViewETL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4324,34 +4320,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_std_view) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(ViewSTD(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(ViewSTD(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(ViewSTD(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(ViewSTD(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(ViewSTD(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4360,34 +4356,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4395,34 +4391,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, ViewETL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4431,34 +4427,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4467,34 +4463,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4502,34 +4498,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4538,34 +4534,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4574,7 +4570,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -4609,7 +4605,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -4644,7 +4640,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -4679,26 +4675,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(Text(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(Text(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(Text(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(Text(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4708,26 +4704,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(ViewETL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4738,26 +4734,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4768,7 +4764,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -4797,7 +4793,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -4831,7 +4827,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -4870,31 +4866,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(Text(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(Text(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(Text(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4904,31 +4900,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4939,31 +4935,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4974,7 +4970,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -5013,7 +5009,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -5050,7 +5046,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -5089,31 +5085,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5123,31 +5119,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5158,31 +5154,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5193,7 +5189,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -5227,7 +5223,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -5266,7 +5262,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -5305,31 +5301,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5339,31 +5335,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5374,31 +5370,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5409,7 +5405,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -5443,7 +5439,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -5475,7 +5471,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); diff --git a/test/test_string_u8_external_buffer.cpp b/test/test_string_u8_external_buffer.cpp index bc2caaaf4..d0a02373c 100644 --- a/test/test_string_u8_external_buffer.cpp +++ b/test/test_string_u8_external_buffer.cpp @@ -75,20 +75,25 @@ namespace using Text = etl::u8string_ext; using IText = etl::iu8string; using TextL = etl::u8string; - using CompareText = std::u8string; + using TextSTD = std::u8string; using value_t = Text::value_type; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using ViewETL = etl::u8string_view; +#if ETL_USING_STL && ETL_USING_CPP17 + using ViewSTD = std::u8string_view; +#endif + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -203,9 +208,9 @@ namespace TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -215,11 +220,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -249,7 +254,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -265,7 +270,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -282,7 +287,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -299,7 +304,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -316,7 +321,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -333,7 +338,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -350,7 +355,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -390,10 +395,23 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::u8string_view view(initial_text.data(), initial_text.size()); + ViewETL view(initial_text.data(), initial_text.size()); + TextBuffer buffer{0}; + Text text(view, buffer.data(), buffer.size()); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK(text.size() == SIZE); + CHECK(!text.empty()); + } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) + { + ViewSTD view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -402,6 +420,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -466,8 +485,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -485,8 +504,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -505,7 +524,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -521,12 +540,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; TextBuffer buffer{0}; Text text(il, buffer.data(), buffer.size()); @@ -674,7 +693,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -689,7 +708,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::u8string(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -705,7 +724,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::u8string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -721,13 +740,45 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::u8string(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = ViewETL(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = ViewSTD(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -850,7 +901,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 8; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -894,7 +945,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 2; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -920,24 +971,6 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_fill) - { - TextBuffer buffer1{ 0 }; - TextBuffer buffer2{ 0 }; - Text text(11, STR('A'), buffer1.data(), buffer1.size()); - Text expected(11, STR('B'), buffer2.data(), buffer2.size()); - - text.fill(STR('B')); - - bool is_equal = Equal(expected, text); - CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_full) { @@ -1017,7 +1050,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1035,7 +1068,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1053,7 +1086,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1073,7 +1106,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1093,7 +1126,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1107,7 +1140,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1121,7 +1154,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1135,7 +1168,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1149,7 +1182,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1167,7 +1200,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1185,12 +1218,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1205,15 +1238,61 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_etl_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + ViewETL view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_std_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + ViewSTD view(input.data(), input.size()); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1231,7 +1310,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1247,7 +1326,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1263,7 +1342,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1279,7 +1358,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1297,7 +1376,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1373,7 +1452,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1401,7 +1480,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1434,7 +1513,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1456,11 +1535,11 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1482,7 +1561,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1528,7 +1607,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1555,7 +1634,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1629,7 +1708,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1653,7 +1732,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1712,7 +1791,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1731,18 +1810,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string) { - size_t s = short_text.size(); - (void)s; - - assert(s <= 5); - - for (size_t offset = s; offset <= short_text.size(); ++offset) + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1758,23 +1833,64 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_2) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } } +#endif - //************************************************************************* + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { -#include "etl/private/diagnostic_array_bounds_push.h" for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); - TextBuffer buffer{ 0 }; + TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); - TextBuffer buffer2{ 0 }; + TextBuffer buffer2{0}; Text insert(insert_text.begin(), insert_text.end(), buffer2.data(), buffer2.size()); text.insert(offset, insert); @@ -1787,7 +1903,6 @@ namespace CHECK(text.is_truncated()); #endif } -#include "etl/private/diagnostic_pop.h" } //************************************************************************* @@ -1795,7 +1910,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1821,7 +1936,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1871,7 +1986,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1905,6 +2020,76 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_etl_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_std_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + ViewSTD append(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(append); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + append = ViewSTD(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(append); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1928,7 +2113,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1961,7 +2146,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1970,7 +2155,7 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::u8string::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -2032,7 +2217,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2066,7 +2251,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2100,7 +2285,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2137,12 +2322,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2156,7 +2341,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2170,7 +2355,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2184,7 +2369,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2198,7 +2383,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2212,7 +2397,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2226,7 +2411,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2238,17 +2423,16 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { - // Non-overflow short text. - CompareText compare_text(short_text.c_str()); - + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + text.replace(2, Text::npos, ViewETL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2256,13 +2440,41 @@ namespace CHECK(!text.is_truncated()); #endif + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2274,9 +2486,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + text.replace(2, 7, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2288,9 +2500,23 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2299,18 +2525,18 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { - // Non-overflow short text. - CompareText compare_text(short_text.c_str()); - + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")), 1, 5); + text.replace(2, Text::npos, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2318,13 +2544,13 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2336,9 +2562,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2350,9 +2576,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2364,23 +2590,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 7, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2392,9 +2604,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2406,9 +2618,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2416,17 +2628,558 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, TextL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str()); @@ -2440,7 +3193,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2454,7 +3207,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2468,7 +3221,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2482,7 +3235,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str()); @@ -2496,7 +3249,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); @@ -2510,7 +3263,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); @@ -2524,7 +3277,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); @@ -2539,12 +3292,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); @@ -2558,7 +3311,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -2572,7 +3325,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); @@ -2586,7 +3339,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); @@ -2601,12 +3354,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); @@ -2620,7 +3373,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -2634,7 +3387,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2648,7 +3401,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -2662,7 +3415,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); @@ -2676,7 +3429,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); @@ -2690,7 +3443,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2704,7 +3457,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); @@ -2719,12 +3472,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); @@ -2740,7 +3493,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2756,7 +3509,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace")).c_str(), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); @@ -2772,7 +3525,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str(), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); @@ -2789,7 +3542,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2808,7 +3561,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2836,7 +3589,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2864,7 +3617,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2892,7 +3645,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2907,7 +3660,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2969,13 +3722,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3031,33 +3784,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); - TextBuffer buffer{0}; - Text text(initial_text.c_str(), buffer.data(), buffer.size()); + TextSTD compare_text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); - Text::iterator ditr = text.erase(text.begin() + 2); - CHECK(*citr == *ditr); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) - { - CompareText compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); - Text::iterator ditr = text.erase(text.cbegin() + 2); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2); + text.erase(text.begin() + 2); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3069,13 +3804,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); - Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); + + text.erase(text.begin() + 2, text.begin() + 4); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3100,7 +3836,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3115,7 +3851,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3130,7 +3866,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3145,7 +3881,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3211,7 +3947,7 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); TextBuffer buffer3; @@ -3228,17 +3964,17 @@ namespace CHECK((initial < initial) == (initial_text < initial_text)); // String-Pointer Pointer-String - CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((less < pinitial_text) == (less_text < pinitial_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); - CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); - CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); - CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3251,8 +3987,8 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); TextBuffer buffer3; const Text greater(greater_text.c_str(), buffer3.data(), buffer3.size()); @@ -3268,17 +4004,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3308,17 +4044,17 @@ namespace CHECK((initial > initial) == (initial_text > initial_text)); // String-Pointer Pointer-String - CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((less > pinitial_text) == (less_text > pinitial_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); - CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); - CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); - CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3331,8 +4067,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end(), buffer2.data(), buffer2.size()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); TextBuffer buffer3; const Text greater(greater_text.begin(), greater_text.end(), buffer3.data(), buffer3.size()); @@ -3348,24 +4084,24 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); - + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3384,8 +4120,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3408,7 +4144,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3416,7 +4152,7 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3428,15 +4164,15 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3456,8 +4192,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3466,12 +4202,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3488,13 +4224,77 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::u8string<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::u8string<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewETL needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + ViewETL pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_std_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewSTD needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + ViewSTD pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3502,7 +4302,7 @@ namespace const value_t* needle = STR("needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3521,7 +4321,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } @@ -3533,7 +4333,7 @@ namespace const value_t* needle = STR("needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3552,7 +4352,7 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(IText::npos, position2); } @@ -3562,18 +4362,18 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3590,19 +4390,76 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_pointer) + TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewETL needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + ViewETL pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_std_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); + ViewSTD needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + ViewSTD pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_pointer) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3621,98 +4478,320 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::u8string compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::u8string::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; - position1 = compare_haystack.rfind(needle, position1, 3); - position2 = haystack.rfind(needle, position2, 3); - CHECK_EQUAL(position1, position2); + position1 = compare_haystack.rfind(needle, position1, 3); + position2 = haystack.rfind(needle, position2, 3); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10, 3); + position2 = haystack.rfind(needle, haystack.size() - 10, 3); + CHECK_EQUAL(position1, position2); + + position2 = haystack.rfind(STR("pin"), 3); + CHECK_EQUAL(IText::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_c_position) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); + + TextBufferL buffer{0}; + Text haystack(the_haystack, buffer.data(), buffer.size()); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(STR('e'), position1); + position2 = haystack.rfind(STR('e'), position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); + position2 = haystack.rfind(STR('e'), haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + position2 = haystack.rfind(STR('z')); + CHECK_EQUAL(IText::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_string) + { + TextSTD compare_text(STR("ABCDEF")); + + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(TextL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(TextL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(TextL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(TextL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(TextL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_etl_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_std_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, TextL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, TextL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, TextL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, TextL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, TextL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(needle, compare_haystack.size() - 10, 3); - position2 = haystack.rfind(needle, haystack.size() - 10, 3); - CHECK_EQUAL(position1, position2); + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); - position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(IText::npos, position2); + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_c_position) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - std::u8string compare_haystack(the_haystack); + int compare_result; + int result; - TextBufferL buffer{0}; - Text haystack(the_haystack, buffer.data(), buffer.size()); + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); - size_t position1 = std::u8string::npos; - size_t position2 = etl::u8string<50>::npos; + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(STR('e'), position1); - position2 = haystack.rfind(STR('e'), position2); - CHECK_EQUAL(position1, position2); + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); - position2 = haystack.rfind(STR('e'), haystack.size() - 10); - CHECK_EQUAL(position1, position2); + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); - position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(IText::npos, position2); + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); - result = text.compare(TextL(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); - result = text.compare(TextL(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); - result = text.compare(TextL(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); - result = text.compare(TextL(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); - result = text.compare(TextL(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); - + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3720,36 +4799,36 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); - result = text.compare(3, 6, TextL(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); - result = text.compare(3, 6, TextL(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); - result = text.compare(3, 6, TextL(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); - result = text.compare(3, 6, TextL(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); - result = text.compare(3, 6, TextL(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); - + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3757,35 +4836,36 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3822,7 +4902,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3859,7 +4939,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3896,38 +4976,100 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(ViewETL(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3958,7 +5100,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3994,7 +5136,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4035,43 +5177,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4112,7 +5326,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4142,16 +5356,18 @@ namespace CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); position2 = text.find_last_of(STR("ZCXE"), 100, 4); CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4192,43 +5408,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4264,7 +5552,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4305,7 +5593,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4346,43 +5634,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4418,7 +5778,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4452,7 +5812,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index bff4c2116..27713f899 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -31,6 +31,7 @@ SOFTWARE. #include "etl/string_view.h" #include "etl/string.h" #include "etl/wstring.h" +#include "etl/u8string.h" #include "etl/u16string.h" #include "etl/u32string.h" #include "etl/hash.h" @@ -45,12 +46,18 @@ namespace { using View = etl::string_view; using WView = etl::wstring_view; +#if ETL_USING_CPP20 + using U8View = etl::u8string_view; +#endif using U16View = etl::u16string_view; using U32View = etl::u32string_view; etl::string<11> etltext = "Hello World"; std::string text = "Hello World"; std::wstring wtext = L"Hello World"; +#if ETL_USING_CPP20 + std::u8string u8text = u8"Hello World"; +#endif std::u16string u16text = u"Hello World"; std::u32string u32text = U"Hello World"; std::string text_smaller = "Hello Worlc"; @@ -166,7 +173,7 @@ namespace //************************************************************************* TEST(test_constructor_from_std_string_view) { - std::string_view stdview(etltext.begin(), etltext.end()); + std::string_view stdview(text.data(), text.size()); View view(stdview); @@ -182,7 +189,7 @@ namespace //************************************************************************* TEST(test_constructor_from_std_wstring_view) { - std::wstring_view stdview(wtext.begin(), wtext.end()); + std::wstring_view stdview(wtext.data(), wtext.size()); WView view(stdview); @@ -194,11 +201,27 @@ namespace } #endif +#if ETL_USING_STL && ETL_USING_CPP20 + //************************************************************************* + TEST(test_constructor_from_std_u8string_view) + { + std::u8string_view stdview(u8text.begin(), u8text.end()); + + U8View view(stdview); + + CHECK(stdview.size() == view.size()); + CHECK(stdview.size() == view.max_size()); + + bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); + CHECK(isEqual); + } +#endif + #if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* TEST(test_constructor_from_std_u16string_view) { - std::u16string_view stdview(u16text.begin(), u16text.end()); + std::u16string_view stdview(u16text.data(), u16text.size()); U16View view(stdview); @@ -214,7 +237,7 @@ namespace //************************************************************************* TEST(test_constructor_from_std_u32string_view) { - std::u32string_view stdview(u32text.begin(), u32text.end()); + std::u32string_view stdview(u32text.data(), u32text.size()); U32View view(stdview); diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 862565c0e..b8f51dba4 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -66,21 +66,21 @@ namespace { static const size_t SIZE = 11; - using Text = etl::wstring; - using IText = etl::iwstring; - using CompareText = std::wstring; - using value_t = Text::value_type; - using TextL = etl::wstring<52>; - using TextS = etl::wstring<4>; - - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using Text = etl::wstring; + using IText = etl::iwstring; + using TextSTD = std::wstring; + using value_t = Text::value_type; + using TextL = etl::wstring<52>; + using TextS = etl::wstring<4>; + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; using ViewETL = etl::wstring_view; #if ETL_USING_STL && ETL_USING_CPP17 using ViewSTD = std::wstring_view; @@ -147,7 +147,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE); CHECK(text.size() == INITIAL_SIZE); @@ -175,7 +175,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); @@ -191,7 +191,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(longer_text.c_str()); @@ -207,7 +207,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE, STR('A')); @@ -223,7 +223,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); Text text(SIZE + 1, STR('A')); @@ -239,7 +239,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); Text text(initial_text.c_str(), initial_text.size() / 2); @@ -255,7 +255,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); Text text(longer_text.c_str(), longer_text.size()); @@ -271,7 +271,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(compare_text.begin(), compare_text.end()); @@ -381,8 +381,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); Text text(initial_text.c_str()); Text text2(text, 2, 4); @@ -397,8 +397,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextL textl(longer_text.c_str()); Text text2(textl, 2, 12); @@ -414,7 +414,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; Text text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; bool is_equal = Equal(compare_text, text); @@ -427,7 +427,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; Text text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), @@ -558,7 +558,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -572,7 +572,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -587,7 +587,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::wstring(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -602,7 +602,7 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::wstring(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); @@ -616,7 +616,7 @@ namespace text = ViewETL(STR("Hello World")); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -631,7 +631,7 @@ namespace text = ViewSTD(STR("Hello World")); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -905,7 +905,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -921,7 +921,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -937,7 +937,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -955,7 +955,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); for (size_t i = 0UL; i < text.size(); ++i) @@ -973,7 +973,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -985,7 +985,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.front() == compare_text.front()); @@ -997,7 +997,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -1009,7 +1009,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); const Text text(initial_text.c_str()); CHECK(text.back() == compare_text.back()); @@ -1021,7 +1021,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(compare_text.begin(), compare_text.end()); @@ -1038,7 +1038,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); const Text text(compare_text.begin(), compare_text.end()); @@ -1055,10 +1055,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1074,11 +1074,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_etl_view) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); ViewETL view(input); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1095,11 +1095,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_std_view) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - ViewSTD view(input.data(), input.data_end()); + ViewSTD view(input.data(), input.size()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1116,10 +1116,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextL input(longer_text.c_str()); - CompareText compare_text; + TextSTD compare_text; Text text; compare_text.assign(compare_input); @@ -1135,7 +1135,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str()); @@ -1150,7 +1150,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(longer_text.c_str()); @@ -1165,7 +1165,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; text.assign(initial_text.c_str(), initial_text.size()); @@ -1180,7 +1180,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); Text text; text.assign(longer_text.c_str(), longer_text.size()); @@ -1197,7 +1197,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text; @@ -1269,7 +1269,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1295,7 +1295,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; for (size_t i = 0UL; i < SIZE; ++i) @@ -1326,7 +1326,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); compare_text.pop_back(); @@ -1350,7 +1350,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1370,7 +1370,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); const value_t INITIAL_VALUE = STR('A'); @@ -1415,7 +1415,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INITIAL_SIZE = 5; @@ -1441,7 +1441,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; Text text; const size_t INSERT_SIZE = 4; @@ -1514,7 +1514,7 @@ namespace for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; Text text; text.assign(initial_text.begin(), initial_text.begin() + INITIAL_SIZE); @@ -1537,7 +1537,7 @@ namespace const size_t INITIAL_SIZE = 5; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; Text text; size_t offset = 0; @@ -1595,7 +1595,7 @@ namespace for (size_t offset = 10; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextL text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); text.insert(text.begin() + offset, text.begin() + 5, text.begin() + 10); @@ -1614,7 +1614,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1635,9 +1635,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewETL view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1657,9 +1657,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewSTD view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewSTD view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1679,7 +1679,7 @@ namespace { for (size_t offset = 0; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); Text text(initial_text.begin(), initial_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1700,7 +1700,7 @@ namespace { for (size_t offset = 0; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(longer_text.begin(), longer_text.end()); insert.erase(insert.begin(), insert.end()); @@ -1721,7 +1721,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.begin(), short_text.end()); + TextSTD compare_text(short_text.begin(), short_text.end()); Text text(short_text.begin(), short_text.end()); Text insert(insert_text.begin(), insert_text.end()); @@ -1767,7 +1767,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1800,9 +1800,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_etl_view) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewETL view(insert_text.data(), insert_text.data() + insert_text.size()); + ViewETL view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1817,7 +1817,7 @@ namespace // Overflow. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - view.assign(initial_text.data(), initial_text.data() + initial_text.size()); + view.assign(initial_text.data(), initial_text.size()); compare_text.append(initial_text); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -1834,9 +1834,9 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_std_view) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewSTD append(insert_text.data(), insert_text.data() + insert_text.size()); + ViewSTD append(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1851,7 +1851,7 @@ namespace // Overflow. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.data() + initial_text.size()); + append = ViewSTD(initial_text.data(), initial_text.size()); compare_text.append(initial_text); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -1885,7 +1885,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -1916,7 +1916,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -1980,7 +1980,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Whole string. @@ -2012,7 +2012,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); // Non-overflow. @@ -2044,7 +2044,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); Text append(insert_text.c_str()); @@ -2077,10 +2077,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2094,7 +2094,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2108,7 +2108,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2122,7 +2122,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2136,7 +2136,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2150,7 +2150,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2164,7 +2164,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2179,10 +2179,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace"))); @@ -2196,7 +2196,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace"))); @@ -2210,7 +2210,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace with some text"))); @@ -2224,7 +2224,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); @@ -2238,7 +2238,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewETL(STR("Replace"))); @@ -2252,7 +2252,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewETL(STR("Replace with some text"))); @@ -2266,7 +2266,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); @@ -2282,10 +2282,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace"))); @@ -2299,7 +2299,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace"))); @@ -2313,7 +2313,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace with some text"))); @@ -2327,7 +2327,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); @@ -2341,7 +2341,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewSTD(STR("Replace"))); @@ -2355,7 +2355,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, ViewSTD(STR("Replace with some text"))); @@ -2369,7 +2369,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); @@ -2385,10 +2385,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_string) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); @@ -2402,7 +2402,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2416,7 +2416,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); @@ -2430,7 +2430,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); @@ -2445,10 +2445,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); @@ -2462,7 +2462,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); @@ -2476,7 +2476,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); @@ -2490,7 +2490,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); @@ -2506,10 +2506,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); @@ -2523,7 +2523,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); @@ -2537,7 +2537,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); @@ -2551,7 +2551,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); @@ -2567,10 +2567,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace")), 1, 5); @@ -2584,7 +2584,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2598,7 +2598,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2612,7 +2612,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2626,7 +2626,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace")), 1, 5); @@ -2640,7 +2640,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); @@ -2654,7 +2654,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); @@ -2668,7 +2668,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); @@ -2683,10 +2683,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); @@ -2700,7 +2700,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); @@ -2714,7 +2714,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); @@ -2728,7 +2728,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); @@ -2742,7 +2742,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); @@ -2756,7 +2756,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); @@ -2770,7 +2770,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); @@ -2784,7 +2784,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); @@ -2800,10 +2800,10 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); @@ -2817,7 +2817,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); @@ -2831,7 +2831,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); @@ -2845,7 +2845,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); @@ -2859,7 +2859,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); @@ -2873,7 +2873,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); @@ -2887,7 +2887,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); @@ -2901,7 +2901,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); @@ -2917,7 +2917,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, STR("Replace")); @@ -2934,7 +2934,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace")); @@ -2962,7 +2962,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text")); @@ -2990,7 +2990,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace")); @@ -3018,7 +3018,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text")); @@ -3033,7 +3033,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); @@ -3093,7 +3093,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, STR("Replace"), 5); @@ -3110,7 +3110,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace"), 5); @@ -3138,7 +3138,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text"), 15); @@ -3166,7 +3166,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, STR("Replace"), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace"), 5); @@ -3194,7 +3194,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, STR("Replace with some text"), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, STR("Replace with some text"), 15); @@ -3209,7 +3209,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); @@ -3277,7 +3277,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(2, 4, 7, STR('A')); @@ -3294,7 +3294,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -3322,7 +3322,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -3350,7 +3350,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -3378,7 +3378,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -3393,7 +3393,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A')); @@ -3453,11 +3453,11 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3515,10 +3515,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.begin() + 2); Text::iterator ditr = text.erase(text.begin() + 2); CHECK(*citr == *ditr); @@ -3532,10 +3532,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2); Text::iterator ditr = text.erase(text.cbegin() + 2); CHECK(*citr == *ditr); @@ -3549,10 +3549,10 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); + TextSTD::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); CHECK(*citr == *ditr); @@ -3578,7 +3578,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.begin(), text.end(), compare_text.begin()); @@ -3591,7 +3591,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.cbegin(), text.cend(), compare_text.cbegin()); @@ -3604,7 +3604,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.rbegin(), text.rend(), compare_text.rbegin()); @@ -3617,7 +3617,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); bool is_equal = std::equal(text.crbegin(), text.crend(), compare_text.crbegin()); @@ -3804,7 +3804,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3845,13 +3845,13 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3871,7 +3871,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); value_t buffer1[SIZE]; @@ -3899,11 +3899,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); - etl::wstring<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -3917,11 +3917,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::wstring<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::wstring<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -3929,12 +3929,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); - etl::wstring<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); ViewETL needle_view(needle); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3948,12 +3948,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(etl::wstring<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::wstring<50> pin(STR("pin")); - ViewETL pin_view(pin); + ViewETL pin_view(STR("pin")); position2 = haystack.find(pin_view); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -3962,12 +3961,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); - std::wstring needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); ViewSTD needle_view(needle); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0UL; size_t position2 = 0UL; @@ -3981,12 +3980,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(etl::wstring<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - std::wstring pin(STR("pin")); - ViewSTD pin_view(pin); + ViewSTD pin_view(STR("pin")); position2 = haystack.find(pin_view); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #endif @@ -3997,8 +3995,8 @@ namespace const value_t* needle = STR("needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -4012,11 +4010,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4026,8 +4024,8 @@ namespace const value_t* needle = STR("needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = 0; size_t position2 = 0; @@ -4041,11 +4039,11 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1, 3); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); const value_t* pin = STR("pin"); position2 = haystack.find(pin, 0, 3); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4053,14 +4051,14 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); - etl::wstring<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -4070,9 +4068,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::wstring<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4080,28 +4078,27 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); - etl::wstring<50> needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + Text needle(STR("needle")); ViewETL needle_view(needle); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle_view, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle, haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::wstring<50> pin(STR("pin")); - ViewETL pin_view(pin); - position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + ViewETL pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); } #if ETL_USING_STL && ETL_USING_CPP17 @@ -4110,15 +4107,15 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); - std::wstring needle(STR("needle")); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); ViewSTD needle_view(needle); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle_view, position2); @@ -4128,10 +4125,9 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - std::wstring pin(STR("pin")); - ViewSTD pin_view(pin); + ViewSTD pin_view(STR("pin")); position2 = haystack.rfind(pin_view); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } #endif @@ -4140,13 +4136,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -4156,9 +4152,9 @@ namespace position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - etl::wstring<50> pin(STR("pin")); + Text pin(STR("pin")); position2 = haystack.rfind(pin); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4166,13 +4162,13 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); const value_t* needle = STR("needle"); size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(needle, position1, 3); position2 = haystack.rfind(needle, position2, 3); @@ -4183,7 +4179,7 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR("pin"), 3); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* @@ -4191,11 +4187,11 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); - etl::wstring<50> haystack(the_haystack); + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position2 = Text::npos; position1 = compare_haystack.rfind(STR('e'), position1); position2 = haystack.rfind(STR('e'), position2); @@ -4206,16 +4202,16 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(etl::iwstring::npos, position2); + CHECK_EQUAL(TextL::npos, position2); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_substr) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str()); - CompareText compare_result; + TextSTD compare_result; Text result; // Equal. @@ -4250,34 +4246,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4285,34 +4281,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_etl_view) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(ViewETL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(ViewETL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(ViewETL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(ViewETL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(ViewETL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4321,34 +4317,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_std_view) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); result = text.compare(ViewSTD(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); result = text.compare(ViewSTD(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); result = text.compare(ViewSTD(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); result = text.compare(ViewSTD(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); result = text.compare(ViewSTD(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4357,34 +4353,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, Text(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, Text(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, Text(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, Text(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, Text(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4392,34 +4388,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, ViewETL(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4428,34 +4424,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } @@ -4464,34 +4460,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, Text(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, Text(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, Text(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4499,34 +4495,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4535,34 +4531,34 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } @@ -4571,7 +4567,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); int compare_result; @@ -4606,7 +4602,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -4641,7 +4637,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); int compare_result; @@ -4676,26 +4672,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(Text(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(Text(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(Text(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(Text(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4705,26 +4701,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(ViewETL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4735,26 +4731,26 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); @@ -4765,7 +4761,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF")); @@ -4794,7 +4790,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR("ZCXF"), 0, 4); @@ -4828,7 +4824,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(STR('C')); @@ -4867,31 +4863,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(Text(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(Text(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(Text(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(Text(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(Text(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4901,31 +4897,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4936,31 +4932,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); @@ -4971,7 +4967,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("ZCXE")); @@ -5010,7 +5006,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(STR("AZCXE"), 0, 4); @@ -5047,7 +5043,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_of(STR('C')); @@ -5086,31 +5082,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(Text(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(Text(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(Text(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(Text(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5120,31 +5116,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5155,31 +5151,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); @@ -5190,7 +5186,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB")); @@ -5224,7 +5220,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR("ZAXB"), 0, 4); @@ -5263,7 +5259,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(STR('A')); @@ -5302,31 +5298,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(Text(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(Text(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(Text(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(Text(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(Text(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5336,31 +5332,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5371,31 +5367,31 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); @@ -5406,7 +5402,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD")); @@ -5440,7 +5436,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(STR("ZEXD"), 0, 4); @@ -5472,7 +5468,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_last_not_of(STR('F')); diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index a30dc63fa..443b0b8a8 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -69,24 +69,34 @@ namespace static constexpr size_t SIZE_L = 52; static constexpr size_t SIZE_S = 4; - using Text = etl::wstring_ext; - using IText = etl::iwstring; - using TextL = etl::wstring; - using CompareText = std::wstring; - using value_t = Text::value_type; + using Text = etl::wstring_ext; + using IText = etl::iwstring; + using TextL = etl::wstring; + using TextSTD = std::wstring; + using value_t = Text::value_type; + + using ViewETL = etl::wstring_view; +#if ETL_USING_STL && ETL_USING_CPP17 + using ViewSTD = std::wstring_view; +#endif using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - CompareText initial_text; - CompareText less_text; - CompareText greater_text; - CompareText shorter_text; - CompareText different_text; - CompareText insert_text; - CompareText longer_text; - CompareText short_text; + using ViewETL = etl::wstring_view; +#if ETL_USING_STL && ETL_USING_CPP17 + using ViewSTD = std::wstring_view; +#endif + + TextSTD initial_text; + TextSTD less_text; + TextSTD greater_text; + TextSTD shorter_text; + TextSTD different_text; + TextSTD insert_text; + TextSTD longer_text; + TextSTD short_text; const value_t* pinitial_text = STR("Hello World"); @@ -201,9 +211,9 @@ namespace TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - CHECK(text.begin() == text.end()); - CHECK(text.cbegin() == text.cend()); - CHECK(text.rbegin() == text.rend()); + CHECK(text.begin() == text.end()); + CHECK(text.cbegin() == text.cend()); + CHECK(text.rbegin() == text.rend()); CHECK(text.crbegin() == text.crend()); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -213,11 +223,11 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_value) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); TextBuffer buffer{0}; - CompareText compare_text(INITIAL_SIZE, INITIAL_VALUE); + TextSTD compare_text(INITIAL_SIZE, INITIAL_VALUE); Text text(INITIAL_SIZE, INITIAL_VALUE, buffer.data(), buffer.size()); CHECK(text.size() == INITIAL_SIZE); @@ -247,7 +257,7 @@ namespace TEST_FIXTURE(SetupFixture, test_constructor_char_pointer) { TextBuffer buffer{0}; - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -263,7 +273,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(longer_text.c_str(), buffer.data(), buffer.size()); @@ -280,7 +290,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE, STR('A'), buffer.data(), buffer.size()); @@ -297,7 +307,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_char_pointer_size_excess) { - CompareText compare_text(SIZE, STR('A')); + TextSTD compare_text(SIZE, STR('A')); TextBuffer buffer{0}; Text text(SIZE + 1, STR('A'), buffer.data(), buffer.size()); @@ -314,7 +324,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char) { - CompareText compare_text(initial_text.c_str(), initial_text.size() / 2); + TextSTD compare_text(initial_text.c_str(), initial_text.size() / 2); TextBuffer buffer{0}; Text text(initial_text.c_str(), initial_text.size() / 2, buffer.data(), buffer.size()); @@ -331,7 +341,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_size_char_excess) { - CompareText compare_text(initial_text.c_str(), initial_text.size()); + TextSTD compare_text(initial_text.c_str(), initial_text.size()); TextBuffer buffer{0}; Text text(longer_text.c_str(), longer_text.size(), buffer.data(), buffer.size()); @@ -348,7 +358,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_range) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -388,10 +398,23 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_string_view) + TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - etl::wstring_view view(initial_text.data(), initial_text.size()); + ViewETL view(initial_text.data(), initial_text.size()); + TextBuffer buffer{0}; + Text text(view, buffer.data(), buffer.size()); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK(text.size() == SIZE); + CHECK(!text.empty()); + } +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) + { + ViewSTD view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -400,6 +423,7 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -464,8 +488,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length) { - CompareText compare_text(initial_text.c_str()); - CompareText compare_text2(compare_text, 2, 4); + TextSTD compare_text(initial_text.c_str()); + TextSTD compare_text2(compare_text, 2, 4); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -483,8 +507,8 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_position_length_excess) { - CompareText compare_text(longer_text.c_str()); - CompareText compare_text2(compare_text, 2, 11); + TextSTD compare_text(longer_text.c_str()); + TextSTD compare_text2(compare_text, 2, 11); TextBufferL bufferl{0}; Text textl(longer_text.c_str(), bufferl.data(), bufferl.size()); @@ -503,7 +527,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list) { - CompareText compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; std::initializer_list il = { STR('H'), STR('e'), STR('l') , STR('l') , STR('o') }; TextBuffer buffer{0}; @@ -519,12 +543,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_construct_initializer_list_excess) { - CompareText compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; + TextSTD compare_text = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), + STR('W'), STR('o'), STR('r'), STR('l'), STR('d') }; std::initializer_list il = { STR('H'), STR('e'), STR('l'), STR('l'), STR('o'), STR(' '), - STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), - STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; + STR('W'), STR('o'), STR('r'), STR('l'), STR('d'), STR(' '), + STR('T'), STR('h'), STR('e'), STR('r'), STR('e') }; TextBuffer buffer{0}; Text text(il, buffer.data(), buffer.size()); @@ -672,7 +696,7 @@ namespace text = STR("Hello World"); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!text.is_truncated()); @@ -687,7 +711,7 @@ namespace text = STR("Hello World There"); - bool is_equal = Equal(std::wstring(STR("Hello World")), text); + bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(text.is_truncated()); @@ -703,7 +727,7 @@ namespace itext = STR("Hello World"); - bool is_equal = Equal(std::wstring(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(!itext.is_truncated()); @@ -719,13 +743,45 @@ namespace itext = STR("Hello World There"); - bool is_equal = Equal(std::wstring(STR("Hello World")), itext); + bool is_equal = Equal(TextSTD(STR("Hello World")), itext); CHECK(is_equal); #if ETL_HAS_STRING_TRUNCATION_CHECKS CHECK(itext.is_truncated()); #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = ViewETL(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text = ViewSTD(STR("Hello World")); + + bool is_equal = Equal(TextSTD(STR("Hello World")), text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) { @@ -734,7 +790,7 @@ namespace TextBuffer buffer2{0}; const Text constText(initial_text.c_str(), buffer2.data(), buffer2.size()); - + CHECK_EQUAL(&text[0], text.begin()); CHECK_EQUAL(&constText[0], constText.begin()); } @@ -848,7 +904,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_up) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 8; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -892,7 +948,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_uninitialized_resize_down) { - const size_t INITIAL_SIZE = 5; + const size_t INITIAL_SIZE = 5UL; const size_t NEW_SIZE = 2; const value_t INITIAL_VALUE = STR('A'); const value_t FILL_VALUE = STR('B'); @@ -918,24 +974,6 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_fill) - { - TextBuffer buffer1{ 0 }; - TextBuffer buffer2{ 0 }; - Text text(11, STR('A'), buffer1.data(), buffer1.size()); - Text expected(11, STR('B'), buffer2.data(), buffer2.size()); - - text.fill(STR('B')); - - bool is_equal = Equal(expected, text); - CHECK(is_equal); - -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_full) { @@ -1015,7 +1053,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1033,7 +1071,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_index_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1051,7 +1089,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1071,7 +1109,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_at_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1091,7 +1129,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1105,7 +1143,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_front_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1119,7 +1157,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1133,7 +1171,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_back_const) { - const CompareText compare_text(initial_text.c_str()); + const TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1147,7 +1185,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1165,7 +1203,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_data_const) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; const Text text(compare_text.begin(), compare_text.end(), buffer.data(), buffer.size()); @@ -1183,12 +1221,12 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer2{0}; Text text(buffer2.data(), buffer2.size()); @@ -1203,15 +1241,61 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_etl_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + ViewETL view(input); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_std_view) + { + TextSTD compare_input(initial_text.c_str()); + TextBuffer buffer{0}; + Text input(initial_text.c_str(), buffer.data(), buffer.size()); + ViewSTD view(input.data(), input.size()); + + TextSTD compare_text; + TextBuffer buffer2{0}; + Text text(buffer2.data(), buffer2.size()); + + compare_text.assign(compare_input); + text.assign(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) { - CompareText compare_input(initial_text.c_str()); + TextSTD compare_input(initial_text.c_str()); TextBufferL bufferl{0}; Text input(longer_text.c_str(), bufferl.data(), bufferl.size()); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1229,7 +1313,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1245,7 +1329,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_excess) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1261,7 +1345,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1277,7 +1361,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_pointer_length_excess) { - CompareText compare_text(longer_text.c_str()); + TextSTD compare_text(longer_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1295,7 +1379,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1371,7 +1455,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1399,7 +1483,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_push_back_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1432,7 +1516,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_pop_back) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -1454,11 +1538,11 @@ namespace TEST_FIXTURE(SetupFixture, test_insert_position_value) { const size_t INITIAL_SIZE = 5; - const value_t INITIAL_VALUE = STR('A'); + const value_t INITIAL_VALUE = STR('A'); for (size_t offset = 0; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1480,7 +1564,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_value_excess) { - CompareText compare_text(initial_text.begin(), initial_text.end()); + TextSTD compare_text(initial_text.begin(), initial_text.end()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1526,7 +1610,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1553,7 +1637,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_position_n_value_excess) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1627,7 +1711,7 @@ namespace for (size_t offset = 0UL; offset <= INITIAL_SIZE; ++offset) { - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1651,7 +1735,7 @@ namespace const size_t INITIAL_SIZE = 5UL; const value_t INITIAL_VALUE = STR('A'); - CompareText compare_text; + TextSTD compare_text; TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); @@ -1710,7 +1794,7 @@ namespace for (size_t offset = 10UL; offset < length; ++offset) { - CompareText compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); + TextSTD compare_text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); TextBufferL bufferl{0}; Text text(bufferl.data(), bufferl.size()); text = STR("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); @@ -1731,8 +1815,9 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer{0}; + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); TextBuffer buffer2{0}; @@ -1750,12 +1835,60 @@ namespace } } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + { + for (size_t offset = 0UL; offset <= short_text.size(); ++offset) + { + TextSTD compare_text(short_text.cbegin(), short_text.cend()); + TextBuffer buffer; + buffer.fill(0); + Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + text.insert(offset, view); + compare_text.insert(offset, insert_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + } + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) { for (size_t offset = 0UL; offset <= initial_text.size(); ++offset) { - CompareText compare_text(initial_text.cbegin(), initial_text.cend()); + TextSTD compare_text(initial_text.cbegin(), initial_text.cend()); TextBuffer buffer{0}; Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); @@ -1780,7 +1913,7 @@ namespace { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1806,7 +1939,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_subpos_sunlen) { - CompareText compare_text(short_text.cbegin(), short_text.cend()); + TextSTD compare_text(short_text.cbegin(), short_text.cend()); TextBuffer buffer{0}; Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1856,7 +1989,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1890,6 +2023,76 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_etl_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + ViewETL view(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(view); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + view.assign(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(view); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_append_std_view) + { + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + ViewSTD append(insert_text.data(), insert_text.size()); + + // Non-overflow. + compare_text.append(insert_text); + text.append(append); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + append = ViewSTD(initial_text.data(), initial_text.size()); + + compare_text.append(initial_text); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.append(append); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -1913,7 +2116,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_to_self) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1946,7 +2149,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_string_subpos_sublen) { - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -1955,7 +2158,7 @@ namespace Text append(insert_text.c_str(), buffer2.data(), buffer2.size()); // Whole string. - compare_text.append(insert_text, 0, std::wstring::npos); + compare_text.append(insert_text, 0, TextSTD::npos); text.append(append, 0, Text::npos); bool is_equal = Equal(compare_text, text); @@ -2017,7 +2220,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_c_string) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2051,7 +2254,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_n_c) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2085,7 +2288,7 @@ namespace TEST_FIXTURE(SetupFixture, test_append_range) { // Non-overflow. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2122,12 +2325,12 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_string) { // Non-overflow short text, npos. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace"))); @@ -2141,7 +2344,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace"))); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace"))); @@ -2155,7 +2358,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2169,7 +2372,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2183,7 +2386,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 7, TextL(STR("Replace"))); @@ -2197,7 +2400,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 2, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 2, TextL(STR("Replace with some text"))); @@ -2211,7 +2414,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, TextL(STR("Replace with some text"))); @@ -2223,17 +2426,16 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) { - // Non-overflow short text. - CompareText compare_text(short_text.c_str()); - + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace"))); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + text.replace(2, Text::npos, ViewETL(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2241,13 +2443,41 @@ namespace CHECK(!text.is_truncated()); #endif + // Non-overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 2, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 2, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + // Overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2259,9 +2489,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, CompareText(STR("Replace"))); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + text.replace(2, 7, ViewETL(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2273,9 +2503,23 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text"))); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + text.replace(2, 2, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2284,18 +2528,18 @@ namespace #endif } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) { - // Non-overflow short text. - CompareText compare_text(short_text.c_str()); - + // Non-overflow short text, npos. + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, CompareText(STR("Replace")), 1, 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")), 1, 5); + text.replace(2, Text::npos, ViewSTD(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2303,13 +2547,13 @@ namespace CHECK(!text.is_truncated()); #endif - // Non-overflow short text, npos. + // Non-overflow short text. compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 2, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2321,9 +2565,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2335,9 +2579,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2349,23 +2593,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, CompareText(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, TextL(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace")), 1, CompareText::npos); + compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + text.replace(2, 7, ViewSTD(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2377,9 +2607,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, CompareText(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + text.replace(2, 2, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2391,9 +2621,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, CompareText(STR("Replace with some text")), 1, CompareText::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2401,19 +2631,560 @@ namespace CHECK(text.is_truncated()); #endif } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_first_last_string) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, TextL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, TextL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, TextL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) + { + // Non-overflow short text. + TextSTD compare_text(short_text.c_str()); + TextBuffer buffer{0}; + Text text(short_text.c_str(), buffer.data(), buffer.size()); + + compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); + + bool is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow short text. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow short text, npos. + compare_text.assign(short_text.c_str()); + text.assign(short_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Non-overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Non-overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(!text.is_truncated()); +#endif + + // Overflow. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + + // Overflow, npos. + compare_text.assign(initial_text.c_str()); + text.assign(initial_text.c_str()); + + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); + compare_text.resize(std::min(compare_text.size(), SIZE)); + text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); + + is_equal = Equal(compare_text, text); + CHECK(is_equal); +#if ETL_HAS_STRING_TRUNCATION_CHECKS + CHECK(text.is_truncated()); +#endif + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace")); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2425,9 +3196,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2439,9 +3210,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2453,9 +3224,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2467,9 +3238,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace")); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace")); + text.replace(2, 7, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2481,9 +3252,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2495,9 +3266,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2509,9 +3280,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text")); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text")); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2524,14 +3295,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2543,9 +3314,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, CompareText(STR("Replace with some text")).c_str()); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2557,9 +3328,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace")); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2571,9 +3342,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text")); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text")); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2586,14 +3357,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(2, 4, STR("Replace"), 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace"), 5); + text.replace(2, 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2605,9 +3376,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2619,9 +3390,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2633,9 +3404,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2647,9 +3418,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 7, STR("Replace"), 5); + compare_text.replace(2, 7, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, STR("Replace"), 5); + text.replace(2, 7, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2661,9 +3432,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace"), 5); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace"), 5); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2675,9 +3446,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, 4, STR("Replace with some text"), 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text"), 15); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2689,9 +3460,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, STR("Replace with some text"), 15); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace with some text"), 15); + text.replace(2, Text::npos, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2704,14 +3475,14 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_pointer_n) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace")).c_str(), 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2725,9 +3496,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2741,9 +3512,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, STR("Replace"), 5); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace")).c_str(), 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, STR("Replace"), 5); + text.replace(text.begin() + 2, text.begin() + 9, TextL(STR("Replace")).c_str(), 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2757,9 +3528,9 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, STR("Replace with some text"), 15); + compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text")).c_str(), 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, STR("Replace with some text"), 15); + text.replace(text.begin() + 2, text.begin() + 4, TextL(STR("Replace with some text")).c_str(), 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2774,7 +3545,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_position_length_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2793,7 +3564,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2821,7 +3592,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2849,7 +3620,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 7, STR('A')); + compare_text.replace(2, TextSTD::npos, 7, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 7, STR('A')); @@ -2877,7 +3648,7 @@ namespace compare_text.assign(initial_text.c_str()); text.assign(initial_text.c_str()); - compare_text.replace(2, CompareText::npos, 15, STR('A')); + compare_text.replace(2, TextSTD::npos, 15, STR('A')); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, Text::npos, 15, STR('A')); @@ -2892,7 +3663,7 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); @@ -2954,13 +3725,13 @@ namespace TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last) { // Non-overflow short text. - CompareText compare_text(short_text.c_str()); + TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - CompareText replace(STR("Replace")); - CompareText replace_long(STR("Replace with some text")); + TextSTD replace(STR("Replace")); + TextSTD replace_long(STR("Replace with some text")); compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5); compare_text.resize(std::min(compare_text.size(), SIZE)); @@ -3016,33 +3787,15 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_iterator) + TEST_FIXTURE(SetupFixture, test_erase_single) { - CompareText compare_text(initial_text.c_str()); - TextBuffer buffer{0}; - Text text(initial_text.c_str(), buffer.data(), buffer.size()); + TextSTD compare_text(initial_text.c_str()); - CompareText::iterator citr = compare_text.erase(compare_text.begin() + 2); - Text::iterator ditr = text.erase(text.begin() + 2); - CHECK(*citr == *ditr); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_erase_single_const_iterator) - { - CompareText compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2); - Text::iterator ditr = text.erase(text.cbegin() + 2); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2); + text.erase(text.begin() + 2); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3054,13 +3807,14 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_erase_range) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); - CompareText::iterator citr = compare_text.erase(compare_text.cbegin() + 2, compare_text.cbegin() + 4); - Text::iterator ditr = text.erase(text.cbegin() + 2, text.cbegin() + 4); - CHECK(*citr == *ditr); + compare_text.erase(compare_text.begin() + 2, compare_text.begin() + 4); + + text.erase(text.begin() + 2, text.begin() + 4); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3085,7 +3839,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3100,7 +3854,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3115,7 +3869,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3130,7 +3884,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_const_reverse_iterator) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3196,7 +3950,7 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less < initial) == (less_text < initial_text)); + CHECK((less < initial) == (less_text < initial_text)); CHECK((initial < less) == (initial_text < less_text)); TextBuffer buffer3; @@ -3213,17 +3967,17 @@ namespace CHECK((initial < initial) == (initial_text < initial_text)); // String-Pointer Pointer-String - CHECK((less < pinitial_text) == (less_text < pinitial_text)); - CHECK((pinitial_text < less) == (pinitial_text < less_text)); + CHECK((less < pinitial_text) == (less_text < pinitial_text)); + CHECK((pinitial_text < less) == (pinitial_text < less_text)); - CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); - CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); + CHECK((greater < pinitial_text) == (greater_text < pinitial_text)); + CHECK((pinitial_text < greater) == (pinitial_text < greater_text)); - CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); - CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); + CHECK((shorter < pinitial_text) == (shorter_text < pinitial_text)); + CHECK((pinitial_text < shorter) == (pinitial_text < shorter_text)); - CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); - CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); + CHECK((initial < pinitial_text) == (initial_text < pinitial_text)); + CHECK((pinitial_text < initial) == (pinitial_text < initial_text)); } //************************************************************************* @@ -3236,8 +3990,8 @@ namespace const Text initial(initial_text.c_str(), buffer2.data(), buffer2.size()); // String-String - CHECK((less <= initial) == (less_text <= initial_text)); - CHECK((initial <= less) == (initial_text <= less_text)); + CHECK((less <= initial) == (less_text <= initial_text)); + CHECK((initial <= less) == (initial_text <= less_text)); TextBuffer buffer3; const Text greater(greater_text.c_str(), buffer3.data(), buffer3.size()); @@ -3253,17 +4007,17 @@ namespace CHECK((initial <= initial) == (initial_text <= initial_text)); // String-Pointer Pointer-String - CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); - CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); + CHECK((less <= pinitial_text) == (less_text <= pinitial_text)); + CHECK((pinitial_text <= less) == (pinitial_text <= less_text)); - CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); - CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); + CHECK((greater <= pinitial_text) == (greater_text <= pinitial_text)); + CHECK((pinitial_text <= greater) == (pinitial_text <= greater_text)); - CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); - CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); + CHECK((shorter <= pinitial_text) == (shorter_text <= pinitial_text)); + CHECK((pinitial_text <= shorter) == (pinitial_text <= shorter_text)); - CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); - CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); + CHECK((initial <= pinitial_text) == (initial_text <= pinitial_text)); + CHECK((pinitial_text <= initial) == (pinitial_text <= initial_text)); } //************************************************************************* @@ -3293,17 +4047,17 @@ namespace CHECK((initial > initial) == (initial_text > initial_text)); // String-Pointer Pointer-String - CHECK((less > pinitial_text) == (less_text > pinitial_text)); - CHECK((pinitial_text > less) == (pinitial_text > less_text)); + CHECK((less > pinitial_text) == (less_text > pinitial_text)); + CHECK((pinitial_text > less) == (pinitial_text > less_text)); - CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); - CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); + CHECK((greater > pinitial_text) == (greater_text > pinitial_text)); + CHECK((pinitial_text > greater) == (pinitial_text > greater_text)); - CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); - CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); + CHECK((shorter > pinitial_text) == (shorter_text > pinitial_text)); + CHECK((pinitial_text > shorter) == (pinitial_text > shorter_text)); - CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); - CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); + CHECK((initial > pinitial_text) == (initial_text > pinitial_text)); + CHECK((pinitial_text > initial) == (pinitial_text > initial_text)); } //************************************************************************* @@ -3316,8 +4070,8 @@ namespace const Text initial(initial_text.begin(), initial_text.end(), buffer2.data(), buffer2.size()); // String-String - CHECK((less >= initial) == (less_text >= initial_text)); - CHECK((initial >= less) == (initial_text >= less_text)); + CHECK((less >= initial) == (less_text >= initial_text)); + CHECK((initial >= less) == (initial_text >= less_text)); TextBuffer buffer3; const Text greater(greater_text.begin(), greater_text.end(), buffer3.data(), buffer3.size()); @@ -3333,24 +4087,24 @@ namespace CHECK((initial >= initial) == (initial_text >= initial_text)); // String-Pointer Pointer-String - CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); - CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); + CHECK((less >= pinitial_text) == (less_text >= pinitial_text)); + CHECK((pinitial_text >= less) == (pinitial_text >= less_text)); - CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); - CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); + CHECK((greater >= pinitial_text) == (greater_text >= pinitial_text)); + CHECK((pinitial_text >= greater) == (pinitial_text >= greater_text)); - CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); - CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); + CHECK((shorter >= pinitial_text) == (shorter_text >= pinitial_text)); + CHECK((pinitial_text >= shorter) == (pinitial_text >= shorter_text)); - CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); - CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); + CHECK((initial >= pinitial_text) == (initial_text >= pinitial_text)); + CHECK((pinitial_text >= initial) == (pinitial_text >= initial_text)); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy) { - CompareText compare_text(initial_text.c_str()); - + TextSTD compare_text(initial_text.c_str()); + TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3369,8 +4123,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3393,7 +4147,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_equals_npos) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3401,7 +4155,7 @@ namespace value_t buffer1[SIZE]; value_t buffer2[SIZE]; - size_t length1 = compare_text.copy(buffer1, CompareText::npos, 2); + size_t length1 = compare_text.copy(buffer1, TextSTD::npos, 2); buffer1[length1] = STR('\0'); size_t length2 = text.copy(buffer2, Text::npos, 2); @@ -3413,15 +4167,15 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_count_too_large) { - CompareText compare_text(initial_text.c_str()); + TextSTD compare_text(initial_text.c_str()); TextBuffer buffer{0}; Text text(initial_text.c_str(), buffer.data(), buffer.size()); @@ -3441,8 +4195,8 @@ namespace #endif bool is_equal = std::equal(buffer1, - buffer1 + length1, - buffer2); + buffer1 + length1, + buffer2); CHECK(is_equal); } @@ -3451,12 +4205,12 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBuffer buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); @@ -3473,13 +4227,77 @@ namespace CHECK_EQUAL(position1, position2); position2 = haystack.find(needle, position2 + 1); - CHECK_EQUAL(etl::wstring<50>::npos, position2); + CHECK_EQUAL(Text::npos, position2); - etl::wstring<50> pin(STR("pin")); + Text pin(STR("pin"), buffer.data(), buffer.size()); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewETL needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + ViewETL pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_std_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewSTD needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextBufferL buffer2{0}; + Text haystack(the_haystack, buffer2.data(), buffer2.size()); + + size_t position1 = 0UL; + size_t position2 = 0UL; + + position1 = compare_haystack.find(compare_needle, position1); + position2 = haystack.find(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.find(compare_needle, position1 + 1); + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(position1, position2); + + position2 = haystack.find(needle_view, position2 + 1); + CHECK_EQUAL(TextL::npos, position2); + + ViewSTD pin_view(STR("pin")); + position2 = haystack.find(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) { @@ -3487,7 +4305,7 @@ namespace const value_t* needle = STR("needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3506,7 +4324,7 @@ namespace position2 = haystack.find(needle, position2 + 1); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin); CHECK_EQUAL(IText::npos, position2); } @@ -3518,7 +4336,7 @@ namespace const value_t* needle = STR("needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); @@ -3537,7 +4355,7 @@ namespace position2 = haystack.find(needle, position2 + 1, 3); CHECK_EQUAL(IText::npos, position2); - const value_t* pin = STR("pin"); + const value_t *pin = STR("pin"); position2 = haystack.find(pin, 0, 3); CHECK_EQUAL(IText::npos, position2); } @@ -3547,18 +4365,18 @@ namespace { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_needle(STR("needle")); + TextSTD compare_needle(STR("needle")); TextBufferL buffer{0}; Text needle(STR("needle"), buffer.data(), buffer.size()); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; Text haystack(the_haystack, buffer2.data(), buffer2.size()); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(compare_needle, position1); position2 = haystack.rfind(needle, position2); @@ -3575,19 +4393,76 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_pointer) + TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + { + const value_t* the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_needle(STR("needle")); + ViewETL needle_view(STR("needle")); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + ViewETL pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_std_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_needle(STR("needle")); + TextSTD needle(STR("needle")); + ViewSTD needle_view(needle); + + TextSTD compare_haystack(the_haystack); + TextL haystack(the_haystack); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(compare_needle, position1); + position2 = haystack.rfind(needle_view, position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); + position2 = haystack.rfind(needle_view, haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + ViewSTD pin_view(STR("pin")); + position2 = haystack.rfind(pin_view); + CHECK_EQUAL(TextL::npos, position2); + } +#endif + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_pointer) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; position1 = compare_haystack.rfind(needle, position1); position2 = haystack.rfind(needle, position2); @@ -3606,16 +4481,16 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer_n) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + const value_t*the_haystack = STR("A haystack with a needle and another needle"); - std::wstring compare_haystack(the_haystack); + TextSTD compare_haystack(the_haystack); TextBufferL buffer{0}; Text haystack(the_haystack, buffer.data(), buffer.size()); const value_t* needle = STR("needle"); - size_t position1 = std::wstring::npos; + size_t position1 = TextSTD::npos; size_t position2 = Text::npos; @@ -3632,72 +4507,294 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_c_position) + TEST_FIXTURE(SetupFixture, test_rfind_c_position) + { + const value_t*the_haystack = STR("A haystack with a needle and another needle"); + + TextSTD compare_haystack(the_haystack); + + TextBufferL buffer{0}; + Text haystack(the_haystack, buffer.data(), buffer.size()); + + size_t position1 = TextSTD::npos; + size_t position2 = TextL::npos; + + position1 = compare_haystack.rfind(STR('e'), position1); + position2 = haystack.rfind(STR('e'), position2); + CHECK_EQUAL(position1, position2); + + position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); + position2 = haystack.rfind(STR('e'), haystack.size() - 10); + CHECK_EQUAL(position1, position2); + + position2 = haystack.rfind(STR('z')); + CHECK_EQUAL(IText::npos, position2); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_string) + { + TextSTD compare_text(STR("ABCDEF")); + + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(TextL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(TextL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(TextL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(TextL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(TextL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_etl_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_std_view) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); + result = text.compare(ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); + result = text.compare(ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); + result = text.compare(ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); + result = text.compare(ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); + result = text.compare(ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } +#endif + + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, TextL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, TextL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, TextL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, TextL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, TextL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + { + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); + + int compare_result; + int result; + + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); + + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); + + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); + + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); + + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); + TextSTD compare_text(STR("xxxABCDEFyyy")); + TextBuffer buffer{0}; + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - std::wstring compare_haystack(the_haystack); + int compare_result; + int result; - TextBufferL buffer{0}; - Text haystack(the_haystack, buffer.data(), buffer.size()); + // Equal. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + CHECK(compares_agree(compare_result, result)); - size_t position1 = std::wstring::npos; - size_t position2 = etl::wstring<50>::npos; + // Less. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(STR('e'), position1); - position2 = haystack.rfind(STR('e'), position2); - CHECK_EQUAL(position1, position2); + // Greater. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + CHECK(compares_agree(compare_result, result)); - position1 = compare_haystack.rfind(STR('e'), compare_haystack.size() - 10); - position2 = haystack.rfind(STR('e'), haystack.size() - 10); - CHECK_EQUAL(position1, position2); + // Shorter. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + CHECK(compares_agree(compare_result, result)); - position2 = haystack.rfind(STR('z')); - CHECK_EQUAL(IText::npos, position2); + // Longer. + compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); int compare_result; int result; // Equal. - compare_result = compare_text.compare(CompareText(STR("ABCDEF"))); - result = text.compare(TextL(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(CompareText(STR("ABCDEE"))); - result = text.compare(TextL(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(CompareText(STR("ABCDEG"))); - result = text.compare(TextL(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(CompareText(STR("ABCDE"))); - result = text.compare(TextL(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(CompareText(STR("ABCDEFG"))); - result = text.compare(TextL(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string) + TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); - + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3705,36 +4802,36 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEF"))); - result = text.compare(3, 6, TextL(STR("ABCDEF"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEE"))); - result = text.compare(3, 6, TextL(STR("ABCDEE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEG"))); - result = text.compare(3, 6, TextL(STR("ABCDEG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDE"))); - result = text.compare(3, 6, TextL(STR("ABCDE"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("ABCDEFG"))); - result = text.compare(3, 6, TextL(STR("ABCDEFG"))); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) { - CompareText compare_text(STR("xxxABCDEFyyy")); - + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3742,35 +4839,36 @@ namespace int result; // Equal. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEFbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEEbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, TextL(STR("aaABCDEGbb")), 2, 6); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, TextL(STR("aaABCDEbb")), 2, 5); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. - compare_result = compare_text.compare(3, 6, CompareText(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, TextL(STR("aaABCDEFGbb")), 2, 7); + compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } +#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3807,7 +4905,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3844,7 +4942,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_c_string_n) { - CompareText compare_text(STR("xxxABCDEFyyy")); + TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); @@ -3881,38 +4979,100 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_of(CompareText(STR("ZCXF"))); + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); size_t position2 = text.find_first_of(TextL(STR("ZCXF"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("WXYZ"))); + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); position2 = text.find_first_of(TextL(STR("WXYZ"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 3); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); position2 = text.find_first_of(TextL(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(CompareText(STR("ZCXF")), 100); + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); position2 = text.find_first_of(TextL(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(ViewETL(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); + position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3943,7 +5103,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -3979,7 +5139,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4020,43 +5180,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_of(CompareText(STR("ZCXE"))); + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); size_t position2 = text.find_last_of(TextL(STR("ZCXE"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("WXYZ")), 3); + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); position2 = text.find_last_of(TextL(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 5); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); position2 = text.find_last_of(TextL(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), compare_text.size()); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); position2 = text.find_last_of(TextL(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(CompareText(STR("ZCXE")), 100); + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); position2 = text.find_last_of(TextL(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4097,7 +5329,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4127,16 +5359,18 @@ namespace CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(STR("ZCXE"), 100, 4); position2 = text.find_last_of(STR("ZCXE"), 100, 4); CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" } //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4177,43 +5411,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_string_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); size_t position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB"))); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); position2 = text.find_first_not_of(TextL(STR("ZAXB"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 3); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), compare_text.size()); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); position2 = text.find_first_not_of(TextL(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(CompareText(STR("ZAXB")), 100); + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); position2 = text.find_first_not_of(TextL(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEF")); + TextBuffer buffer{0}; + Text text(STR("ABCDEF"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4249,7 +5555,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4290,7 +5596,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4331,43 +5637,115 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_string_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - size_t position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD"))); + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); size_t position2 = text.find_last_not_of(TextL(STR("ZEXD"))); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 3); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 5); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), compare_text.size()); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); position2 = text.find_last_not_of(TextL(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(CompareText(STR("ZEXD")), 100); + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); position2 = text.find_last_not_of(TextL(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } + +#if ETL_USING_STL && ETL_USING_CPP17 + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) + { + TextSTD compare_text(STR("ABCDEFABCDE")); + TextBuffer buffer{0}; + Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); + + size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); + + CHECK_EQUAL(position1, position2); + + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); + + CHECK_EQUAL(position1, position2); + +#include "etl/private/diagnostic_array_bounds_push.h" + position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); + position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); + + CHECK_EQUAL(position1, position2); +#include "etl/private/diagnostic_pop.h" + } +#endif + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4403,7 +5781,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position_n) { - CompareText compare_text(STR("ABCDEFABCDE")); + TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); @@ -4437,7 +5815,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_character_position) { - CompareText compare_text(STR("ABCDEF")); + TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); @@ -4712,6 +6090,23 @@ namespace CHECK(std::find_if(text.end(), pe, [](Text::value_type x) { return x != 0; }) == pe); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_secure_after_clear) + { + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + text.set_secure(); + text.assign(STR("ABCDEF")); + + Text::pointer pb = text.begin(); + Text::pointer pe = text.end(); + + text.clear(); + + // Check there no non-zero values in the remainder of the string. + CHECK(std::find_if(pb, pe, [](Text::value_type x) { return x != 0; }) == pe); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_secure_flag_after_copy) { From 7adf9adfcfdb497bd67fde9cbdce53ac5c703fbf Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 23 Nov 2024 10:47:41 +0000 Subject: [PATCH 29/55] Removed std::string_view interface Added contains member functions --- include/etl/basic_string.h | 337 +------ include/etl/string.h | 48 - include/etl/u16string.h | 48 - include/etl/u32string.h | 48 - include/etl/u8string.h | 12 - include/etl/wstring.h | 48 - test/test_string_char.cpp | 916 +++--------------- test/test_string_char_external_buffer.cpp | 935 +++--------------- test/test_string_u16.cpp | 916 +++--------------- test/test_string_u16_external_buffer.cpp | 935 +++--------------- test/test_string_u32.cpp | 916 +++--------------- test/test_string_u32_external_buffer.cpp | 935 +++--------------- test/test_string_u8.cpp | 916 +++--------------- test/test_string_u8_external_buffer.cpp | 935 +++--------------- test/test_string_wchar_t.cpp | 915 +++--------------- test/test_string_wchar_t_external_buffer.cpp | 938 +++---------------- 16 files changed, 1283 insertions(+), 8515 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 344e7d3b0..d228166f8 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -52,10 +52,6 @@ SOFTWARE. #include #include -#if ETL_USING_STL && ETL_USING_CPP17 - #include -#endif - #include "private/minmax_push.h" //***************************************************************************** @@ -711,17 +707,6 @@ namespace etl assign(view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Assigns values to the string from a view. - //********************************************************************* - template - void assign(const std::basic_string_view& view) - { - assign(view.begin(), view.end()); - } -#endif - //********************************************************************* /// Assigns values to the string. /// Truncates if the string does not have enough free space. @@ -883,19 +868,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Appends to the string. - ///\param view A std::string_view. - //********************************************************************* - template - ibasic_string& append(const std::basic_string_view& view) - { - insert(end(), view.begin(), view.end()); - return *this; - } -#endif - //********************************************************************* /// Inserts a value to the string. ///\param position The position to insert before. @@ -1138,20 +1110,6 @@ namespace etl return insert(position, view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Inserts a view to the string. - /// If asserts or exceptions are enabled, emits string_full if the string does not have enough free space. - ///\param position The position to insert before. - ///\param view The view element to add. - //********************************************************************* - template - iterator insert(const_iterator position, const std::basic_string_view& view) - { - return insert(position, view.begin(), view.end()); - } -#endif - //********************************************************************* /// Inserts a string at the specified position. ///\param position The position to insert before. @@ -1192,23 +1150,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Inserts a string at the specified position. - ///\param position The position to insert before. - ///\param view The view to insert. - //********************************************************************* - template - etl::ibasic_string& insert(size_type position, const std::basic_string_view& view) - { - ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); - - insert(begin() + position, view.cbegin(), view.cend()); - - return *this; - } -#endif - //********************************************************************* /// Inserts a string at the specified position from subposition for sublength. ///\param position The position to insert before. @@ -1265,31 +1206,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Inserts a view at the specified position from subposition for sublength. - ///\param position The position to insert before. - ///\param view The view to insert. - ///\param subposition The subposition to start from. - ///\param sublength The number of characters to insert. - //********************************************************************* - template - etl::ibasic_string& insert(size_type position, const std::basic_string_view& view, size_type subposition, size_type sublength) - { - ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); - ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); - - if ((sublength == npos) || (subposition + sublength > view.size())) - { - sublength = view.size() - subposition; - } - - insert(begin() + position, view.cbegin() + subposition, view.cbegin() + subposition + sublength); - - return *this; - } -#endif - //********************************************************************* /// Inserts a string at the specified position from pointer. ///\param position The position to insert before. @@ -1461,19 +1377,6 @@ namespace etl return find_impl(view.begin(), view.end(), view.size(), pos); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Find content within the string - ///\param view The content to find - ///\param pos The position to start searching from. - //********************************************************************* - template - size_type find(const std::basic_string_view& view, size_type pos = 0) const - { - return find_impl(view.begin(), view.end(), view.size(), pos); - } -#endif - //********************************************************************* /// Find content within the string ///\param s Pointer to the content to find @@ -1539,19 +1442,6 @@ namespace etl return rfind_impl(view.rbegin(), view.rend(), view.size(), pos); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Find content within the string - ///\param view The content to find - ///\param pos The position to start searching from. - //********************************************************************* - template - size_type rfind(const std::basic_string_view& view, size_type pos = 0) const - { - return rfind_impl(view.rbegin(), view.rend(), view.size(), pos); - } -#endif - //********************************************************************* /// Find content within the string ///\param str The content to find @@ -1607,35 +1497,45 @@ namespace etl } //********************************************************************* - /// Replace 'length' characters from 'position' with 'str'. - ///\param position The position to start from. - ///\param length The number of characters to replace. - ///\param str The string to replace it with. + /// Checks that the string is within the string //********************************************************************* - ibasic_string& replace(size_type position, size_type length_, const ibasic_string& str) + bool contains(const etl::ibasic_string& str) const { - ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); - - // Limit the length. - length_ = etl::min(length_, size() - position); + return find(str) != npos; + } - // Erase the bit we want to replace. - erase(position, length_); + //********************************************************************* + /// Checks that the view is within the string + //********************************************************************* + template + bool contains(const etl::basic_string_view& view) const + { + return find(view) != npos; + } - // Insert the new stuff. - insert(position, str); + //********************************************************************* + /// Checks that text is within the string + //********************************************************************* + bool contains(const_pointer s) const + { + return find(s) != npos; + } - return *this; + //********************************************************************* + /// Checks that character is within the string + //********************************************************************* + bool contains(value_type c) const + { + return find(c) != npos; } //********************************************************************* - /// Replace 'length' characters from 'position' with 'view'. + /// Replace 'length' characters from 'position' with 'str'. ///\param position The position to start from. ///\param length The number of characters to replace. - ///\param view The string to replace it with. + ///\param str The string to replace it with. //********************************************************************* - template - ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view) + ibasic_string& replace(size_type position, size_type length_, const ibasic_string& str) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1646,12 +1546,11 @@ namespace etl erase(position, length_); // Insert the new stuff. - insert(position, view); + insert(position, str); return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 //********************************************************************* /// Replace 'length' characters from 'position' with 'view'. ///\param position The position to start from. @@ -1659,7 +1558,7 @@ namespace etl ///\param view The string to replace it with. //********************************************************************* template - ibasic_string& replace(size_type position, size_type length_, const std::basic_string_view& view) + ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1674,7 +1573,6 @@ namespace etl return *this; } -#endif //********************************************************************* /// Replace characters from 'first' to one before 'last' with 'str'. @@ -1730,30 +1628,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Replace characters from 'first' to one before 'last' with 'view'. - ///\param first The position to start from. - ///\param last The one after the position to end at. - ///\param view The string view to replace it with. - //********************************************************************* - template - ibasic_string& replace(const_iterator first, const_iterator last, const std::basic_string_view& view) - { - // Quick hack, as iterators are pointers. - iterator first_ = to_iterator(first); - iterator last_ = to_iterator(last); - - // Erase the bit we want to replace. - erase(first_, last_); - - // Insert the new stuff. - insert(first_, view.begin(), view.end()); - - return *this; - } -#endif - //********************************************************************* /// Replace characters from 'position' of 'length' with 'str' from 'subposition' of 'sublength'. //********************************************************************* @@ -1808,30 +1682,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Replace characters from 'position' of 'length' with 'view' from 'subposition' of 'sublength'. - //********************************************************************* - template - ibasic_string& replace(size_type position, size_type length_, const std::basic_string_view& view, size_type subposition, size_type sublength) - { - ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); - ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); - - // Limit the lengths. - length_ = etl::min(length_, size() - position); - sublength = etl::min(sublength, view.size() - subposition); - - // Erase the bit we want to replace. - erase(position, length_); - - // Insert the new stuff. - insert(position, view, subposition, sublength); - - return *this; - } -#endif - //********************************************************************* /// Replace characters from 'position' of 'length' with pointed to string. //********************************************************************* @@ -1985,20 +1835,6 @@ namespace etl view.data() + view.size()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Compare with std::basic_string_view. - //************************************************************************* - template - int compare(const std::basic_string_view& view) const - { - return compare(p_buffer, - p_buffer + size(), - view.data(), - view.data() + view.size()); - } -#endif - //************************************************************************* /// Compare position / length with string. //************************************************************************* @@ -2027,20 +1863,6 @@ namespace etl view.data() + view.size()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Compare position / length with std::basic_string_view. - //************************************************************************* - template - int compare(size_type position, size_type length_, const std::basic_string_view& view) const - { - return compare(p_buffer + position, - p_buffer + position + length_, - view.data(), - view.data() + view.size()); - } -#endif - //************************************************************************* /// Compare position / length with string / subposition / sublength. //************************************************************************* @@ -2078,27 +1900,6 @@ namespace etl view.data() + subposition + sublength); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Compare position / length with std::basic_string_view. / subposition / sublength. - //************************************************************************* - template - int compare(size_type position, size_type length_, const std::basic_string_view& view, size_type subposition, size_type sublength) const - { - ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); - ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); - - // Limit the lengths. - length_ = etl::min(length_, size() - position); - sublength = etl::min(sublength, view.size() - subposition); - - return compare(p_buffer + position, - p_buffer + position + length_, - view.data() + subposition, - view.data() + subposition + sublength); - } -#endif - //************************************************************************* /// Compare with C string //************************************************************************* @@ -2163,19 +1964,6 @@ namespace etl return find_first_of(view.data(), position, view.size()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Find first of any of content within the string - ///\param view The content to find - ///\param pos The position to start searching from. - //********************************************************************* - template - size_type find_first_of(const std::basic_string_view& view, size_type position = 0) const - { - return find_first_of(view.data(), position, view.size()); - } -#endif - //********************************************************************* /// Find first of any of content within the string ///\param s Pointer to the content to find @@ -2253,19 +2041,6 @@ namespace etl return find_last_of(view.data(), position, view.size()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Find last of any of content within the string - ///\param view The content to find - ///\param pos The position to start searching from. - //********************************************************************* - template - size_type find_last_of(const std::basic_string_view& view, size_type position = npos) const - { - return find_last_of(view.data(), position, view.size()); - } -#endif - //********************************************************************* /// Find last of any of content within the string ///\param s Pointer to the content to find @@ -2361,19 +2136,6 @@ namespace etl return find_first_not_of(view.data(), position, view.size()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Find first not of any of content within the string - ///\param view The content to find - ///\param pos The position to start searching from. - //********************************************************************* - template - size_type find_first_not_of(const std::basic_string_view& view, size_type position = 0) const - { - return find_first_not_of(view.data(), position, view.size()); - } -#endif - //********************************************************************* /// Find first not of any of content within the string ///\param s Pointer to the content to not find @@ -2458,19 +2220,6 @@ namespace etl return find_last_not_of(view.data(), position, view.size()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //********************************************************************* - /// Find last not of any of content within the string - ///\param view The content to find - ///\param pos The position to start searching from. - //********************************************************************* - template - size_type find_last_not_of(const std::basic_string_view& view, size_type position = npos) const - { - return find_last_not_of(view.data(), position, view.size()); - } -#endif - //********************************************************************* /// Find last not of any of content within the string ///\param s The pointer to the content to find @@ -2574,19 +2323,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Assignment operator. - //************************************************************************* - template - ibasic_string& operator = (const std::basic_string_view& view) - { - assign(view); - - return *this; - } -#endif - //************************************************************************* /// += operator. //************************************************************************* @@ -2608,19 +2344,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// += operator. - //************************************************************************* - template - ibasic_string& operator += (const std::basic_string_view& rhs) - { - append(rhs); - - return *this; - } -#endif - //************************************************************************* /// += operator. //************************************************************************* diff --git a/include/etl/string.h b/include/etl/string.h index 55bfa4524..891815adf 100644 --- a/include/etl/string.h +++ b/include/etl/string.h @@ -186,18 +186,6 @@ namespace etl this->assign(view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit string(const std::string_view& view) - : istring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(view.begin(), view.end()); - } -#endif - //************************************************************************* /// Returns a sub-string. ///\param position The position of the first character. Default = 0. @@ -266,18 +254,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string& operator = (const std::string_view& view) - { - this->assign(view); - - return *this; - } -#endif - //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -406,18 +382,6 @@ namespace etl this->assign(view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit string_ext(const std::string_view& view, value_type* buffer, size_type buffer_size) - : istring(buffer, buffer_size - 1U) - { - this->assign(view.begin(), view.end()); - } -#endif - //************************************************************************* /// Constructor, from an iterator range. ///\tparam TIterator The iterator type. @@ -488,18 +452,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Assignment operator. - //************************************************************************* - string_ext& operator = (const std::string_view& view) - { - this->assign(view); - - return *this; - } -#endif - //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/u16string.h b/include/etl/u16string.h index b18bc07d4..69eb25bcd 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -183,18 +183,6 @@ namespace etl this->assign(view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit u16string(const std::u16string_view& view) - : iu16string(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(view.begin(), view.end()); - } -#endif - //************************************************************************* /// Returns a sub-string. ///\param position The position of the first character. Default = 0. @@ -249,18 +237,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Assignment operator. - //************************************************************************* - u16string& operator = (const std::u16string_view& view) - { - this->assign(view); - - return *this; - } -#endif - //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -409,18 +385,6 @@ namespace etl this->assign(view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit u16string_ext(const std::u16string_view& view, value_type* buffer, size_type buffer_size) - : iu16string(buffer, buffer_size - 1U) - { - this->assign(view.begin(), view.end()); - } -#endif - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -467,18 +431,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Assignment operator. - //************************************************************************* - u16string_ext& operator = (const std::u16string_view& view) - { - this->assign(view); - - return *this; - } -#endif - //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 068e9e3c1..029748aa5 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -183,18 +183,6 @@ namespace etl this->assign(view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit u32string(const std::u32string_view& view) - : iu32string(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(view.begin(), view.end()); - } -#endif - //************************************************************************* /// Returns a sub-string. ///\param position The position of the first character. Default = 0. @@ -249,18 +237,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Assignment operator. - //************************************************************************* - u32string& operator = (const std::u32string_view& view) - { - this->assign(view); - - return *this; - } -#endif - //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -409,18 +385,6 @@ namespace etl this->assign(view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit u32string_ext(const std::u32string_view& view, value_type* buffer, size_type buffer_size) - : iu32string(buffer, buffer_size - 1U) - { - this->assign(view.begin(), view.end()); - } -#endif - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -467,18 +431,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Assignment operator. - //************************************************************************* - u32string_ext& operator = (const std::u32string_view& view) - { - this->assign(view); - - return *this; - } -#endif - //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/u8string.h b/include/etl/u8string.h index 7cc1964f6..009f541ed 100644 --- a/include/etl/u8string.h +++ b/include/etl/u8string.h @@ -488,18 +488,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP20 - //************************************************************************* - /// Assignment operator. - //************************************************************************* - u8string_ext& operator = (const std::u8string_view& view) - { - this->assign(view); - - return *this; - } -#endif - //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 939646386..7107c7d8a 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -183,18 +183,6 @@ namespace etl this->assign(view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit wstring(const std::wstring_view& view) - : iwstring(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(view.begin(), view.end()); - } -#endif - //************************************************************************* /// Returns a sub-string. ///\param position The position of the first character. Default = 0. @@ -249,18 +237,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Assignment operator. - //************************************************************************* - wstring& operator = (const std::wstring_view& view) - { - this->assign(view); - - return *this; - } -#endif - //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -409,18 +385,6 @@ namespace etl this->assign(view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit wstring_ext(const std::wstring_view& view, value_type* buffer, size_type buffer_size) - : iwstring(buffer, buffer_size - 1U) - { - this->assign(view.begin(), view.end()); - } -#endif - //************************************************************************* /// Assignment operator. //************************************************************************* @@ -467,18 +431,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Assignment operator. - //************************************************************************* - wstring_ext& operator = (const std::wstring_view& view) - { - this->assign(view); - - return *this; - } -#endif - //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index cb3de4633..4da5716bd 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -36,10 +36,6 @@ SOFTWARE. #include "etl/string_view.h" #include "etl/fnv_1.h" -#if ETL_USING_STL && ETL_USING_CPP17 - #include -#endif - #undef STR #define STR(x) x @@ -62,10 +58,7 @@ namespace using value_t = Text::value_type; using TextL = etl::string<52>; using TextS = etl::string<4>; - using ViewETL = etl::string_view; -#if ETL_USING_STL && ETL_USING_CPP17 - using ViewSTD = std::string_view; -#endif + using View = etl::string_view; TextSTD initial_text; TextSTD less_text; @@ -299,20 +292,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - ViewETL view(initial_text.data(), initial_text.size()); - Text text(view); - - bool is_equal = Equal(initial_text, text); - CHECK(is_equal); - CHECK(text.size() == SIZE); - CHECK(!text.empty()); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) - { - ViewSTD view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -320,7 +300,6 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -599,26 +578,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) - { - Text text; - - text = ViewETL(STR("Hello World")); - - bool is_equal = Equal(TextSTD(STR("Hello World")), text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + TEST_FIXTURE(SetupFixture, test_assignment_from_view) { Text text; - text = ViewSTD(STR("Hello World")); + text = View(STR("Hello World")); bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); @@ -626,7 +590,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) @@ -1062,32 +1025,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_etl_view) - { - TextSTD compare_input(initial_text.c_str()); - Text input(initial_text.c_str()); - ViewETL view(input); - - TextSTD compare_text; - Text text; - - compare_text.assign(compare_input); - text.assign(view); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_std_view) + TEST_FIXTURE(SetupFixture, test_assign_view) { TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - ViewSTD view(input.data(), input.size()); + View view(input); TextSTD compare_text; Text text; @@ -1101,7 +1043,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) @@ -1621,35 +1562,13 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) - { - for (size_t offset = 0UL; offset <= short_text.size(); ++offset) - { - TextSTD compare_text(short_text.cbegin(), short_text.cend()); - Text text(short_text.cbegin(), short_text.cend()); - ViewETL view(insert_text.data(), insert_text.size()); - - text.insert(offset, view); - compare_text.insert(offset, insert_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewSTD view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1662,7 +1581,6 @@ namespace #endif } } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) @@ -1788,11 +1706,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_etl_view) + TEST_FIXTURE(SetupFixture, test_append_view) { TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1820,41 +1738,6 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_std_view) - { - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - ViewSTD append(insert_text.data(), insert_text.size()); - - // Non-overflow. - compare_text.append(insert_text); - text.append(append); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.size()); - - compare_text.append(initial_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.append(append); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -2166,110 +2049,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) - { - // Non-overflow short text, npos. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) { // Non-overflow short text, npos. TextSTD compare_text(short_text.c_str()); @@ -2277,7 +2057,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace"))); + text.replace(2, Text::npos, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2291,7 +2071,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace"))); + text.replace(2, 2, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2305,7 +2085,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2319,7 +2099,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2333,7 +2113,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace"))); + text.replace(2, 7, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2347,7 +2127,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2361,7 +2141,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2369,7 +2149,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) @@ -2432,7 +2211,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2440,7 +2219,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2454,7 +2233,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2468,7 +2247,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2482,7 +2261,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2491,68 +2270,6 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) { @@ -2670,7 +2387,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2678,7 +2395,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 4, View(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2692,7 +2409,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2706,7 +2423,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2720,7 +2437,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2734,7 +2451,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 7, View(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2748,7 +2465,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2762,7 +2479,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2776,7 +2493,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2785,17 +2502,16 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2807,126 +2523,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")).c_str()); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3915,45 +3514,13 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_etl_view) + TEST_FIXTURE(SetupFixture, test_find_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); Text needle(STR("needle")); - ViewETL needle_view(needle); - - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); - - size_t position1 = 0UL; - size_t position2 = 0UL; - - position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(position1, position2); - - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(Text::npos, position2); - - ViewETL pin_view(STR("pin")); - position2 = haystack.find(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_std_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); + View needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -3972,11 +3539,10 @@ namespace position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(Text::npos, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.find(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -4037,40 +3603,54 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_string) + TEST_FIXTURE(SetupFixture, test_contains_string) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); + TextL haystack(STR("A haystack with a needle and nothing else")); Text needle(STR("needle")); + Text pin(STR("pin")); + Text excess(STR("A really gigantic pin or needle that's really really big")); - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } - size_t position1 = TextSTD::npos; - size_t position2 = Text::npos; + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); - position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle, position2); - CHECK_EQUAL(position1, position2); + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); + } - position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle, haystack.size() - 10); - CHECK_EQUAL(position1, position2); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); - Text pin(STR("pin")); - position2 = haystack.rfind(pin); - CHECK_EQUAL(TextL::npos, position2); + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_string) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); Text needle(STR("needle")); - ViewETL needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4079,27 +3659,26 @@ namespace size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle_view, position2); + position2 = haystack.rfind(needle, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle_view, haystack.size() - 10); + position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewETL pin_view(STR("pin")); - position2 = haystack.rfind(pin_view); + Text pin(STR("pin")); + position2 = haystack.rfind(pin); CHECK_EQUAL(TextL::npos, position2); } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_std_view) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); + Text needle(STR("needle")); + View needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4115,11 +3694,10 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.rfind(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) @@ -4269,7 +3847,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_etl_view) + TEST_FIXTURE(SetupFixture, test_compare_view) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); @@ -4279,67 +3857,30 @@ namespace // Equal. compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewETL(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewETL(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewETL(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewETL(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewETL(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_std_view) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewSTD(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewSTD(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewSTD(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewSTD(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewSTD(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { @@ -4376,43 +3917,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - Text text(STR("xxxABCDEFyyy")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) { TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -4422,30 +3927,29 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) @@ -4483,7 +3987,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) { TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -4493,67 +3997,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - Text text(STR("xxxABCDEFyyy")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { @@ -4689,65 +4156,34 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewETL(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { @@ -4885,75 +4321,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - Text text(STR("ABCDEFABCDE")); - - size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { @@ -5104,74 +4504,38 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) @@ -5320,75 +4684,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - Text text(STR("ABCDEFABCDE")); - - size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index e2704e815..b2998e633 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -64,10 +64,7 @@ namespace using TextBufferL = std::array; using TextBufferS = std::array; - using ViewETL = etl::string_view; -#if ETL_USING_STL && ETL_USING_CPP17 - using ViewSTD = std::string_view; -#endif + using View = etl::string_view; TextSTD initial_text; TextSTD less_text; @@ -380,21 +377,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - ViewETL view(initial_text.data(), initial_text.size()); - TextBuffer buffer{0}; - Text text(view, buffer.data(), buffer.size()); - - bool is_equal = Equal(initial_text, text); - CHECK(is_equal); - CHECK(text.size() == SIZE); - CHECK(!text.empty()); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) - { - ViewSTD view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -403,7 +386,6 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -731,28 +713,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) - { - TextBuffer buffer{0}; - Text text(buffer.data(), buffer.size()); - - text = ViewETL(STR("Hello World")); - - bool is_equal = Equal(TextSTD(STR("Hello World")), text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + TEST_FIXTURE(SetupFixture, test_assignment_from_view) { TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - text = ViewSTD(STR("Hello World")); + text = View(STR("Hello World")); bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); @@ -760,7 +726,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) @@ -1222,35 +1187,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_etl_view) - { - TextSTD compare_input(initial_text.c_str()); - TextBuffer buffer{0}; - Text input(initial_text.c_str(), buffer.data(), buffer.size()); - ViewETL view(input); - - TextSTD compare_text; - TextBuffer buffer2{0}; - Text text(buffer2.data(), buffer2.size()); - - compare_text.assign(compare_input); - text.assign(view); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_std_view) + TEST_FIXTURE(SetupFixture, test_assign_view) { TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - ViewSTD view(input.data(), input.size()); + View view(input); TextSTD compare_text; TextBuffer buffer2{0}; @@ -1265,7 +1207,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) @@ -1816,31 +1757,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) - { - for (size_t offset = 0UL; offset <= short_text.size(); ++offset) - { - TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; - buffer.fill(0); - Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); - - text.insert(offset, view); - compare_text.insert(offset, insert_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { @@ -1848,7 +1765,7 @@ namespace TextBuffer buffer; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1861,7 +1778,6 @@ namespace #endif } } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) @@ -2004,12 +1920,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_etl_view) + TEST_FIXTURE(SetupFixture, test_append_view) { TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -2037,42 +1953,6 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_std_view) - { - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - ViewSTD append(insert_text.data(), insert_text.size()); - - // Non-overflow. - compare_text.append(insert_text); - text.append(append); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.size()); - - compare_text.append(initial_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.append(append); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -2406,111 +2286,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) - { - // Non-overflow short text, npos. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) { // Non-overflow short text, npos. TextSTD compare_text(short_text.c_str()); @@ -2519,7 +2295,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace"))); + text.replace(2, Text::npos, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2533,7 +2309,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace"))); + text.replace(2, 2, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2547,7 +2323,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2561,7 +2337,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2575,7 +2351,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace"))); + text.replace(2, 7, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2589,7 +2365,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2603,7 +2379,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2611,7 +2387,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) @@ -2676,69 +2451,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2747,7 +2460,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2761,7 +2474,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2775,7 +2488,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2789,7 +2502,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2797,7 +2510,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) @@ -2918,7 +2630,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2927,7 +2639,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 4, View(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2941,7 +2653,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2955,7 +2667,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2969,7 +2681,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2983,7 +2695,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 7, View(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2997,7 +2709,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3011,7 +2723,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3025,7 +2737,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3034,127 +2746,8 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -4215,44 +3808,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_etl_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - ViewETL needle_view(STR("needle")); - - TextSTD compare_haystack(the_haystack); - TextBufferL buffer2{0}; - Text haystack(the_haystack, buffer2.data(), buffer2.size()); - - size_t position1 = 0UL; - size_t position2 = 0UL; - - position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(position1, position2); - - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(TextL::npos, position2); - - ViewETL pin_view(STR("pin")); - position2 = haystack.find(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_std_view) + TEST_FIXTURE(SetupFixture, test_find_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - ViewSTD needle_view(STR("needle")); + View needle_view(STR("needle")); TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; @@ -4272,11 +3833,10 @@ namespace position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(TextL::npos, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.find(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -4340,6 +3900,53 @@ namespace CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { @@ -4373,12 +3980,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - ViewETL needle_view(STR("needle")); + View needle_view(STR("needle")); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4394,41 +4001,11 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewETL pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.rfind(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_std_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); - - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); - - size_t position1 = TextSTD::npos; - size_t position2 = TextL::npos; - - position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle_view, haystack.size() - 10); - CHECK_EQUAL(position1, position2); - - ViewSTD pin_view(STR("pin")); - position2 = haystack.rfind(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { @@ -4549,44 +4126,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_etl_view) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewETL(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewETL(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewETL(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewETL(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewETL(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_std_view) + TEST_FIXTURE(SetupFixture, test_compare_view) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; @@ -4597,31 +4137,29 @@ namespace // Equal. compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) @@ -4661,7 +4199,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) { TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; @@ -4672,68 +4210,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - TextBuffer buffer{0}; - Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { @@ -4772,7 +4272,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) { TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; @@ -4783,68 +4283,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - TextBuffer buffer{0}; - Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { @@ -4988,66 +4450,34 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewETL(STR("WXYZ"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) @@ -5194,76 +4624,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - TextBuffer buffer{0}; - Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) @@ -5425,77 +4818,40 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -5651,77 +5007,40 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - TextBuffer buffer{0}; - Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index 98557a8ef..a09f9a59c 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -81,10 +81,7 @@ namespace TextSTD insert_text; TextSTD longer_text; TextSTD short_text; - using ViewETL = etl::u16string_view; -#if ETL_USING_STL && ETL_USING_CPP17 - using ViewSTD = std::u16string_view; -#endif + using View = etl::u16string_view; const value_t* pinitial_text = STR("Hello World"); @@ -310,20 +307,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - ViewETL view(initial_text.data(), initial_text.size()); - Text text(view); - - bool is_equal = Equal(initial_text, text); - CHECK(is_equal); - CHECK(text.size() == SIZE); - CHECK(!text.empty()); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) - { - ViewSTD view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -331,7 +315,6 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -610,26 +593,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) - { - Text text; - - text = ViewETL(STR("Hello World")); - - bool is_equal = Equal(TextSTD(STR("Hello World")), text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + TEST_FIXTURE(SetupFixture, test_assignment_from_view) { Text text; - text = ViewSTD(STR("Hello World")); + text = View(STR("Hello World")); bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); @@ -637,7 +605,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) @@ -1072,32 +1039,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_etl_view) - { - TextSTD compare_input(initial_text.c_str()); - Text input(initial_text.c_str()); - ViewETL view(input); - - TextSTD compare_text; - Text text; - - compare_text.assign(compare_input); - text.assign(view); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_std_view) + TEST_FIXTURE(SetupFixture, test_assign_view) { TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - ViewSTD view(input.data(), input.size()); + View view(input); TextSTD compare_text; Text text; @@ -1111,7 +1057,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) @@ -1631,35 +1576,13 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) - { - for (size_t offset = 0UL; offset <= short_text.size(); ++offset) - { - TextSTD compare_text(short_text.cbegin(), short_text.cend()); - Text text(short_text.cbegin(), short_text.cend()); - ViewETL view(insert_text.data(), insert_text.size()); - - text.insert(offset, view); - compare_text.insert(offset, insert_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewSTD view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1672,7 +1595,6 @@ namespace #endif } } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) @@ -1798,11 +1720,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_etl_view) + TEST_FIXTURE(SetupFixture, test_append_view) { TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1830,41 +1752,6 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_std_view) - { - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - ViewSTD append(insert_text.data(), insert_text.size()); - - // Non-overflow. - compare_text.append(insert_text); - text.append(append); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.size()); - - compare_text.append(initial_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.append(append); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -2176,110 +2063,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) - { - // Non-overflow short text, npos. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) { // Non-overflow short text, npos. TextSTD compare_text(short_text.c_str()); @@ -2287,7 +2071,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace"))); + text.replace(2, Text::npos, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2301,7 +2085,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace"))); + text.replace(2, 2, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2315,7 +2099,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2329,7 +2113,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2343,7 +2127,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace"))); + text.replace(2, 7, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2357,7 +2141,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2371,7 +2155,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2379,7 +2163,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) @@ -2442,68 +2225,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2511,7 +2233,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2525,7 +2247,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2539,7 +2261,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2553,7 +2275,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2561,7 +2283,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) @@ -2680,7 +2401,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2688,7 +2409,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 4, View(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2702,7 +2423,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2716,7 +2437,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2730,7 +2451,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2744,7 +2465,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 7, View(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2758,7 +2479,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2772,7 +2493,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2786,7 +2507,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2795,17 +2516,16 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.replace(2, 4, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); + text.replace(2, 4, STR("Replace")); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2817,9 +2537,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, STR("Replace")); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2831,126 +2551,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(2, 4, STR("Replace")); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, STR("Replace")); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 4, STR("Replace with some text")); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, STR("Replace with some text")); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3925,45 +3528,13 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_etl_view) + TEST_FIXTURE(SetupFixture, test_find_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); Text needle(STR("needle")); - ViewETL needle_view(needle); - - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); - - size_t position1 = 0UL; - size_t position2 = 0UL; - - position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(position1, position2); - - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(Text::npos, position2); - - ViewETL pin_view(STR("pin")); - position2 = haystack.find(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_std_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); + View needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -3982,11 +3553,10 @@ namespace position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(Text::npos, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.find(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -4047,40 +3617,54 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_string) + TEST_FIXTURE(SetupFixture, test_contains_string) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); + TextL haystack(STR("A haystack with a needle and nothing else")); Text needle(STR("needle")); + Text pin(STR("pin")); + Text excess(STR("A really gigantic pin or needle that's really really big")); - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } - size_t position1 = TextSTD::npos; - size_t position2 = Text::npos; + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); - position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle, position2); - CHECK_EQUAL(position1, position2); + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); + } - position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle, haystack.size() - 10); - CHECK_EQUAL(position1, position2); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); - Text pin(STR("pin")); - position2 = haystack.rfind(pin); - CHECK_EQUAL(TextL::npos, position2); + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_string) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); Text needle(STR("needle")); - ViewETL needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4089,27 +3673,26 @@ namespace size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle_view, position2); + position2 = haystack.rfind(needle, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle_view, haystack.size() - 10); + position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewETL pin_view(STR("pin")); - position2 = haystack.rfind(pin_view); + Text pin(STR("pin")); + position2 = haystack.rfind(pin); CHECK_EQUAL(TextL::npos, position2); } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_std_view) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); + Text needle(STR("needle")); + View needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4125,11 +3708,10 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.rfind(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) @@ -4279,7 +3861,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_etl_view) + TEST_FIXTURE(SetupFixture, test_compare_view) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); @@ -4289,67 +3871,30 @@ namespace // Equal. compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewETL(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewETL(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewETL(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewETL(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewETL(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_std_view) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewSTD(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewSTD(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewSTD(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewSTD(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewSTD(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { @@ -4386,43 +3931,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - Text text(STR("xxxABCDEFyyy")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) { TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -4432,30 +3941,29 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) @@ -4493,7 +4001,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) { TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -4503,67 +4011,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - Text text(STR("xxxABCDEFyyy")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { @@ -4699,64 +4170,33 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewETL(STR("WXYZ"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) @@ -4895,74 +4335,38 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - Text text(STR("ABCDEFABCDE")); - - size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) @@ -5114,75 +4518,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -5330,75 +4698,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - Text text(STR("ABCDEFABCDE")); - - size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index 867a799ee..96fd23d5e 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -78,10 +78,7 @@ namespace using TextBufferL = std::array; using TextBufferS = std::array; - using ViewETL = etl::u16string_view; -#if ETL_USING_STL && ETL_USING_CPP17 - using ViewSTD = std::u16string_view; -#endif + using View = etl::u16string_view; TextSTD initial_text; TextSTD less_text; @@ -394,21 +391,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - ViewETL view(initial_text.data(), initial_text.size()); - TextBuffer buffer{0}; - Text text(view, buffer.data(), buffer.size()); - - bool is_equal = Equal(initial_text, text); - CHECK(is_equal); - CHECK(text.size() == SIZE); - CHECK(!text.empty()); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) - { - ViewSTD view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -417,7 +400,6 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -745,28 +727,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) - { - TextBuffer buffer{0}; - Text text(buffer.data(), buffer.size()); - - text = ViewETL(STR("Hello World")); - - bool is_equal = Equal(TextSTD(STR("Hello World")), text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + TEST_FIXTURE(SetupFixture, test_assignment_from_view) { TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - text = ViewSTD(STR("Hello World")); + text = View(STR("Hello World")); bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); @@ -774,7 +740,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) @@ -1236,35 +1201,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_etl_view) - { - TextSTD compare_input(initial_text.c_str()); - TextBuffer buffer{0}; - Text input(initial_text.c_str(), buffer.data(), buffer.size()); - ViewETL view(input); - - TextSTD compare_text; - TextBuffer buffer2{0}; - Text text(buffer2.data(), buffer2.size()); - - compare_text.assign(compare_input); - text.assign(view); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_std_view) + TEST_FIXTURE(SetupFixture, test_assign_view) { TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - ViewSTD view(input.data(), input.size()); + View view(input); TextSTD compare_text; TextBuffer buffer2{0}; @@ -1279,7 +1221,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) @@ -1830,31 +1771,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) - { - for (size_t offset = 0UL; offset <= short_text.size(); ++offset) - { - TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; - buffer.fill(0); - Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); - - text.insert(offset, view); - compare_text.insert(offset, insert_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { @@ -1862,7 +1779,7 @@ namespace TextBuffer buffer; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1875,7 +1792,6 @@ namespace #endif } } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) @@ -2018,12 +1934,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_etl_view) + TEST_FIXTURE(SetupFixture, test_append_view) { TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -2051,42 +1967,6 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_std_view) - { - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - ViewSTD append(insert_text.data(), insert_text.size()); - - // Non-overflow. - compare_text.append(insert_text); - text.append(append); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.size()); - - compare_text.append(initial_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.append(append); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -2420,111 +2300,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) - { - // Non-overflow short text, npos. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) { // Non-overflow short text, npos. TextSTD compare_text(short_text.c_str()); @@ -2533,7 +2309,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace"))); + text.replace(2, Text::npos, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2547,7 +2323,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace"))); + text.replace(2, 2, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2561,7 +2337,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2575,7 +2351,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2589,7 +2365,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace"))); + text.replace(2, 7, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2603,7 +2379,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2617,7 +2393,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2625,7 +2401,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) @@ -2690,69 +2465,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2761,7 +2474,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2775,7 +2488,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2789,7 +2502,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2803,7 +2516,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2811,7 +2524,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) @@ -2932,7 +2644,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2941,7 +2653,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 4, View(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2955,7 +2667,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2969,7 +2681,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2983,7 +2695,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2997,7 +2709,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 7, View(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3011,7 +2723,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3025,7 +2737,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3039,7 +2751,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3048,127 +2760,8 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -4229,44 +3822,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_etl_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - ViewETL needle_view(STR("needle")); - - TextSTD compare_haystack(the_haystack); - TextBufferL buffer2{0}; - Text haystack(the_haystack, buffer2.data(), buffer2.size()); - - size_t position1 = 0UL; - size_t position2 = 0UL; - - position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(position1, position2); - - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(TextL::npos, position2); - - ViewETL pin_view(STR("pin")); - position2 = haystack.find(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_std_view) + TEST_FIXTURE(SetupFixture, test_find_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - ViewSTD needle_view(STR("needle")); + View needle_view(STR("needle")); TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; @@ -4286,11 +3847,10 @@ namespace position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(TextL::npos, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.find(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -4354,6 +3914,53 @@ namespace CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { @@ -4387,12 +3994,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - ViewETL needle_view(STR("needle")); + View needle_view(STR("needle")); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4408,41 +4015,11 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewETL pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.rfind(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_std_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); - - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); - - size_t position1 = TextSTD::npos; - size_t position2 = TextL::npos; - - position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle_view, haystack.size() - 10); - CHECK_EQUAL(position1, position2); - - ViewSTD pin_view(STR("pin")); - position2 = haystack.rfind(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { @@ -4563,44 +4140,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_etl_view) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewETL(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewETL(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewETL(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewETL(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewETL(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_std_view) + TEST_FIXTURE(SetupFixture, test_compare_view) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; @@ -4611,31 +4151,29 @@ namespace // Equal. compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) @@ -4675,7 +4213,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) { TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; @@ -4686,68 +4224,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - TextBuffer buffer{0}; - Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { @@ -4786,7 +4286,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) { TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; @@ -4797,68 +4297,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - TextBuffer buffer{0}; - Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { @@ -5002,66 +4464,34 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewETL(STR("WXYZ"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) @@ -5208,76 +4638,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - TextBuffer buffer{0}; - Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) @@ -5439,77 +4832,40 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -5665,77 +5021,40 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - TextBuffer buffer{0}; - Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 2d9ef3229..2b607b33b 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -81,10 +81,7 @@ namespace TextSTD insert_text; TextSTD longer_text; TextSTD short_text; - using ViewETL = etl::u32string_view; -#if ETL_USING_STL && ETL_USING_CPP17 - using ViewSTD = std::u32string_view; -#endif + using View = etl::u32string_view; const value_t* pinitial_text = STR("Hello World"); @@ -310,20 +307,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - ViewETL view(initial_text.data(), initial_text.size()); - Text text(view); - - bool is_equal = Equal(initial_text, text); - CHECK(is_equal); - CHECK(text.size() == SIZE); - CHECK(!text.empty()); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) - { - ViewSTD view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -331,7 +315,6 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -610,26 +593,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) - { - Text text; - - text = ViewETL(STR("Hello World")); - - bool is_equal = Equal(TextSTD(STR("Hello World")), text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + TEST_FIXTURE(SetupFixture, test_assignment_from_view) { Text text; - text = ViewSTD(STR("Hello World")); + text = View(STR("Hello World")); bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); @@ -637,7 +605,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) @@ -1072,32 +1039,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_etl_view) - { - TextSTD compare_input(initial_text.c_str()); - Text input(initial_text.c_str()); - ViewETL view(input); - - TextSTD compare_text; - Text text; - - compare_text.assign(compare_input); - text.assign(view); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_std_view) + TEST_FIXTURE(SetupFixture, test_assign_view) { TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - ViewSTD view(input.data(), input.size()); + View view(input); TextSTD compare_text; Text text; @@ -1111,7 +1057,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) @@ -1631,35 +1576,13 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) - { - for (size_t offset = 0UL; offset <= short_text.size(); ++offset) - { - TextSTD compare_text(short_text.cbegin(), short_text.cend()); - Text text(short_text.cbegin(), short_text.cend()); - ViewETL view(insert_text.data(), insert_text.size()); - - text.insert(offset, view); - compare_text.insert(offset, insert_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewSTD view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1672,7 +1595,6 @@ namespace #endif } } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) @@ -1798,11 +1720,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_etl_view) + TEST_FIXTURE(SetupFixture, test_append_view) { TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1830,41 +1752,6 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_std_view) - { - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - ViewSTD append(insert_text.data(), insert_text.size()); - - // Non-overflow. - compare_text.append(insert_text); - text.append(append); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.size()); - - compare_text.append(initial_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.append(append); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -2176,110 +2063,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) - { - // Non-overflow short text, npos. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) { // Non-overflow short text, npos. TextSTD compare_text(short_text.c_str()); @@ -2287,7 +2071,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace"))); + text.replace(2, Text::npos, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2301,7 +2085,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace"))); + text.replace(2, 2, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2315,7 +2099,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2329,7 +2113,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2343,7 +2127,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace"))); + text.replace(2, 7, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2357,7 +2141,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2371,7 +2155,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2379,7 +2163,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) @@ -2442,68 +2225,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2511,7 +2233,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2525,7 +2247,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2539,7 +2261,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2553,7 +2275,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2561,7 +2283,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) @@ -2680,7 +2401,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2688,7 +2409,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 4, View(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2702,7 +2423,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2716,7 +2437,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2730,7 +2451,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2744,7 +2465,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 7, View(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2758,7 +2479,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2772,7 +2493,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2786,7 +2507,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2795,17 +2516,16 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.replace(2, 4, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); + text.replace(2, 4, STR("Replace")); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2817,9 +2537,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, STR("Replace")); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2831,126 +2551,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(2, 4, STR("Replace")); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, STR("Replace")); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 4, STR("Replace with some text")); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace with some text")); + text.replace(2, 4, STR("Replace with some text")); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3925,45 +3528,13 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_etl_view) + TEST_FIXTURE(SetupFixture, test_find_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); Text needle(STR("needle")); - ViewETL needle_view(needle); - - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); - - size_t position1 = 0UL; - size_t position2 = 0UL; - - position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(position1, position2); - - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(Text::npos, position2); - - ViewETL pin_view(STR("pin")); - position2 = haystack.find(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_std_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); + View needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -3982,11 +3553,10 @@ namespace position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(Text::npos, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.find(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -4047,40 +3617,54 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_string) + TEST_FIXTURE(SetupFixture, test_contains_string) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); + TextL haystack(STR("A haystack with a needle and nothing else")); Text needle(STR("needle")); + Text pin(STR("pin")); + Text excess(STR("A really gigantic pin or needle that's really really big")); - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } - size_t position1 = std::u32string::npos; - size_t position2 = Text::npos; + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); - position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle, position2); - CHECK_EQUAL(position1, position2); + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); + } - position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle, haystack.size() - 10); - CHECK_EQUAL(position1, position2); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); - Text pin(STR("pin")); - position2 = haystack.rfind(pin); - CHECK_EQUAL(TextL::npos, position2); + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_string) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); Text needle(STR("needle")); - ViewETL needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4089,27 +3673,26 @@ namespace size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle_view, position2); + position2 = haystack.rfind(needle, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle_view, haystack.size() - 10); + position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewETL pin_view(STR("pin")); - position2 = haystack.rfind(pin_view); + Text pin(STR("pin")); + position2 = haystack.rfind(pin); CHECK_EQUAL(TextL::npos, position2); } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_std_view) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); + Text needle(STR("needle")); + View needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4125,11 +3708,10 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.rfind(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) @@ -4279,7 +3861,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_etl_view) + TEST_FIXTURE(SetupFixture, test_compare_view) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); @@ -4289,67 +3871,30 @@ namespace // Equal. compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewETL(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewETL(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewETL(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewETL(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewETL(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_std_view) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewSTD(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewSTD(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewSTD(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewSTD(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewSTD(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { @@ -4386,43 +3931,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - Text text(STR("xxxABCDEFyyy")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) { TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -4432,30 +3941,29 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) @@ -4493,7 +4001,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) { TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -4503,67 +4011,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - Text text(STR("xxxABCDEFyyy")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { @@ -4699,64 +4170,33 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewETL(STR("WXYZ"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) @@ -4895,74 +4335,38 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - Text text(STR("ABCDEFABCDE")); - - size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) @@ -5114,75 +4518,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -5330,75 +4698,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - Text text(STR("ABCDEFABCDE")); - - size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 2461206b2..bdbaf7b22 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -78,10 +78,7 @@ namespace using TextBufferL = std::array; using TextBufferS = std::array; - using ViewETL = etl::u32string_view; -#if ETL_USING_STL && ETL_USING_CPP17 - using ViewSTD = std::u32string_view; -#endif + using View = etl::u32string_view; TextSTD initial_text; TextSTD less_text; @@ -394,21 +391,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - ViewETL view(initial_text.data(), initial_text.size()); - TextBuffer buffer{0}; - Text text(view, buffer.data(), buffer.size()); - - bool is_equal = Equal(initial_text, text); - CHECK(is_equal); - CHECK(text.size() == SIZE); - CHECK(!text.empty()); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) - { - ViewSTD view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -417,7 +400,6 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -745,28 +727,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) - { - TextBuffer buffer{0}; - Text text(buffer.data(), buffer.size()); - - text = ViewETL(STR("Hello World")); - - bool is_equal = Equal(TextSTD(STR("Hello World")), text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + TEST_FIXTURE(SetupFixture, test_assignment_from_view) { TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - text = ViewSTD(STR("Hello World")); + text = View(STR("Hello World")); bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); @@ -774,7 +740,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) @@ -1236,35 +1201,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_etl_view) - { - TextSTD compare_input(initial_text.c_str()); - TextBuffer buffer{0}; - Text input(initial_text.c_str(), buffer.data(), buffer.size()); - ViewETL view(input); - - TextSTD compare_text; - TextBuffer buffer2{0}; - Text text(buffer2.data(), buffer2.size()); - - compare_text.assign(compare_input); - text.assign(view); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_std_view) + TEST_FIXTURE(SetupFixture, test_assign_view) { TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - ViewSTD view(input.data(), input.size()); + View view(input); TextSTD compare_text; TextBuffer buffer2{0}; @@ -1279,7 +1221,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) @@ -1830,31 +1771,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) - { - for (size_t offset = 0UL; offset <= short_text.size(); ++offset) - { - TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; - buffer.fill(0); - Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); - - text.insert(offset, view); - compare_text.insert(offset, insert_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { @@ -1862,7 +1779,7 @@ namespace TextBuffer buffer; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1875,7 +1792,6 @@ namespace #endif } } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) @@ -2018,12 +1934,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_etl_view) + TEST_FIXTURE(SetupFixture, test_append_view) { TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -2051,42 +1967,6 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_std_view) - { - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - ViewSTD append(insert_text.data(), insert_text.size()); - - // Non-overflow. - compare_text.append(insert_text); - text.append(append); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.size()); - - compare_text.append(initial_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.append(append); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -2420,111 +2300,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) - { - // Non-overflow short text, npos. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) { // Non-overflow short text, npos. TextSTD compare_text(short_text.c_str()); @@ -2533,7 +2309,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace"))); + text.replace(2, Text::npos, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2547,7 +2323,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace"))); + text.replace(2, 2, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2561,7 +2337,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2575,7 +2351,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2589,7 +2365,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace"))); + text.replace(2, 7, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2603,7 +2379,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2617,7 +2393,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2625,7 +2401,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) @@ -2690,69 +2465,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2761,7 +2474,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2775,7 +2488,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2789,7 +2502,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2803,7 +2516,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2811,7 +2524,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) @@ -2932,7 +2644,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2941,7 +2653,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 4, View(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2955,7 +2667,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2969,7 +2681,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2983,7 +2695,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2997,7 +2709,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 7, View(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3011,7 +2723,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3025,7 +2737,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3039,7 +2751,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3048,127 +2760,8 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -4229,44 +3822,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_etl_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - ViewETL needle_view(STR("needle")); - - TextSTD compare_haystack(the_haystack); - TextBufferL buffer2{0}; - Text haystack(the_haystack, buffer2.data(), buffer2.size()); - - size_t position1 = 0UL; - size_t position2 = 0UL; - - position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(position1, position2); - - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(TextL::npos, position2); - - ViewETL pin_view(STR("pin")); - position2 = haystack.find(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_std_view) + TEST_FIXTURE(SetupFixture, test_find_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - ViewSTD needle_view(STR("needle")); + View needle_view(STR("needle")); TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; @@ -4286,11 +3847,10 @@ namespace position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(TextL::npos, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.find(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -4354,6 +3914,53 @@ namespace CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { @@ -4387,12 +3994,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - ViewETL needle_view(STR("needle")); + View needle_view(STR("needle")); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4408,41 +4015,11 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewETL pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.rfind(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_std_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); - - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); - - size_t position1 = TextSTD::npos; - size_t position2 = TextL::npos; - - position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle_view, haystack.size() - 10); - CHECK_EQUAL(position1, position2); - - ViewSTD pin_view(STR("pin")); - position2 = haystack.rfind(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { @@ -4563,44 +4140,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_etl_view) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewETL(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewETL(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewETL(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewETL(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewETL(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_std_view) + TEST_FIXTURE(SetupFixture, test_compare_view) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; @@ -4611,31 +4151,29 @@ namespace // Equal. compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) @@ -4675,7 +4213,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) { TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; @@ -4686,68 +4224,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - TextBuffer buffer{0}; - Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { @@ -4786,7 +4286,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) { TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; @@ -4797,68 +4297,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - TextBuffer buffer{0}; - Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { @@ -5002,66 +4464,34 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewETL(STR("WXYZ"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) @@ -5208,76 +4638,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - TextBuffer buffer{0}; - Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) @@ -5439,77 +4832,40 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -5665,77 +5021,40 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - TextBuffer buffer{0}; - Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_u8.cpp b/test/test_string_u8.cpp index 84020bbd8..5ce38042a 100644 --- a/test/test_string_u8.cpp +++ b/test/test_string_u8.cpp @@ -75,10 +75,7 @@ namespace using value_t = Text::value_type; using TextL = etl::u8string<52>; using TextS = etl::u8string<4>; - using ViewETL = etl::u8string_view; -#if ETL_USING_STL && ETL_USING_CPP17 - using ViewSTD = std::u8string_view; -#endif + using View = etl::u8string_view; TextSTD initial_text; TextSTD less_text; @@ -313,20 +310,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - ViewETL view(initial_text.data(), initial_text.size()); - Text text(view); - - bool is_equal = Equal(initial_text, text); - CHECK(is_equal); - CHECK(text.size() == SIZE); - CHECK(!text.empty()); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) - { - ViewSTD view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -334,7 +318,6 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -613,26 +596,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) - { - Text text; - - text = ViewETL(STR("Hello World")); - - bool is_equal = Equal(TextSTD(STR("Hello World")), text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + TEST_FIXTURE(SetupFixture, test_assignment_from_view) { Text text; - text = ViewSTD(STR("Hello World")); + text = View(STR("Hello World")); bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); @@ -640,7 +608,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) @@ -1075,32 +1042,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_etl_view) - { - TextSTD compare_input(initial_text.c_str()); - Text input(initial_text.c_str()); - ViewETL view(input); - - TextSTD compare_text; - Text text; - - compare_text.assign(compare_input); - text.assign(view); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_std_view) + TEST_FIXTURE(SetupFixture, test_assign_view) { TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - ViewSTD view(input.data(), input.size()); + View view(input); TextSTD compare_text; Text text; @@ -1114,7 +1060,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) @@ -1634,35 +1579,13 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) - { - for (size_t offset = 0UL; offset <= short_text.size(); ++offset) - { - TextSTD compare_text(short_text.cbegin(), short_text.cend()); - Text text(short_text.cbegin(), short_text.cend()); - ViewETL view(insert_text.data(), insert_text.size()); - - text.insert(offset, view); - compare_text.insert(offset, insert_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewSTD view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1675,7 +1598,6 @@ namespace #endif } } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) @@ -1801,11 +1723,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_etl_view) + TEST_FIXTURE(SetupFixture, test_append_view) { TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1833,41 +1755,6 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_std_view) - { - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - ViewSTD append(insert_text.data(), insert_text.size()); - - // Non-overflow. - compare_text.append(insert_text); - text.append(append); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.size()); - - compare_text.append(initial_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.append(append); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -2179,110 +2066,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) - { - // Non-overflow short text, npos. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) { // Non-overflow short text, npos. TextSTD compare_text(short_text.c_str()); @@ -2290,7 +2074,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace"))); + text.replace(2, Text::npos, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2304,7 +2088,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace"))); + text.replace(2, 2, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2318,7 +2102,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2332,7 +2116,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2346,7 +2130,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace"))); + text.replace(2, 7, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2360,7 +2144,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2374,7 +2158,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2382,7 +2166,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) @@ -2445,68 +2228,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2514,7 +2236,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2528,7 +2250,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2542,7 +2264,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2556,7 +2278,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2564,7 +2286,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) @@ -2683,7 +2404,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2691,7 +2412,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 4, View(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2705,7 +2426,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2719,7 +2440,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2733,7 +2454,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2747,7 +2468,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 7, View(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2761,7 +2482,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2775,7 +2496,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2789,7 +2510,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2798,17 +2519,16 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); + text.replace(2, 4, TextL(STR("Replace")).c_str()); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2820,9 +2540,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2834,126 +2554,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); + compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace")).c_str()); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace")).c_str()); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")).c_str()); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, TextL(STR("Replace")).c_str()); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")).c_str()); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); + text.replace(2, 4, TextL(STR("Replace with some text")).c_str()); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3928,45 +3531,13 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_etl_view) + TEST_FIXTURE(SetupFixture, test_find_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); Text needle(STR("needle")); - ViewETL needle_view(needle); - - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); - - size_t position1 = 0UL; - size_t position2 = 0UL; - - position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(position1, position2); - - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(Text::npos, position2); - - ViewETL pin_view(STR("pin")); - position2 = haystack.find(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_std_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); + View needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -3985,11 +3556,10 @@ namespace position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(Text::npos, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.find(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -4050,40 +3620,54 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_string) + TEST_FIXTURE(SetupFixture, test_contains_string) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); + TextL haystack(STR("A haystack with a needle and nothing else")); Text needle(STR("needle")); + Text pin(STR("pin")); + Text excess(STR("A really gigantic pin or needle that's really really big")); - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } - size_t position1 = std::u8string::npos; - size_t position2 = Text::npos; + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); - position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle, position2); - CHECK_EQUAL(position1, position2); + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); + } - position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle, haystack.size() - 10); - CHECK_EQUAL(position1, position2); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); - Text pin(STR("pin")); - position2 = haystack.rfind(pin); - CHECK_EQUAL(TextL::npos, position2); + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_string) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); Text needle(STR("needle")); - ViewETL needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4092,27 +3676,26 @@ namespace size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle_view, position2); + position2 = haystack.rfind(needle, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle_view, haystack.size() - 10); + position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewETL pin_view(STR("pin")); - position2 = haystack.rfind(pin_view); + Text pin(STR("pin")); + position2 = haystack.rfind(pin); CHECK_EQUAL(TextL::npos, position2); } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_std_view) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); + Text needle(STR("needle")); + View needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4128,11 +3711,10 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.rfind(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) @@ -4282,7 +3864,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_etl_view) + TEST_FIXTURE(SetupFixture, test_compare_view) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); @@ -4292,67 +3874,30 @@ namespace // Equal. compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewETL(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewETL(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewETL(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewETL(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewETL(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_std_view) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewSTD(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewSTD(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewSTD(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewSTD(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewSTD(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { @@ -4389,43 +3934,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - Text text(STR("xxxABCDEFyyy")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) { TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -4435,30 +3944,29 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) @@ -4496,7 +4004,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) { TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -4506,67 +4014,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - Text text(STR("xxxABCDEFyyy")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { @@ -4702,64 +4173,33 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewETL(STR("WXYZ"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) @@ -4898,74 +4338,38 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - Text text(STR("ABCDEFABCDE")); - - size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) @@ -5117,75 +4521,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -5333,75 +4701,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - Text text(STR("ABCDEFABCDE")); - - size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_u8_external_buffer.cpp b/test/test_string_u8_external_buffer.cpp index d0a02373c..085f77380 100644 --- a/test/test_string_u8_external_buffer.cpp +++ b/test/test_string_u8_external_buffer.cpp @@ -81,10 +81,7 @@ namespace using TextBufferL = std::array; using TextBufferS = std::array; - using ViewETL = etl::u8string_view; -#if ETL_USING_STL && ETL_USING_CPP17 - using ViewSTD = std::u8string_view; -#endif + using View = etl::u8string_view; TextSTD initial_text; TextSTD less_text; @@ -397,21 +394,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - ViewETL view(initial_text.data(), initial_text.size()); - TextBuffer buffer{0}; - Text text(view, buffer.data(), buffer.size()); - - bool is_equal = Equal(initial_text, text); - CHECK(is_equal); - CHECK(text.size() == SIZE); - CHECK(!text.empty()); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) - { - ViewSTD view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -420,7 +403,6 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -748,28 +730,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) - { - TextBuffer buffer{0}; - Text text(buffer.data(), buffer.size()); - - text = ViewETL(STR("Hello World")); - - bool is_equal = Equal(TextSTD(STR("Hello World")), text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + TEST_FIXTURE(SetupFixture, test_assignment_from_view) { TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - text = ViewSTD(STR("Hello World")); + text = View(STR("Hello World")); bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); @@ -777,7 +743,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) @@ -1239,35 +1204,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_etl_view) - { - TextSTD compare_input(initial_text.c_str()); - TextBuffer buffer{0}; - Text input(initial_text.c_str(), buffer.data(), buffer.size()); - ViewETL view(input); - - TextSTD compare_text; - TextBuffer buffer2{0}; - Text text(buffer2.data(), buffer2.size()); - - compare_text.assign(compare_input); - text.assign(view); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_std_view) + TEST_FIXTURE(SetupFixture, test_assign_view) { TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - ViewSTD view(input.data(), input.size()); + View view(input); TextSTD compare_text; TextBuffer buffer2{0}; @@ -1282,7 +1224,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) @@ -1833,31 +1774,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) - { - for (size_t offset = 0UL; offset <= short_text.size(); ++offset) - { - TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; - buffer.fill(0); - Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); - - text.insert(offset, view); - compare_text.insert(offset, insert_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { @@ -1865,7 +1782,7 @@ namespace TextBuffer buffer; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1878,7 +1795,6 @@ namespace #endif } } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) @@ -2021,12 +1937,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_etl_view) + TEST_FIXTURE(SetupFixture, test_append_view) { TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -2054,42 +1970,6 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_std_view) - { - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - ViewSTD append(insert_text.data(), insert_text.size()); - - // Non-overflow. - compare_text.append(insert_text); - text.append(append); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.size()); - - compare_text.append(initial_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.append(append); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -2423,111 +2303,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) - { - // Non-overflow short text, npos. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) { // Non-overflow short text, npos. TextSTD compare_text(short_text.c_str()); @@ -2536,7 +2312,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace"))); + text.replace(2, Text::npos, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2550,7 +2326,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace"))); + text.replace(2, 2, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2564,7 +2340,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2578,7 +2354,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2592,7 +2368,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace"))); + text.replace(2, 7, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2606,7 +2382,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2620,7 +2396,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2628,7 +2404,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) @@ -2693,69 +2468,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2764,7 +2477,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2778,7 +2491,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2792,7 +2505,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2806,7 +2519,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2814,7 +2527,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) @@ -2935,7 +2647,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2944,7 +2656,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 4, View(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2958,7 +2670,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2972,7 +2684,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2986,7 +2698,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3000,7 +2712,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 7, View(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3014,7 +2726,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3028,7 +2740,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3042,7 +2754,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3051,127 +2763,8 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -4232,44 +3825,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_etl_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - ViewETL needle_view(STR("needle")); - - TextSTD compare_haystack(the_haystack); - TextBufferL buffer2{0}; - Text haystack(the_haystack, buffer2.data(), buffer2.size()); - - size_t position1 = 0UL; - size_t position2 = 0UL; - - position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(position1, position2); - - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(TextL::npos, position2); - - ViewETL pin_view(STR("pin")); - position2 = haystack.find(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_std_view) + TEST_FIXTURE(SetupFixture, test_find_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - ViewSTD needle_view(STR("needle")); + View needle_view(STR("needle")); TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; @@ -4289,11 +3850,10 @@ namespace position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(TextL::npos, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.find(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -4326,6 +3886,53 @@ namespace CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_char_pointer_n) { @@ -4390,12 +3997,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - ViewETL needle_view(STR("needle")); + View needle_view(STR("needle")); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4411,41 +4018,11 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewETL pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.rfind(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_std_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); - - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); - - size_t position1 = TextSTD::npos; - size_t position2 = TextL::npos; - - position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle_view, haystack.size() - 10); - CHECK_EQUAL(position1, position2); - - ViewSTD pin_view(STR("pin")); - position2 = haystack.rfind(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { @@ -4566,44 +4143,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_etl_view) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewETL(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewETL(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewETL(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewETL(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewETL(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_std_view) + TEST_FIXTURE(SetupFixture, test_compare_view) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; @@ -4614,31 +4154,29 @@ namespace // Equal. compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) @@ -4678,7 +4216,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) { TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; @@ -4689,68 +4227,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - TextBuffer buffer{0}; - Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) { @@ -4789,7 +4289,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) { TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; @@ -4800,68 +4300,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - TextBuffer buffer{0}; - Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { @@ -5005,66 +4467,34 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewETL(STR("WXYZ"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) @@ -5211,76 +4641,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - TextBuffer buffer{0}; - Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) @@ -5442,77 +4835,40 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -5668,77 +5024,40 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - TextBuffer buffer{0}; - Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index b8f51dba4..1a8ed43bd 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -81,10 +81,8 @@ namespace TextSTD insert_text; TextSTD longer_text; TextSTD short_text; - using ViewETL = etl::wstring_view; -#if ETL_USING_STL && ETL_USING_CPP17 - using ViewSTD = std::wstring_view; -#endif + + using View = etl::wstring_view; const value_t* pinitial_text = STR("Hello World"); @@ -310,20 +308,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - ViewETL view(initial_text.data(), initial_text.size()); - Text text(view); - - bool is_equal = Equal(initial_text, text); - CHECK(is_equal); - CHECK(text.size() == SIZE); - CHECK(!text.empty()); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) - { - ViewSTD view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); Text text(view); bool is_equal = Equal(initial_text, text); @@ -331,7 +316,6 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -610,26 +594,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) - { - Text text; - - text = ViewETL(STR("Hello World")); - - bool is_equal = Equal(TextSTD(STR("Hello World")), text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + TEST_FIXTURE(SetupFixture, test_assignment_from_view) { Text text; - text = ViewSTD(STR("Hello World")); + text = View(STR("Hello World")); bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); @@ -637,7 +606,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) @@ -1072,32 +1040,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_etl_view) - { - TextSTD compare_input(initial_text.c_str()); - Text input(initial_text.c_str()); - ViewETL view(input); - - TextSTD compare_text; - Text text; - - compare_text.assign(compare_input); - text.assign(view); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_std_view) + TEST_FIXTURE(SetupFixture, test_assign_view) { TextSTD compare_input(initial_text.c_str()); Text input(initial_text.c_str()); - ViewSTD view(input.data(), input.size()); + View view(input); TextSTD compare_text; Text text; @@ -1111,7 +1058,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) @@ -1631,35 +1577,13 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) - { - for (size_t offset = 0UL; offset <= short_text.size(); ++offset) - { - TextSTD compare_text(short_text.cbegin(), short_text.cend()); - Text text(short_text.cbegin(), short_text.cend()); - ViewETL view(insert_text.data(), insert_text.size()); - - text.insert(offset, view); - compare_text.insert(offset, insert_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); Text text(short_text.cbegin(), short_text.cend()); - ViewSTD view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1672,7 +1596,6 @@ namespace #endif } } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) @@ -1798,11 +1721,11 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_etl_view) + TEST_FIXTURE(SetupFixture, test_append_view) { TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -1830,41 +1753,6 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_std_view) - { - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - ViewSTD append(insert_text.data(), insert_text.size()); - - // Non-overflow. - compare_text.append(insert_text); - text.append(append); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.size()); - - compare_text.append(initial_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.append(append); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -2176,110 +2064,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) - { - // Non-overflow short text, npos. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) { // Non-overflow short text, npos. TextSTD compare_text(short_text.c_str()); @@ -2287,7 +2072,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace"))); + text.replace(2, Text::npos, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2301,7 +2086,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace"))); + text.replace(2, 2, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2315,7 +2100,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2329,7 +2114,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2343,7 +2128,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace"))); + text.replace(2, 7, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2357,7 +2142,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2371,7 +2156,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2379,7 +2164,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) @@ -2442,68 +2226,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2511,7 +2234,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2525,7 +2248,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2539,7 +2262,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2553,7 +2276,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2561,7 +2284,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) @@ -2680,7 +2402,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2688,7 +2410,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 4, View(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2702,7 +2424,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2716,7 +2438,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2730,7 +2452,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2744,7 +2466,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 7, View(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2758,7 +2480,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2772,7 +2494,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2786,7 +2508,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2795,17 +2517,16 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); Text text(short_text.c_str()); - compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); + compare_text.replace(2, 4, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); + text.replace(2, 4, STR("Replace")); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2817,9 +2538,9 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); + compare_text.replace(2, TextSTD::npos, STR("Replace")); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, STR("Replace")); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2831,124 +2552,7 @@ namespace compare_text.assign(short_text.c_str()); text.assign(short_text.c_str()); - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - Text text(short_text.c_str()); - - compare_text.replace(2, 4, STR("Replace")); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, STR("Replace")); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, STR("Replace")); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, STR("Replace")); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 4, STR("Replace with some text")); + compare_text.replace(2, 4, STR("Replace with some text")); compare_text.resize(std::min(compare_text.size(), SIZE)); text.replace(2, 4, STR("Replace with some text")); @@ -3925,45 +3529,13 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_etl_view) + TEST_FIXTURE(SetupFixture, test_find_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); Text needle(STR("needle")); - ViewETL needle_view(needle); - - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); - - size_t position1 = 0UL; - size_t position2 = 0UL; - - position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(position1, position2); - - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(Text::npos, position2); - - ViewETL pin_view(STR("pin")); - position2 = haystack.find(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_std_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); + View needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -3982,11 +3554,10 @@ namespace position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(Text::npos, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.find(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -4047,40 +3618,54 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_string) + TEST_FIXTURE(SetupFixture, test_contains_string) { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); + TextL haystack(STR("A haystack with a needle and nothing else")); Text needle(STR("needle")); + Text pin(STR("pin")); + Text excess(STR("A really gigantic pin or needle that's really really big")); - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } - size_t position1 = std::wstring::npos; - size_t position2 = Text::npos; + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); - position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle, position2); - CHECK_EQUAL(position1, position2); + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + CHECK_FALSE(haystack.contains(View(STR("A really gigantic pin or needle that's really really big")))); + } - position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle, haystack.size() - 10); - CHECK_EQUAL(position1, position2); + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); - Text pin(STR("pin")); - position2 = haystack.rfind(pin); - CHECK_EQUAL(TextL::npos, position2); + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + CHECK_FALSE(haystack.contains(STR("A really gigantic pin or needle that's really really big"))); } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_rfind_string) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); Text needle(STR("needle")); - ViewETL needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4089,27 +3674,26 @@ namespace size_t position2 = Text::npos; position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle_view, position2); + position2 = haystack.rfind(needle, position2); CHECK_EQUAL(position1, position2); position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle_view, haystack.size() - 10); + position2 = haystack.rfind(needle, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewETL pin_view(STR("pin")); - position2 = haystack.rfind(pin_view); + Text pin(STR("pin")); + position2 = haystack.rfind(pin); CHECK_EQUAL(TextL::npos, position2); } -#if ETL_USING_STL && ETL_USING_CPP17 //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_std_view) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); + Text needle(STR("needle")); + View needle_view(needle); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4125,11 +3709,10 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.rfind(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) @@ -4279,43 +3862,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_etl_view) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewETL(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewETL(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewETL(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewETL(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewETL(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_std_view) + TEST_FIXTURE(SetupFixture, test_compare_view) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); @@ -4325,30 +3872,29 @@ namespace // Equal. compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewSTD(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewSTD(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewSTD(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewSTD(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewSTD(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) @@ -4386,43 +3932,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - Text text(STR("xxxABCDEFyyy")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) { TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -4432,30 +3942,29 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) @@ -4493,7 +4002,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) { TextSTD compare_text(STR("xxxABCDEFyyy")); Text text(STR("xxxABCDEFyyy")); @@ -4503,67 +4012,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - Text text(STR("xxxABCDEFyyy")); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { @@ -4699,64 +4171,33 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewETL(STR("WXYZ"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) @@ -4895,74 +4336,38 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - Text text(STR("ABCDEFABCDE")); - - size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) @@ -5114,75 +4519,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) { TextSTD compare_text(STR("ABCDEF")); Text text(STR("ABCDEF")); size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - Text text(STR("ABCDEF")); - - size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) { @@ -5330,75 +4699,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); Text text(STR("ABCDEFABCDE")); size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - Text text(STR("ABCDEFABCDE")); - - size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index 443b0b8a8..5d277936c 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -75,19 +75,13 @@ namespace using TextSTD = std::wstring; using value_t = Text::value_type; - using ViewETL = etl::wstring_view; -#if ETL_USING_STL && ETL_USING_CPP17 - using ViewSTD = std::wstring_view; -#endif + using View = etl::wstring_view; using TextBuffer = std::array; using TextBufferL = std::array; using TextBufferS = std::array; - using ViewETL = etl::wstring_view; -#if ETL_USING_STL && ETL_USING_CPP17 - using ViewSTD = std::wstring_view; -#endif + using View = etl::wstring_view; TextSTD initial_text; TextSTD less_text; @@ -400,21 +394,7 @@ namespace //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_etl_string_view) { - ViewETL view(initial_text.data(), initial_text.size()); - TextBuffer buffer{0}; - Text text(view, buffer.data(), buffer.size()); - - bool is_equal = Equal(initial_text, text); - CHECK(is_equal); - CHECK(text.size() == SIZE); - CHECK(!text.empty()); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_constructor_from_std_string_view) - { - ViewSTD view(initial_text.data(), initial_text.size()); + View view(initial_text.data(), initial_text.size()); TextBuffer buffer{0}; Text text(view, buffer.data(), buffer.size()); @@ -423,7 +403,6 @@ namespace CHECK(text.size() == SIZE); CHECK(!text.empty()); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) @@ -751,28 +730,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_etl_view) - { - TextBuffer buffer{0}; - Text text(buffer.data(), buffer.size()); - - text = ViewETL(STR("Hello World")); - - bool is_equal = Equal(TextSTD(STR("Hello World")), text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assignment_from_std_view) + TEST_FIXTURE(SetupFixture, test_assignment_from_view) { TextBuffer buffer{0}; Text text(buffer.data(), buffer.size()); - text = ViewSTD(STR("Hello World")); + text = View(STR("Hello World")); bool is_equal = Equal(TextSTD(STR("Hello World")), text); CHECK(is_equal); @@ -780,7 +743,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_begin) @@ -1242,35 +1204,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_etl_view) - { - TextSTD compare_input(initial_text.c_str()); - TextBuffer buffer{0}; - Text input(initial_text.c_str(), buffer.data(), buffer.size()); - ViewETL view(input); - - TextSTD compare_text; - TextBuffer buffer2{0}; - Text text(buffer2.data(), buffer2.size()); - - compare_text.assign(compare_input); - text.assign(view); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_assign_std_view) + TEST_FIXTURE(SetupFixture, test_assign_view) { TextSTD compare_input(initial_text.c_str()); TextBuffer buffer{0}; Text input(initial_text.c_str(), buffer.data(), buffer.size()); - ViewSTD view(input.data(), input.size()); + View view(input); TextSTD compare_text; TextBuffer buffer2{0}; @@ -1285,7 +1224,6 @@ namespace CHECK(!text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_string_excess) @@ -1836,31 +1774,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_etl_view) - { - for (size_t offset = 0UL; offset <= short_text.size(); ++offset) - { - TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; - buffer.fill(0); - Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); - - text.insert(offset, view); - compare_text.insert(offset, insert_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - } - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_size_t_position_std_view) + TEST_FIXTURE(SetupFixture, test_insert_size_t_position_view) { for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { @@ -1868,7 +1782,7 @@ namespace TextBuffer buffer; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); text.insert(offset, view); compare_text.insert(offset, insert_text); @@ -1881,7 +1795,6 @@ namespace #endif } } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_size_t_position_string_excess) @@ -2024,12 +1937,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_etl_view) + TEST_FIXTURE(SetupFixture, test_append_view) { TextSTD compare_text(short_text.c_str()); TextBuffer buffer{0}; Text text(short_text.c_str(), buffer.data(), buffer.size()); - ViewETL view(insert_text.data(), insert_text.size()); + View view(insert_text.data(), insert_text.size()); // Non-overflow. compare_text.append(insert_text); @@ -2057,42 +1970,6 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_append_std_view) - { - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - ViewSTD append(insert_text.data(), insert_text.size()); - - // Non-overflow. - compare_text.append(insert_text); - text.append(append); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - append = ViewSTD(initial_text.data(), initial_text.size()); - - compare_text.append(initial_text); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.append(append); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_append_truncated_string) { @@ -2426,111 +2303,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view) - { - // Non-overflow short text, npos. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view) { // Non-overflow short text, npos. TextSTD compare_text(short_text.c_str()); @@ -2539,7 +2312,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace"))); + text.replace(2, Text::npos, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2553,7 +2326,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace"))); + text.replace(2, 2, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2567,7 +2340,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2581,7 +2354,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2595,7 +2368,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace"))); + text.replace(2, 7, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2609,7 +2382,7 @@ namespace compare_text.replace(2, 2, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 2, ViewSTD(STR("Replace with some text"))); + text.replace(2, 2, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2623,7 +2396,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text"))); + text.replace(2, Text::npos, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2631,7 +2404,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_first_last_string) @@ -2696,69 +2468,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_etl_view) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace"))); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewETL(STR("Replace"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewETL(STR("Replace with some text"))); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_first_last_std_view) + TEST_FIXTURE(SetupFixture, test_replace_first_last_view) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2767,7 +2477,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace"))); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2781,7 +2491,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2795,7 +2505,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, TextSTD(STR("Replace"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 9, ViewSTD(STR("Replace"))); + text.replace(text.begin() + 2, text.begin() + 9, View(STR("Replace"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2809,7 +2519,7 @@ namespace compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, TextSTD(STR("Replace with some text"))); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(text.begin() + 2, text.begin() + 4, ViewSTD(STR("Replace with some text"))); + text.replace(text.begin() + 2, text.begin() + 4, View(STR("Replace with some text"))); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2817,7 +2527,6 @@ namespace CHECK(text.is_truncated()); #endif } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_string_subposition_sublength) @@ -2938,7 +2647,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_replace_position_length_view_subposition_sublength) { // Non-overflow short text. TextSTD compare_text(short_text.c_str()); @@ -2947,7 +2656,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 4, View(STR("Replace")), 1, 5); bool is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2961,7 +2670,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2975,7 +2684,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -2989,7 +2698,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3003,7 +2712,7 @@ namespace compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewETL(STR("Replace")), 1, 5); + text.replace(2, 7, View(STR("Replace")), 1, 5); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3017,7 +2726,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3031,7 +2740,7 @@ namespace compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewETL(STR("Replace with some text")), 1, 15); + text.replace(2, 4, View(STR("Replace with some text")), 1, 15); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3045,7 +2754,7 @@ namespace compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewETL(STR("Replace with some text")), 1, Text::npos); + text.replace(2, Text::npos, View(STR("Replace with some text")), 1, Text::npos); is_equal = Equal(compare_text, text); CHECK(is_equal); @@ -3054,125 +2763,6 @@ namespace #endif } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_replace_position_length_std_view_subposition_sublength) - { - // Non-overflow short text. - TextSTD compare_text(short_text.c_str()); - TextBuffer buffer{0}; - Text text(short_text.c_str(), buffer.data(), buffer.size()); - - compare_text.replace(2, 4, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace")), 1, 5); - - bool is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow short text. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow short text, npos. - compare_text.assign(short_text.c_str()); - text.assign(short_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Non-overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 7, TextSTD(STR("Replace")), 1, 5); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 7, ViewSTD(STR("Replace")), 1, 5); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Non-overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(!text.is_truncated()); -#endif - - // Overflow. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, 4, TextSTD(STR("Replace with some text")), 1, 15); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, 4, ViewSTD(STR("Replace with some text")), 1, 15); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - - // Overflow, npos. - compare_text.assign(initial_text.c_str()); - text.assign(initial_text.c_str()); - - compare_text.replace(2, TextSTD::npos, TextSTD(STR("Replace with some text")), 1, TextSTD::npos); - compare_text.resize(std::min(compare_text.size(), SIZE)); - text.replace(2, Text::npos, ViewSTD(STR("Replace with some text")), 1, Text::npos); - - is_equal = Equal(compare_text, text); - CHECK(is_equal); -#if ETL_HAS_STRING_TRUNCATION_CHECKS - CHECK(text.is_truncated()); -#endif - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_replace_position_length_pointer) { @@ -4235,44 +3825,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_etl_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - ViewETL needle_view(STR("needle")); - - TextSTD compare_haystack(the_haystack); - TextBufferL buffer2{0}; - Text haystack(the_haystack, buffer2.data(), buffer2.size()); - - size_t position1 = 0UL; - size_t position2 = 0UL; - - position1 = compare_haystack.find(compare_needle, position1); - position2 = haystack.find(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.find(compare_needle, position1 + 1); - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(position1, position2); - - position2 = haystack.find(needle_view, position2 + 1); - CHECK_EQUAL(TextL::npos, position2); - - ViewETL pin_view(STR("pin")); - position2 = haystack.find(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_std_view) + TEST_FIXTURE(SetupFixture, test_find_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - ViewSTD needle_view(STR("needle")); + View needle_view(STR("needle")); TextSTD compare_haystack(the_haystack); TextBufferL buffer2{0}; @@ -4292,11 +3850,10 @@ namespace position2 = haystack.find(needle_view, position2 + 1); CHECK_EQUAL(TextL::npos, position2); - ViewSTD pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.find(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_pointer) @@ -4360,6 +3917,53 @@ namespace CHECK_EQUAL(IText::npos, position2); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text needle(STR("needle"), buffer2.data(), buffer2.size()); + Text pin(STR("pin"), buffer3.data(), buffer3.size()); + Text excess(STR("A really gigantic pin or needle that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.contains(needle)); + CHECK_FALSE(haystack.contains(pin)); + CHECK_FALSE(haystack.contains(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(View(STR("needle")))); + CHECK_FALSE(haystack.contains(View(STR("pin")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR("needle"))); + CHECK_FALSE(haystack.contains(STR("pin"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_contains_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.contains(STR('l'))); + CHECK_FALSE(haystack.contains(STR('p'))); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { @@ -4393,12 +3997,12 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_etl_view) + TEST_FIXTURE(SetupFixture, test_rfind_view) { const value_t* the_haystack = STR("A haystack with a needle and another needle"); TextSTD compare_needle(STR("needle")); - ViewETL needle_view(STR("needle")); + View needle_view(STR("needle")); TextSTD compare_haystack(the_haystack); TextL haystack(the_haystack); @@ -4414,41 +4018,11 @@ namespace position2 = haystack.rfind(needle_view, haystack.size() - 10); CHECK_EQUAL(position1, position2); - ViewETL pin_view(STR("pin")); + View pin_view(STR("pin")); position2 = haystack.rfind(pin_view); CHECK_EQUAL(TextL::npos, position2); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_rfind_std_view) - { - const value_t* the_haystack = STR("A haystack with a needle and another needle"); - - TextSTD compare_needle(STR("needle")); - TextSTD needle(STR("needle")); - ViewSTD needle_view(needle); - - TextSTD compare_haystack(the_haystack); - TextL haystack(the_haystack); - - size_t position1 = TextSTD::npos; - size_t position2 = TextL::npos; - - position1 = compare_haystack.rfind(compare_needle, position1); - position2 = haystack.rfind(needle_view, position2); - CHECK_EQUAL(position1, position2); - - position1 = compare_haystack.rfind(compare_needle, compare_haystack.size() - 10); - position2 = haystack.rfind(needle_view, haystack.size() - 10); - CHECK_EQUAL(position1, position2); - - ViewSTD pin_view(STR("pin")); - position2 = haystack.rfind(pin_view); - CHECK_EQUAL(TextL::npos, position2); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_pointer) { @@ -4569,7 +4143,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_etl_view) + TEST_FIXTURE(SetupFixture, test_compare_view) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; @@ -4580,69 +4154,30 @@ namespace // Equal. compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewETL(STR("ABCDEF"))); + result = text.compare(View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewETL(STR("ABCDEE"))); + result = text.compare(View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewETL(STR("ABCDEG"))); + result = text.compare(View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewETL(STR("ABCDE"))); + result = text.compare(View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewETL(STR("ABCDEFG"))); + result = text.compare(View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_std_view) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(TextSTD(STR("ABCDEF"))); - result = text.compare(ViewSTD(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(TextSTD(STR("ABCDEE"))); - result = text.compare(ViewSTD(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(TextSTD(STR("ABCDEG"))); - result = text.compare(ViewSTD(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(TextSTD(STR("ABCDE"))); - result = text.compare(ViewSTD(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(TextSTD(STR("ABCDEFG"))); - result = text.compare(ViewSTD(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } -#endif - - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string) { @@ -4681,44 +4216,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - TextBuffer buffer{0}; - Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEF"))); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEE"))); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEG"))); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewETL(STR("ABCDE"))); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewETL(STR("ABCDEFG"))); - CHECK(compares_agree(compare_result, result)); - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view) { TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; @@ -4729,30 +4227,29 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEF"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEF"))); + result = text.compare(3, 6, View(STR("ABCDEF"))); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEE"))); + result = text.compare(3, 6, View(STR("ABCDEE"))); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEG"))); + result = text.compare(3, 6, View(STR("ABCDEG"))); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDE"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDE"))); + result = text.compare(3, 6, View(STR("ABCDE"))); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("ABCDEFG"))); - result = text.compare(3, 6, ViewSTD(STR("ABCDEFG"))); + result = text.compare(3, 6, View(STR("ABCDEFG"))); CHECK(compares_agree(compare_result, result)); } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_position_length_string_subposition_sublength) @@ -4792,7 +4289,7 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_etl_view_subposition_sublength) + TEST_FIXTURE(SetupFixture, test_compare_position_length_view_subposition_sublength) { TextSTD compare_text(STR("xxxABCDEFyyy")); TextBuffer buffer{0}; @@ -4803,68 +4300,30 @@ namespace // Equal. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEFbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Less. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEEbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEEbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Greater. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewETL(STR("aaABCDEGbb")), 2, 6); + result = text.compare(3, 6, View(STR("aaABCDEGbb")), 2, 6); CHECK(compares_agree(compare_result, result)); // Shorter. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewETL(STR("aaABCDEbb")), 2, 5); + result = text.compare(3, 6, View(STR("aaABCDEbb")), 2, 5); CHECK(compares_agree(compare_result, result)); // Longer. compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewETL(STR("aaABCDEFGbb")), 2, 7); + result = text.compare(3, 6, View(STR("aaABCDEFGbb")), 2, 7); CHECK(compares_agree(compare_result, result)); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_compare_position_length_std_view_subposition_sublength) - { - TextSTD compare_text(STR("xxxABCDEFyyy")); - TextBuffer buffer{0}; - Text text(STR("xxxABCDEFyyy"), buffer.data(), buffer.size()); - - int compare_result; - int result; - - // Equal. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Less. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEEbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEEbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Greater. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEGbb")), 2, 6); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEGbb")), 2, 6); - CHECK(compares_agree(compare_result, result)); - - // Shorter. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEbb")), 2, 5); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEbb")), 2, 5); - CHECK(compares_agree(compare_result, result)); - - // Longer. - compare_result = compare_text.compare(3, 6, TextSTD(STR("aaABCDEFGbb")), 2, 7); - result = text.compare(3, 6, ViewSTD(STR("aaABCDEFGbb")), 2, 7); - CHECK(compares_agree(compare_result, result)); - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_compare_c_string) { @@ -5008,67 +4467,35 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_of_view_position) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewETL(STR("ZCXF"))); + size_t position2 = text.find_first_of(View(STR("ZCXF"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewETL(STR("WXYZ"))); + position2 = text.find_first_of(View(STR("WXYZ"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 3); + position2 = text.find_first_of(View(STR("ZCXF")), 3); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewETL(STR("ZCXF")), 100); + position2 = text.find_first_of(View(STR("ZCXF")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_first_of(TextSTD(STR("ZCXF"))); - size_t position2 = text.find_first_of(ViewSTD(STR("ZCXF"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("WXYZ"))); - position2 = text.find_first_of(ViewSTD(STR("WXYZ"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 3); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 3); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_of(TextSTD(STR("ZCXF")), 100); - position2 = text.find_first_of(ViewSTD(STR("ZCXF")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_of_pointer_position) { @@ -5214,77 +4641,40 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewETL(STR("ZCXE"))); + size_t position2 = text.find_last_of(View(STR("ZCXE"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewETL(STR("WXYZ")), 3); + position2 = text.find_last_of(View(STR("WXYZ")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 5); + position2 = text.find_last_of(View(STR("ZCXE")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), text.size()); + position2 = text.find_last_of(View(STR("ZCXE")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewETL(STR("ZCXE")), 100); + position2 = text.find_last_of(View(STR("ZCXE")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - TextBuffer buffer{0}; - Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_last_of(TextSTD(STR("ZCXE"))); - size_t position2 = text.find_last_of(ViewSTD(STR("ZCXE"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("WXYZ")), 3); - position2 = text.find_last_of(ViewSTD(STR("WXYZ")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 5); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), compare_text.size()); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_of(TextSTD(STR("ZCXE")), 100); - position2 = text.find_last_of(ViewSTD(STR("ZCXE")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_of_pointer_position) { @@ -5445,76 +4835,39 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_etl_view_position) - { - TextSTD compare_text(STR("ABCDEF")); - TextBuffer buffer{0}; - Text text(STR("ABCDEF"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewETL(STR("ZAXB")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_first_not_of_std_view_position) + TEST_FIXTURE(SetupFixture, test_find_first_not_of_view_position) { TextSTD compare_text(STR("ABCDEF")); TextBuffer buffer{0}; Text text(STR("ABCDEF"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - size_t position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + size_t position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB"))); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB"))); + position2 = text.find_first_not_of(View(STR("ZAXB"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 3); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 3); + position2 = text.find_first_not_of(View(STR("ZAXB")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), compare_text.size()); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), text.size()); + position2 = text.find_first_not_of(View(STR("ZAXB")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_first_not_of(TextSTD(STR("ZAXB")), 100); - position2 = text.find_first_not_of(ViewSTD(STR("ZAXB")), 100); + position2 = text.find_first_not_of(View(STR("ZAXB")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#endif //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_first_not_of_pointer_position) @@ -5671,77 +5024,40 @@ namespace } //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_etl_view_position) + TEST_FIXTURE(SetupFixture, test_find_last_not_of_view_position) { TextSTD compare_text(STR("ABCDEFABCDE")); TextBuffer buffer{0}; Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewETL(STR("ZEXD"))); + size_t position2 = text.find_last_not_of(View(STR("ZEXD"))); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 3); + position2 = text.find_last_not_of(View(STR("ZEXD")), 3); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 5); + position2 = text.find_last_not_of(View(STR("ZEXD")), 5); CHECK_EQUAL(position1, position2); position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), text.size()); + position2 = text.find_last_not_of(View(STR("ZEXD")), text.size()); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_array_bounds_push.h" position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewETL(STR("ZEXD")), 100); + position2 = text.find_last_not_of(View(STR("ZEXD")), 100); CHECK_EQUAL(position1, position2); #include "etl/private/diagnostic_pop.h" } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_find_last_not_of_std_view_position) - { - TextSTD compare_text(STR("ABCDEFABCDE")); - TextBuffer buffer{0}; - Text text(STR("ABCDEFABCDE"), buffer.data(), buffer.size()); - - size_t position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD"))); - size_t position2 = text.find_last_not_of(ViewSTD(STR("ZEXD"))); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 3); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 3); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 5); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 5); - - CHECK_EQUAL(position1, position2); - - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), compare_text.size()); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), text.size()); - - CHECK_EQUAL(position1, position2); - -#include "etl/private/diagnostic_array_bounds_push.h" - position1 = compare_text.find_last_not_of(TextSTD(STR("ZEXD")), 100); - position2 = text.find_last_not_of(ViewSTD(STR("ZEXD")), 100); - - CHECK_EQUAL(position1, position2); -#include "etl/private/diagnostic_pop.h" - } -#endif - //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_last_not_of_pointer_position) { From 6ce4fa40bbbed2ad97f68395272bc911f67a9bbd Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 23 Nov 2024 12:33:36 +0000 Subject: [PATCH 30/55] Added starts_with and ends_with to basic_string --- include/etl/basic_string.h | 93 ++++++++++++++++++- test/test_string_char.cpp | 84 +++++++++++++++++ test/test_string_char_external_buffer.cpp | 98 ++++++++++++++++++++ test/test_string_u16.cpp | 84 +++++++++++++++++ test/test_string_u16_external_buffer.cpp | 98 ++++++++++++++++++++ test/test_string_u32.cpp | 84 +++++++++++++++++ test/test_string_u32_external_buffer.cpp | 98 ++++++++++++++++++++ test/test_string_u8.cpp | 84 +++++++++++++++++ test/test_string_u8_external_buffer.cpp | 98 ++++++++++++++++++++ test/test_string_wchar_t.cpp | 84 +++++++++++++++++ test/test_string_wchar_t_external_buffer.cpp | 98 ++++++++++++++++++++ 11 files changed, 999 insertions(+), 4 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index d228166f8..5cc37f107 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -1497,7 +1497,7 @@ namespace etl } //********************************************************************* - /// Checks that the string is within the string + /// Checks that the string is within this string //********************************************************************* bool contains(const etl::ibasic_string& str) const { @@ -1505,7 +1505,7 @@ namespace etl } //********************************************************************* - /// Checks that the view is within the string + /// Checks that the view is within this string //********************************************************************* template bool contains(const etl::basic_string_view& view) const @@ -1514,7 +1514,7 @@ namespace etl } //********************************************************************* - /// Checks that text is within the string + /// Checks that text is within this string //********************************************************************* bool contains(const_pointer s) const { @@ -1522,13 +1522,98 @@ namespace etl } //********************************************************************* - /// Checks that character is within the string + /// Checks that character is within this string //********************************************************************* bool contains(value_type c) const { return find(c) != npos; } + //********************************************************************* + /// Checks that the string is the start of this string + //********************************************************************* + bool starts_with(const ibasic_string& str) const + { + return compare(0, str.size(), str) == 0; + } + + //********************************************************************* + /// Checks that the view is the start of this string + //********************************************************************* + template + bool starts_with(const basic_string_view& view) const + { + return compare(0, view.size(), view) == 0; + } + + //********************************************************************* + /// Checks that the string is the start of this string + //********************************************************************* + bool starts_with(const_pointer s) const + { + size_t len = etl::strlen(s); + + return compare(0, len, s, len) == 0; + } + + //********************************************************************* + /// Checks that the character is the start of this string + //********************************************************************* + bool starts_with(value_type c) const + { + return !empty() && (front() == c); + } + + //********************************************************************* + /// Checks that the string is the end of this string + //********************************************************************* + bool ends_with(const ibasic_string& str) const + { + if (str.size() > size()) + { + return false; + } + + return compare(size() - str.size(), str.size(), str) == 0; + } + + //********************************************************************* + /// Checks that the view is the end of this string + //********************************************************************* + template + bool ends_with(const basic_string_view& view) const + { + if (view.size() > size()) + { + return false; + } + + return compare(size() - view.size(), view.size(), view) == 0; + } + + //********************************************************************* + /// Checks that the string is the end of this string + //********************************************************************* + bool ends_with(const_pointer s) const + { + size_t len = etl::strlen(s); + + if (len > size()) + { + return false; + } + + return compare(size() - len, len, s, len) == 0; + } + + //********************************************************************* + /// Checks that the character is the end of this string + //********************************************************************* + bool ends_with(value_type c) const + { + return !empty() && (back() == c); + } + //********************************************************************* /// Replace 'length' characters from 'position' with 'str'. ///\param position The position to start from. diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 4da5716bd..5c1e0c999 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -3644,6 +3644,90 @@ namespace CHECK_FALSE(haystack.contains(STR('p'))); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text start(STR("A haystack")); + Text not_start(STR("a needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text end(STR("else")); + Text not_end(STR("needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index b2998e633..4ef708512 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -3947,6 +3947,104 @@ namespace CHECK_FALSE(haystack.contains(STR('p'))); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index a09f9a59c..f7565b01e 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -3658,6 +3658,90 @@ namespace CHECK_FALSE(haystack.contains(STR('p'))); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text start(STR("A haystack")); + Text not_start(STR("a needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text end(STR("else")); + Text not_end(STR("needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index 96fd23d5e..b15a47728 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -3961,6 +3961,104 @@ namespace CHECK_FALSE(haystack.contains(STR('p'))); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 2b607b33b..b27fcaffd 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -3658,6 +3658,90 @@ namespace CHECK_FALSE(haystack.contains(STR('p'))); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text start(STR("A haystack")); + Text not_start(STR("a needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text end(STR("else")); + Text not_end(STR("needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index bdbaf7b22..118586859 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -3961,6 +3961,104 @@ namespace CHECK_FALSE(haystack.contains(STR('p'))); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { diff --git a/test/test_string_u8.cpp b/test/test_string_u8.cpp index 5ce38042a..d8d9c6a35 100644 --- a/test/test_string_u8.cpp +++ b/test/test_string_u8.cpp @@ -3661,6 +3661,90 @@ namespace CHECK_FALSE(haystack.contains(STR('p'))); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text start(STR("A haystack")); + Text not_start(STR("a needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text end(STR("else")); + Text not_end(STR("needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { diff --git a/test/test_string_u8_external_buffer.cpp b/test/test_string_u8_external_buffer.cpp index 085f77380..e76130083 100644 --- a/test/test_string_u8_external_buffer.cpp +++ b/test/test_string_u8_external_buffer.cpp @@ -3933,6 +3933,104 @@ namespace CHECK_FALSE(haystack.contains(STR('p'))); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_find_char_pointer_n) { diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 1a8ed43bd..8b3ae997e 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -3659,6 +3659,90 @@ namespace CHECK_FALSE(haystack.contains(STR('p'))); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text start(STR("A haystack")); + Text not_start(STR("a needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + Text end(STR("else")); + Text not_end(STR("needle")); + Text excess(STR("Really gigantic text that's really really big")); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextL haystack(STR("A haystack with a needle and nothing else")); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index 5d277936c..7ce900d04 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -3964,6 +3964,104 @@ namespace CHECK_FALSE(haystack.contains(STR('p'))); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text start(STR("A haystack"), buffer2.data(), buffer2.size()); + Text not_start(STR("a needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.starts_with(start)); + CHECK_FALSE(haystack.starts_with(not_start)); + CHECK_FALSE(haystack.starts_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(View(STR("A haystack")))); + CHECK_FALSE(haystack.starts_with(View(STR("a needle")))); + CHECK_FALSE(haystack.starts_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(STR("A haystack"))); + CHECK_FALSE(haystack.starts_with(STR("a needle"))); + CHECK_FALSE(haystack.starts_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_starts_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.starts_with(haystack[0])); + CHECK_FALSE(haystack.starts_with(haystack[1])); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_string) + { + TextBufferL buffer1{0}; + TextBuffer buffer2{0}; + TextBuffer buffer3{0}; + TextBuffer buffer4{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + Text end(STR("else"), buffer2.data(), buffer2.size()); + Text not_end(STR("needle"), buffer3.data(), buffer3.size()); + Text excess(STR("Really gigantic text that's really really big"), buffer4.data(), buffer4.size()); + + CHECK_TRUE(haystack.ends_with(end)); + CHECK_FALSE(haystack.ends_with(not_end)); + CHECK_FALSE(haystack.ends_with(excess)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_view) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(View(STR("else")))); + CHECK_FALSE(haystack.ends_with(View(STR("needle")))); + CHECK_FALSE(haystack.ends_with(View(STR("Really gigantic text that's really really big")))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_pointer) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(STR("else"))); + CHECK_FALSE(haystack.ends_with(STR("needle"))); + CHECK_FALSE(haystack.ends_with(STR("Really gigantic text that's really really big"))); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_ends_with_char) + { + TextBufferL buffer1{0}; + Text haystack(STR("A haystack with a needle and nothing else"), buffer1.data(), buffer1.size()); + + CHECK_TRUE(haystack.ends_with(haystack[haystack.size() - 1])); + CHECK_FALSE(haystack.ends_with(haystack[haystack.size() - 2])); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_rfind_string) { From bdb8956e8d7a4aae6aa118e89e59de8750b21ed0 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 24 Nov 2024 08:53:51 +0000 Subject: [PATCH 31/55] Made construction from std::basic_string_view explicit --- include/etl/string_view.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 3558d2ef9..48c6c75d4 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -172,7 +172,7 @@ namespace etl /// Constructor from std::basic string_view //************************************************************************* template - ETL_CONSTEXPR basic_string_view(const std::basic_string_view& other) ETL_NOEXCEPT + explicit ETL_CONSTEXPR basic_string_view(const std::basic_string_view& other) ETL_NOEXCEPT : mbegin(other.data()) , mend(other.data() + other.size()) { From 7552aa06db1f9b2477700e176a61302bd0167797 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 24 Nov 2024 08:55:22 +0000 Subject: [PATCH 32/55] Removed remaining std::u8string_view functions --- include/etl/u8string.h | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/include/etl/u8string.h b/include/etl/u8string.h index 009f541ed..7510c4f67 100644 --- a/include/etl/u8string.h +++ b/include/etl/u8string.h @@ -186,18 +186,6 @@ namespace etl this->assign(view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP20 - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit u8string(const std::u8string_view& view) - : iu8string(reinterpret_cast(&buffer), MAX_SIZE) - { - this->assign(view.begin(), view.end()); - } -#endif - //************************************************************************* /// Returns a sub-u8string. ///\param position The position of the first character. Default = 0. @@ -266,18 +254,6 @@ namespace etl return *this; } -#if ETL_USING_STL && ETL_USING_CPP20 - //************************************************************************* - /// Assignment operator. - //************************************************************************* - u8string& operator = (const std::u8string_view& view) - { - this->assign(view); - - return *this; - } -#endif - //************************************************************************* /// Fix the internal pointers after a low level memory copy. //************************************************************************* @@ -430,18 +406,6 @@ namespace etl this->assign(view.begin(), view.end()); } -#if ETL_USING_STL && ETL_USING_CPP20 - //************************************************************************* - /// From string_view. - ///\param view The string_view. - //************************************************************************* - explicit u8string_ext(const std::u8string_view& view, value_type* buffer, size_type buffer_size) - : iu8string(buffer, buffer_size - 1U) - { - this->assign(view.begin(), view.end()); - } -#endif - //************************************************************************* /// Assignment operator. //************************************************************************* From a6ef8ec08d9c20f25e5829589757ece8bc0bb77b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 24 Nov 2024 09:01:33 +0000 Subject: [PATCH 33/55] Added member function resize_and_overwrite --- include/etl/basic_string.h | 24 ++++++-- test/test_string_char.cpp | 64 ++++++++++++++++++- test/test_string_char_external_buffer.cpp | 65 +++++++++++++++++++- test/test_string_u16.cpp | 58 +++++++++++++++++ test/test_string_u16_external_buffer.cpp | 39 +++++++++++- test/test_string_u32.cpp | 58 +++++++++++++++++ test/test_string_u32_external_buffer.cpp | 39 +++++++++++- test/test_string_u8.cpp | 58 +++++++++++++++++ test/test_string_u8_external_buffer.cpp | 65 +++++++++++++++++++- test/test_string_wchar_t.cpp | 58 +++++++++++++++++ test/test_string_wchar_t_external_buffer.cpp | 39 +++++++++++- 11 files changed, 550 insertions(+), 17 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 5cc37f107..9146d5232 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -496,6 +496,22 @@ namespace etl cleanup(); } + //********************************************************************* + /// Resizes the string and overwrites to data using the operation. + //********************************************************************* + template + void resize_and_overwrite(size_type new_size, TOperation operation) + { + if (new_size > CAPACITY) + { + ETL_ASSERT_FAIL(ETL_ERROR(string_out_of_bounds)); + } + + current_size = operation(p_buffer, new_size); + p_buffer[current_size] = '\0'; + cleanup(); + } + //********************************************************************* /// Resizes the string, but doesn't initialise the free space /// except for a terminator null. @@ -1532,7 +1548,7 @@ namespace etl //********************************************************************* /// Checks that the string is the start of this string //********************************************************************* - bool starts_with(const ibasic_string& str) const + bool starts_with(const etl::ibasic_string& str) const { return compare(0, str.size(), str) == 0; } @@ -1541,7 +1557,7 @@ namespace etl /// Checks that the view is the start of this string //********************************************************************* template - bool starts_with(const basic_string_view& view) const + bool starts_with(const etl::basic_string_view& view) const { return compare(0, view.size(), view) == 0; } @@ -1567,7 +1583,7 @@ namespace etl //********************************************************************* /// Checks that the string is the end of this string //********************************************************************* - bool ends_with(const ibasic_string& str) const + bool ends_with(const etl::ibasic_string& str) const { if (str.size() > size()) { @@ -1581,7 +1597,7 @@ namespace etl /// Checks that the view is the end of this string //********************************************************************* template - bool ends_with(const basic_string_view& view) const + bool ends_with(const etl::basic_string_view& view) const { if (view.size() > size()) { diff --git a/test/test_string_char.cpp b/test/test_string_char.cpp index 5c1e0c999..7c118ff88 100644 --- a/test/test_string_char.cpp +++ b/test/test_string_char.cpp @@ -725,7 +725,7 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); } //************************************************************************* @@ -738,7 +738,7 @@ namespace text.uninitialized_resize(NEW_SIZE); - CHECK_EQUAL(text.size(), SIZE); + CHECK_EQUAL(SIZE, text.size()); } //************************************************************************* @@ -766,7 +766,65 @@ namespace bool is_equal = Equal(compare_text, text); CHECK(is_equal); - CHECK_EQUAL(text.size(), NEW_SIZE); + CHECK_EQUAL(NEW_SIZE, text.size()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + Text text(initial_text.c_str(), initial_text.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); } //************************************************************************* diff --git a/test/test_string_char_external_buffer.cpp b/test/test_string_char_external_buffer.cpp index 4ef708512..3eb26da5d 100644 --- a/test/test_string_char_external_buffer.cpp +++ b/test/test_string_char_external_buffer.cpp @@ -919,6 +919,67 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_full) { @@ -1737,7 +1798,7 @@ namespace for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1762,7 +1823,7 @@ namespace for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); View view(insert_text.data(), insert_text.size()); diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index f7565b01e..37465e2a4 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -783,6 +783,64 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + Text text(initial_text.c_str(), initial_text.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_fill) { diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index b15a47728..c94fdad04 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -933,6 +933,41 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_full) { @@ -1751,7 +1786,7 @@ namespace for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1776,7 +1811,7 @@ namespace for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); View view(insert_text.data(), insert_text.size()); diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index b27fcaffd..b72ef01ee 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -783,6 +783,64 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + Text text(initial_text.c_str(), initial_text.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_fill) { diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 118586859..f5e255107 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -933,6 +933,41 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_full) { @@ -1751,7 +1786,7 @@ namespace for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1776,7 +1811,7 @@ namespace for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); View view(insert_text.data(), insert_text.size()); diff --git a/test/test_string_u8.cpp b/test/test_string_u8.cpp index d8d9c6a35..e3d5c1faf 100644 --- a/test/test_string_u8.cpp +++ b/test/test_string_u8.cpp @@ -786,6 +786,64 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + Text text(initial_text.c_str(), initial_text.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_fill) { diff --git a/test/test_string_u8_external_buffer.cpp b/test/test_string_u8_external_buffer.cpp index e76130083..5f64fb37b 100644 --- a/test/test_string_u8_external_buffer.cpp +++ b/test/test_string_u8_external_buffer.cpp @@ -936,6 +936,67 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_full) { @@ -1754,7 +1815,7 @@ namespace for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1779,7 +1840,7 @@ namespace for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); View view(insert_text.data(), insert_text.size()); diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 8b3ae997e..81b2d8bbd 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -784,6 +784,64 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 8UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H234567")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + Text text(initial_text.c_str(), INITIAL_SIZE); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) noexcept + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + Text text(initial_text.c_str(), initial_text.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_fill) { diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index 7ce900d04..886c7b70c 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -936,6 +936,41 @@ namespace CHECK_EQUAL(text.size(), NEW_SIZE); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_down) + { + const size_t INITIAL_SIZE = 5UL; + const size_t NEW_SIZE = 3UL; + + TextBuffer buffer{0}; + Text text(initial_text.c_str(), INITIAL_SIZE, buffer.data(), buffer.size()); + + // Overwrite from index 1 to one less than the new size and set to that size. + text.resize_and_overwrite(NEW_SIZE, [](Text::pointer p, size_t n) + { + size_t i = 1; + while (i < (n - 1)) + { + p[i] = '1' + Text::value_type(i); + ++i; + } + + return i; + }); + + CHECK_EQUAL(NEW_SIZE - 1, text.size()); + CHECK_TRUE(Equal(TextSTD(STR("H2")), text)); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_resize_and_overwrite_up_excess) + { + TextBuffer buffer{0}; + Text text(initial_text.c_str(), initial_text.size(), buffer.data(), buffer.size()); + + CHECK_THROW(text.resize_and_overwrite(text.capacity() + 1, [](Text::pointer /*p*/, size_t n) { return n; }), etl::string_out_of_bounds); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_empty_full) { @@ -1754,7 +1789,7 @@ namespace for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); @@ -1779,7 +1814,7 @@ namespace for (size_t offset = 0UL; offset <= short_text.size(); ++offset) { TextSTD compare_text(short_text.cbegin(), short_text.cend()); - TextBuffer buffer; + TextBuffer buffer{0}; buffer.fill(0); Text text(short_text.begin(), short_text.end(), buffer.data(), buffer.size()); View view(insert_text.data(), insert_text.size()); From 3deaaeb18058ec95671001904efb35a51f025ba5 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sun, 24 Nov 2024 15:01:38 +0000 Subject: [PATCH 34/55] Added contains member function to string_view --- include/etl/string_view.h | 25 +++++++++++++++++++++++++ test/test_string_view.cpp | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 48c6c75d4..af2619244 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -763,6 +763,31 @@ namespace etl return find_last_not_of(etl::basic_string_view(text), position); } + //********************************************************************* + /// Checks that the view is within this string + //********************************************************************* + template + bool contains(const etl::basic_string_view& view) const + { + return find(view) != npos; + } + + //********************************************************************* + /// Checks that text is within this string + //********************************************************************* + bool contains(const_pointer s) const + { + return find(s) != npos; + } + + //********************************************************************* + /// Checks that character is within this string + //********************************************************************* + bool contains(value_type c) const + { + return find(c) != npos; + } + //************************************************************************* /// Equality for string_view. //************************************************************************* diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index 27713f899..bc9404e61 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -822,6 +822,39 @@ namespace CHECK(!view.ends_with("Hello Worldxxxxxx")); } + //************************************************************************* + TEST(test_contains) + { + const char* s1 = "Hello"; + const char* s2 = "llo Wor"; + const char* s3 = "World"; + const char* s4 = "Xorld"; + const char* s5 = "Hello Worldxxxxxx"; + + View view(text.c_str()); + View v1(s1); + View v2(s2); + View v3(s3); + View v4(s4); + View v5(s5); + + CHECK_TRUE(view.contains(v1)); + CHECK_TRUE(view.contains(v2)); + CHECK_TRUE(view.contains(v3)); + CHECK_FALSE(view.contains(v4)); + CHECK_FALSE(view.contains(v5)); + + CHECK_TRUE(view.contains('H')); + CHECK_TRUE(view.contains('l')); + CHECK_FALSE(view.contains('X')); + + CHECK_TRUE(view.contains(s1)); + CHECK_TRUE(view.contains(s2)); + CHECK_TRUE(view.contains(s3)); + CHECK_FALSE(view.contains(s4)); + CHECK_FALSE(view.contains(s5)); + } + //************************************************************************* TEST(test_find) { From d40cbf12cc7d64cbad6a60b90f1449d9389c5d30 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 27 Nov 2024 16:35:09 +0000 Subject: [PATCH 35/55] Changed case for script header --- test/run-tests.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/run-tests.sh b/test/run-tests.sh index cb5a9d12b..4b45ba3b7 100644 --- a/test/run-tests.sh +++ b/test/run-tests.sh @@ -154,9 +154,9 @@ fi # Set the sanitizer enable. Default OFF #****************************************************************************** if [ "$4" = "S" ]; then - sanitize="ON" + sanitize="On" else - sanitize="OFF" + sanitize="Off" fi #****************************************************************************** From 58ff15947dd80cf1bacdbc7926d94288eaad4099 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 27 Nov 2024 16:36:00 +0000 Subject: [PATCH 36/55] Fixed possible null dereference for etl::multi_span operator -> --- include/etl/multi_span.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/etl/multi_span.h b/include/etl/multi_span.h index 8e974ee31..4d93df42e 100644 --- a/include/etl/multi_span.h +++ b/include/etl/multi_span.h @@ -134,7 +134,7 @@ namespace etl //************************************************************************* pointer operator ->() { - return &operator*(); + return p_value; } //************************************************************************* @@ -142,7 +142,7 @@ namespace etl //************************************************************************* const_pointer operator ->() const { - return &operator*(); + return p_value; } //************************************************************************* From 7ae2c7626ec6ad807cc26da5e5b24b3ca2a8d9f6 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Wed, 27 Nov 2024 16:36:35 +0000 Subject: [PATCH 37/55] Fixed shadowing warnings --- include/etl/basic_string.h | 88 +++++++++++++++++++------------------- include/etl/string_view.h | 7 ++- 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 9146d5232..f590c9480 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -717,8 +717,8 @@ namespace etl //********************************************************************* /// Assigns values to the string from a view. //********************************************************************* - template - void assign(const etl::basic_string_view& view) + template + void assign(const etl::basic_string_view& view) { assign(view.begin(), view.end()); } @@ -877,8 +877,8 @@ namespace etl /// Appends to the string. ///\param view An etl::string_view. //********************************************************************* - template - ibasic_string& append(const etl::basic_string_view& view) + template + ibasic_string& append(const etl::basic_string_view& view) { insert(end(), view.begin(), view.end()); return *this; @@ -1120,8 +1120,8 @@ namespace etl ///\param position The position to insert before. ///\param view The view element to add. //********************************************************************* - template - iterator insert(const_iterator position, const etl::basic_string_view& view) + template + iterator insert(const_iterator position, const etl::basic_string_view& view) { return insert(position, view.begin(), view.end()); } @@ -1156,8 +1156,8 @@ namespace etl ///\param position The position to insert before. ///\param view The view to insert. //********************************************************************* - template - etl::ibasic_string& insert(size_type position, const etl::basic_string_view& view) + template + etl::ibasic_string& insert(size_type position, const etl::basic_string_view& view) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1206,8 +1206,8 @@ namespace etl ///\param subposition The subposition to start from. ///\param sublength The number of characters to insert. //********************************************************************* - template - etl::ibasic_string& insert(size_type position, const etl::basic_string_view& view, size_type subposition, size_type sublength) + template + etl::ibasic_string& insert(size_type position, const etl::basic_string_view& view, size_type subposition, size_type sublength) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); @@ -1387,8 +1387,8 @@ namespace etl ///\param view The content to find ///\param pos The position to start searching from. //********************************************************************* - template - size_type find(const etl::basic_string_view& view, size_type pos = 0) const + template + size_type find(const etl::basic_string_view& view, size_type pos = 0) const { return find_impl(view.begin(), view.end(), view.size(), pos); } @@ -1452,8 +1452,8 @@ namespace etl ///\param view The content to find ///\param pos The position to start searching from. //********************************************************************* - template - size_type rfind(const etl::basic_string_view& view, size_type pos = 0) const + template + size_type rfind(const etl::basic_string_view& view, size_type pos = 0) const { return rfind_impl(view.rbegin(), view.rend(), view.size(), pos); } @@ -1523,8 +1523,8 @@ namespace etl //********************************************************************* /// Checks that the view is within this string //********************************************************************* - template - bool contains(const etl::basic_string_view& view) const + template + bool contains(const etl::basic_string_view& view) const { return find(view) != npos; } @@ -1556,8 +1556,8 @@ namespace etl //********************************************************************* /// Checks that the view is the start of this string //********************************************************************* - template - bool starts_with(const etl::basic_string_view& view) const + template + bool starts_with(const etl::basic_string_view& view) const { return compare(0, view.size(), view) == 0; } @@ -1596,8 +1596,8 @@ namespace etl //********************************************************************* /// Checks that the view is the end of this string //********************************************************************* - template - bool ends_with(const etl::basic_string_view& view) const + template + bool ends_with(const etl::basic_string_view& view) const { if (view.size() > size()) { @@ -1658,8 +1658,8 @@ namespace etl ///\param length The number of characters to replace. ///\param view The string to replace it with. //********************************************************************* - template - ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view) + template + ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1713,8 +1713,8 @@ namespace etl ///\param last The one after the position to end at. ///\param view The string view to replace it with. //********************************************************************* - template - ibasic_string& replace(const_iterator first, const_iterator last, const etl::basic_string_view& view) + template + ibasic_string& replace(const_iterator first, const_iterator last, const etl::basic_string_view& view) { // Quick hack, as iterators are pointers. iterator first_ = to_iterator(first); @@ -1764,8 +1764,8 @@ namespace etl //********************************************************************* /// Replace characters from 'position' of 'length' with 'view' from 'subposition' of 'sublength'. //********************************************************************* - template - ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) + template + ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); @@ -1927,8 +1927,8 @@ namespace etl //************************************************************************* /// Compare with etl::basic_string_view. //************************************************************************* - template - int compare(const etl::basic_string_view& view) const + template + int compare(const etl::basic_string_view& view) const { return compare(p_buffer, p_buffer + size(), @@ -1955,8 +1955,8 @@ namespace etl //************************************************************************* /// Compare position / length with etl::basic_string_view. //************************************************************************* - template - int compare(size_type position, size_type length_, const etl::basic_string_view& view) const + template + int compare(size_type position, size_type length_, const etl::basic_string_view& view) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -1985,8 +1985,8 @@ namespace etl //************************************************************************* /// Compare position / length with etl::basic_string_view. / subposition / sublength. //************************************************************************* - template - int compare(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) const + template + int compare(size_type position, size_type length_, const etl::basic_string_view& view, size_type subposition, size_type sublength) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds)); @@ -2059,8 +2059,8 @@ namespace etl ///\param view The content to find ///\param pos The position to start searching from. //********************************************************************* - template - size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const + template + size_type find_first_of(const etl::basic_string_view& view, size_type position = 0) const { return find_first_of(view.data(), position, view.size()); } @@ -2136,8 +2136,8 @@ namespace etl ///\param view The content to find ///\param pos The position to start searching from. //********************************************************************* - template - size_type find_last_of(const etl::basic_string_view& view, size_type position = npos) const + template + size_type find_last_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_of(view.data(), position, view.size()); } @@ -2231,8 +2231,8 @@ namespace etl ///\param view The content to find ///\param pos The position to start searching from. //********************************************************************* - template - size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const + template + size_type find_first_not_of(const etl::basic_string_view& view, size_type position = 0) const { return find_first_not_of(view.data(), position, view.size()); } @@ -2315,8 +2315,8 @@ namespace etl ///\param view The content to find ///\param pos The position to start searching from. //********************************************************************* - template - size_type find_last_not_of(const etl::basic_string_view& view, size_type position = npos) const + template + size_type find_last_not_of(const etl::basic_string_view& view, size_type position = npos) const { return find_last_not_of(view.data(), position, view.size()); } @@ -2416,8 +2416,8 @@ namespace etl //************************************************************************* /// Assignment operator. //************************************************************************* - template - ibasic_string& operator = (const etl::basic_string_view& view) + template + ibasic_string& operator = (const etl::basic_string_view& view) { assign(view); @@ -2437,8 +2437,8 @@ namespace etl //************************************************************************* /// += operator. //************************************************************************* - template - ibasic_string& operator += (const etl::basic_string_view& rhs) + template + ibasic_string& operator += (const etl::basic_string_view& rhs) { append(rhs); diff --git a/include/etl/string_view.h b/include/etl/string_view.h index af2619244..7b60d8397 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -100,9 +100,9 @@ namespace etl { public: - typedef T value_type; - typedef TTraits traits_type; - typedef size_t size_type; + typedef T value_type; + typedef TTraits traits_type; + typedef size_t size_type; typedef const T& const_reference; typedef const T* const_pointer; typedef const T* const_iterator; @@ -766,7 +766,6 @@ namespace etl //********************************************************************* /// Checks that the view is within this string //********************************************************************* - template bool contains(const etl::basic_string_view& view) const { return find(view) != npos; From 9fdc03ae02e0861b37be3990802fd3fc1d1ea3be Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 30 Nov 2024 10:18:10 +0000 Subject: [PATCH 38/55] removed redundant parameters --- test/test_message_router.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/test_message_router.cpp b/test/test_message_router.cpp index 938a0854f..43bf11749 100644 --- a/test/test_message_router.cpp +++ b/test/test_message_router.cpp @@ -302,15 +302,15 @@ namespace } } - void on_receive(const Message1& msg) + void on_receive(const Message1&) { } - void on_receive(const Message2& msg) + void on_receive(const Message2&) { } - void on_receive(const Message3& msg) + void on_receive(const Message3&) { } From 9ed9b90f1df265d45e9d276024082e96349b0828 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 30 Nov 2024 11:19:43 +0000 Subject: [PATCH 39/55] Fixed merge issues --- include/etl/string_view.h | 12 ------ test/test_string_view.cpp | 80 --------------------------------------- 2 files changed, 92 deletions(-) diff --git a/include/etl/string_view.h b/include/etl/string_view.h index 7b60d8397..c3c7e80eb 100644 --- a/include/etl/string_view.h +++ b/include/etl/string_view.h @@ -167,18 +167,6 @@ namespace etl { } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - /// Constructor from std::basic string_view - //************************************************************************* - template - explicit ETL_CONSTEXPR basic_string_view(const std::basic_string_view& other) ETL_NOEXCEPT - : mbegin(other.data()) - , mend(other.data() + other.size()) - { - } -#endif - //************************************************************************* /// Returns a const reference to the first element. //************************************************************************* diff --git a/test/test_string_view.cpp b/test/test_string_view.cpp index bc9404e61..afa1e6d33 100644 --- a/test/test_string_view.cpp +++ b/test/test_string_view.cpp @@ -169,86 +169,6 @@ namespace CHECK(isEqual); } -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST(test_constructor_from_std_string_view) - { - std::string_view stdview(text.data(), text.size()); - - View view(stdview); - - CHECK(stdview.size() == view.size()); - CHECK(stdview.size() == view.max_size()); - - bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); - CHECK(isEqual); - } -#endif - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST(test_constructor_from_std_wstring_view) - { - std::wstring_view stdview(wtext.data(), wtext.size()); - - WView view(stdview); - - CHECK(stdview.size() == view.size()); - CHECK(stdview.size() == view.max_size()); - - bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); - CHECK(isEqual); - } -#endif - -#if ETL_USING_STL && ETL_USING_CPP20 - //************************************************************************* - TEST(test_constructor_from_std_u8string_view) - { - std::u8string_view stdview(u8text.begin(), u8text.end()); - - U8View view(stdview); - - CHECK(stdview.size() == view.size()); - CHECK(stdview.size() == view.max_size()); - - bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); - CHECK(isEqual); - } -#endif - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST(test_constructor_from_std_u16string_view) - { - std::u16string_view stdview(u16text.data(), u16text.size()); - - U16View view(stdview); - - CHECK(stdview.size() == view.size()); - CHECK(stdview.size() == view.max_size()); - - bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); - CHECK(isEqual); - } -#endif - -#if ETL_USING_STL && ETL_USING_CPP17 - //************************************************************************* - TEST(test_constructor_from_std_u32string_view) - { - std::u32string_view stdview(u32text.data(), u32text.size()); - - U32View view(stdview); - - CHECK(stdview.size() == view.size()); - CHECK(stdview.size() == view.max_size()); - - bool isEqual = std::equal(view.begin(), view.end(), stdview.begin()); - CHECK(isEqual); - } -#endif - //************************************************************************* TEST(test_constructor_pointer_size) { From cd1805b1d2d9c06d46e12df3c5650f8e424562c0 Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Mon, 2 Dec 2024 13:10:26 +0100 Subject: [PATCH 40/55] Added return to etl::optional emplace, fixed typo (#982) --- include/etl/optional.h | 12 ++++++++---- test/test_optional.cpp | 10 ++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/etl/optional.h b/include/etl/optional.h index 002d010a9..f70b2689c 100644 --- a/include/etl/optional.h +++ b/include/etl/optional.h @@ -484,14 +484,16 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR20_STL - void emplace(TArgs&& ... args) + T& emplace(TArgs&& ... args) { storage.construct(etl::forward(args)...); + + return storage.u.value; } #else //************************************************************************* /// Emplaces a value. - /// 1 parameter. + /// 0 parameters. //************************************************************************* T& emplace() { @@ -1048,14 +1050,16 @@ namespace etl //************************************************************************* template ETL_CONSTEXPR14 - void emplace(TArgs&& ... args) + T& emplace(TArgs&& ... args) { storage.construct(etl::forward(args)...); + + return storage.value; } #else //************************************************************************* /// Emplaces a value. - /// 1 parameter. + /// 0 parameters. //************************************************************************* T& emplace() { diff --git a/test/test_optional.cpp b/test/test_optional.cpp index 61e68672b..87ee24c72 100644 --- a/test/test_optional.cpp +++ b/test/test_optional.cpp @@ -157,6 +157,16 @@ namespace CHECK_EQUAL(0, int(result.value())); } + //************************************************************************* + TEST(test_emplace_return) + { + etl::optional data; + + DataM* datam = &data.emplace(1U); + CHECK_EQUAL(datam, &data.value()); + CHECK(datam != nullptr); + } + //************************************************************************* TEST(test_moveable) { From 86083e18e743c1a8fc56065c50d59a872f1555a2 Mon Sep 17 00:00:00 2001 From: snadampal <87143774+snadampal@users.noreply.github.com> Date: Sat, 30 Nov 2024 15:16:46 -0600 Subject: [PATCH 41/55] fix build and test failures on arm64 linux platform (#978) There are few build and test failures on arm64 platform with "narrowing conversion" errors. This is due to the char datatype implementation differences between different platforms and gcc versions. This commit replaces the char datatype with the explicit datatype that works across all the platforms. --- test/test_bit_stream.cpp | 8 ++++---- test/test_bit_stream_reader_big_endian.cpp | 8 ++++---- test/test_bresenham_line.cpp | 2 +- test/test_correlation.cpp | 18 +++++++++--------- test/test_covariance.cpp | 18 +++++++++--------- test/test_rms.cpp | 4 ++-- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/test/test_bit_stream.cpp b/test/test_bit_stream.cpp index c0cbd2512..7ed5979dd 100644 --- a/test/test_bit_stream.cpp +++ b/test/test_bit_stream.cpp @@ -930,8 +930,8 @@ namespace //************************************************************************* TEST(put_get_multiple_variable_size) { - char c1 = 26; // 6 bits - char c2 = -10; // 7 bits + int8_t c1 = 26; // 6 bits + int8_t c2 = -10; // 7 bits unsigned short s1 = 6742; // 13 bits unsigned short s2 = 1878; // 11 bits int32_t i1 = 2448037L; // 23 bits @@ -983,8 +983,8 @@ namespace bit_stream.restart(); - char rc1 = 0; - char rc2 = 0; + int8_t rc1 = 0; + int8_t rc2 = 0; unsigned short rs1 = 0; unsigned short rs2 = 0; int32_t ri1 = 0; diff --git a/test/test_bit_stream_reader_big_endian.cpp b/test/test_bit_stream_reader_big_endian.cpp index 4cdf3d299..9c099085c 100644 --- a/test/test_bit_stream_reader_big_endian.cpp +++ b/test/test_bit_stream_reader_big_endian.cpp @@ -210,7 +210,7 @@ namespace TEST(test_read_int8_t) { std::array storage = { char(0x01), char(0x5A), char(0xA5), char(0xFF) }; - std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big); @@ -246,7 +246,7 @@ namespace TEST(test_read_checked_int8_t_using_non_member_function) { std::array storage = { char(0x01), char(0x5A), char(0xA5), char(0xFF) }; - std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big); @@ -282,7 +282,7 @@ namespace TEST(test_read_unchecked_int8_t_using_non_member_function) { std::array storage = { char(0x01), char(0x5A), char(0xA5), char(0xFF) }; - std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big); @@ -307,7 +307,7 @@ namespace TEST(test_read_int8_t_5bits) { std::array storage = { char(0x0E), char(0x8B), char(0xF0) }; - std::array expected = { int8_t(0x01), int8_t(0xFA), int8_t(0x05), int8_t(0xFF) }; + std::array expected = { int8_t(0x01), int8_t(0xFA), int8_t(0x05), int8_t(0xFF) }; etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big); diff --git a/test/test_bresenham_line.cpp b/test/test_bresenham_line.cpp index 96f5e231c..e350e894f 100644 --- a/test/test_bresenham_line.cpp +++ b/test/test_bresenham_line.cpp @@ -44,7 +44,7 @@ namespace etl namespace { - using Value = char; + using Value = int8_t; using Point = etl::coordinate_2d; diff --git a/test/test_correlation.cpp b/test/test_correlation.cpp index 82f2d0327..aeed9f759 100644 --- a/test/test_correlation.cpp +++ b/test/test_correlation.cpp @@ -34,17 +34,17 @@ SOFTWARE. namespace { - std::array input_c + std::array input_c { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - std::array input_c_flat + std::array input_c_flat { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - std::array input_c_inv + std::array input_c_inv { 0, -1, -2, -3, -4, -5, -6, -7, -8, -9 }; @@ -120,21 +120,21 @@ namespace double covariance_result; // Negative correlation. - etl::correlation correlation1(input_c.begin(), input_c.end(), input_c_inv.begin()); + etl::correlation correlation1(input_c.begin(), input_c.end(), input_c_inv.begin()); correlation_result = correlation1; CHECK_CLOSE(-1.0, correlation_result, 0.1); covariance_result = correlation1.get_covariance(); CHECK_CLOSE(-8.25, covariance_result, 0.1); // Zero correlation - etl::correlation correlation2(input_c.begin(), input_c.end(), input_c_flat.begin()); + etl::correlation correlation2(input_c.begin(), input_c.end(), input_c_flat.begin()); correlation_result = correlation2; CHECK_CLOSE(0.0, correlation_result, 0.1); covariance_result = correlation2.get_covariance(); CHECK_CLOSE(0.0, covariance_result, 0.1); // Positive correlation. - etl::correlation correlation3(input_c.begin(), input_c.end(), input_c.begin()); + etl::correlation correlation3(input_c.begin(), input_c.end(), input_c.begin()); correlation_result = correlation3; CHECK_CLOSE(1.0, correlation_result, 0.1); covariance_result = correlation3.get_covariance(); @@ -148,21 +148,21 @@ namespace double covariance_result; // Negative correlation. - etl::correlation correlation1(input_c.begin(), input_c.end(), input_c_inv.begin()); + etl::correlation correlation1(input_c.begin(), input_c.end(), input_c_inv.begin()); correlation_result = correlation1; CHECK_CLOSE(-1.0, correlation_result, 0.1); covariance_result = correlation1.get_covariance(); CHECK_CLOSE(-9.17, covariance_result, 0.1); // Zero correlation - etl::correlation correlation2(input_c.begin(), input_c.end(), input_c_flat.begin()); + etl::correlation correlation2(input_c.begin(), input_c.end(), input_c_flat.begin()); correlation_result = correlation2; CHECK_CLOSE(0.0, correlation_result, 0.1); covariance_result = correlation2.get_covariance(); CHECK_CLOSE(0.0, covariance_result, 0.1); // Positive correlation. - etl::correlation correlation3(input_c.begin(), input_c.end(), input_c.begin()); + etl::correlation correlation3(input_c.begin(), input_c.end(), input_c.begin()); correlation_result = correlation3; CHECK_CLOSE(1.0, correlation_result, 0.1); covariance_result = correlation3.get_covariance(); diff --git a/test/test_covariance.cpp b/test/test_covariance.cpp index a127616c8..6ce84d726 100644 --- a/test/test_covariance.cpp +++ b/test/test_covariance.cpp @@ -34,17 +34,17 @@ SOFTWARE. namespace { - std::array input_c + std::array input_c { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - std::array input_c_flat + std::array input_c_flat { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - std::array input_c_inv + std::array input_c_inv { 0, -1, -2, -3, -4, -5, -6, -7, -8, -9 }; @@ -119,17 +119,17 @@ namespace double covariance_result; // Negative covariance. - etl::covariance covariance1(input_c.begin(), input_c.end(), input_c_inv.begin()); + etl::covariance covariance1(input_c.begin(), input_c.end(), input_c_inv.begin()); covariance_result = covariance1.get_covariance(); CHECK_CLOSE(-8.25, covariance_result, 0.1); // Zero covariance - etl::covariance covariance2(input_c.begin(), input_c.end(), input_c_flat.begin()); + etl::covariance covariance2(input_c.begin(), input_c.end(), input_c_flat.begin()); covariance_result = covariance2.get_covariance(); CHECK_CLOSE(0.0, covariance_result, 0.1); // Positive covariance. - etl::covariance covariance3(input_c.begin(), input_c.end(), input_c.begin()); + etl::covariance covariance3(input_c.begin(), input_c.end(), input_c.begin()); covariance_result = covariance3.get_covariance(); CHECK_CLOSE(8.25, covariance_result, 0.1); } @@ -140,17 +140,17 @@ namespace double covariance_result; // Negative covariance. - etl::covariance covariance1(input_c.begin(), input_c.end(), input_c_inv.begin()); + etl::covariance covariance1(input_c.begin(), input_c.end(), input_c_inv.begin()); covariance_result = covariance1.get_covariance(); CHECK_CLOSE(-9.17, covariance_result, 0.1); // Zero covariance - etl::covariance covariance2(input_c.begin(), input_c.end(), input_c_flat.begin()); + etl::covariance covariance2(input_c.begin(), input_c.end(), input_c_flat.begin()); covariance_result = covariance2.get_covariance(); CHECK_CLOSE(0.0, covariance_result, 0.1); // Positive covariance. - etl::covariance covariance3(input_c.begin(), input_c.end(), input_c.begin()); + etl::covariance covariance3(input_c.begin(), input_c.end(), input_c.begin()); covariance_result = covariance3.get_covariance(); CHECK_CLOSE(9.17, covariance_result, 0.1); } diff --git a/test/test_rms.cpp b/test/test_rms.cpp index cbc198841..39ae6753e 100644 --- a/test/test_rms.cpp +++ b/test/test_rms.cpp @@ -34,7 +34,7 @@ SOFTWARE. namespace { - std::array input_c + std::array input_c { // Sawtooth wave 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -8, -7, -6, -5, -4, -3, -2, -1 @@ -52,7 +52,7 @@ namespace //************************************************************************* TEST(test_char_rms) { - etl::rms rms(input_c.begin(), input_c.end()); + etl::rms rms(input_c.begin(), input_c.end()); double result = rms.get_rms(); CHECK_CLOSE(5.21, result, 0.05); From cf646a9d892f5386c79e5d542fb8479c64284868 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 6 Dec 2024 17:50:15 +0000 Subject: [PATCH 42/55] Fixed incorrect for loops in unit tests --- test/test_cyclic_value.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_cyclic_value.cpp b/test/test_cyclic_value.cpp index face6086c..f1f9e1930 100644 --- a/test/test_cyclic_value.cpp +++ b/test/test_cyclic_value.cpp @@ -287,7 +287,7 @@ namespace int expected[8] = { 2, 7, 6, 5, 4, 3, 2, 7 }; - for (int i = 0; i > 8; ++i) + for (int i = 0; i < 8; ++i) { CHECK_EQUAL(expected[i], value); --value; @@ -303,7 +303,7 @@ namespace int expected[8] = { 2, 7, 6, 5, 4, 3, 2, 7 }; - for (int i = 0; i > 8; ++i) + for (int i = 0; i < 8; ++i) { CHECK_EQUAL(expected[i], value); --value; From e7a17a5fb1c9da0d7399dad50af864c49714e6b6 Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Wed, 4 Dec 2024 11:17:32 +0100 Subject: [PATCH 43/55] Added const iterators to span (#986) --- include/etl/span.h | 76 +++++++++++++++++++++++++++++-- test/test_span_dynamic_extent.cpp | 4 ++ test/test_span_fixed_extent.cpp | 4 ++ 3 files changed, 80 insertions(+), 4 deletions(-) diff --git a/include/etl/span.h b/include/etl/span.h index 7aa11c960..acf76f1d5 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -71,8 +71,10 @@ namespace etl typedef T* pointer; typedef const T* const_pointer; - typedef T* iterator; - typedef ETL_OR_STD::reverse_iterator reverse_iterator; + typedef T* iterator; + typedef const T* const_iterator; + typedef ETL_OR_STD::reverse_iterator reverse_iterator; + typedef ETL_OR_STD::reverse_iterator const_reverse_iterator; typedef etl::circular_iterator circular_iterator; typedef etl::circular_iterator > reverse_circular_iterator; @@ -185,6 +187,14 @@ namespace etl return pbegin; } + //************************************************************************* + /// Returns a const iterator to the beginning of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT + { + return pbegin; + } + //************************************************************************* /// Returns an iterator to the beginning of the span. //************************************************************************* @@ -201,6 +211,14 @@ namespace etl return circular_iterator(begin(), end()); } + //************************************************************************* + /// Returns a const iterator to the end of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT + { + return (pbegin + Extent); + } + //************************************************************************* /// Returns an iterator to the end of the span. //************************************************************************* @@ -209,6 +227,14 @@ namespace etl return (pbegin + Extent); } + //************************************************************************* + // Returns a const reverse iterator to the reverse beginning of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT + { + return const_reverse_iterator((pbegin + Extent)); + } + //************************************************************************* // Returns an reverse iterator to the reverse beginning of the span. //************************************************************************* @@ -225,6 +251,14 @@ namespace etl return reverse_circular_iterator(rbegin(), rend()); } + //************************************************************************* + /// Returns a const reverse iterator to the end of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT + { + return const_reverse_iterator(pbegin); + } + //************************************************************************* /// Returns a reverse iterator to the end of the span. //************************************************************************* @@ -413,8 +447,10 @@ namespace etl typedef T* pointer; typedef const T* const_pointer; - typedef T* iterator; - typedef ETL_OR_STD::reverse_iterator reverse_iterator; + typedef T* iterator; + typedef const T* const_iterator; + typedef ETL_OR_STD::reverse_iterator reverse_iterator; + typedef ETL_OR_STD::reverse_iterator const_reverse_iterator; typedef etl::circular_iterator circular_iterator; typedef etl::circular_iterator > reverse_circular_iterator; @@ -544,6 +580,14 @@ namespace etl return pbegin; } + //************************************************************************* + /// Returns a const iterator to the beginning of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT + { + return pbegin; + } + //************************************************************************* /// Returns an iterator to the beginning of the span. //************************************************************************* @@ -560,6 +604,14 @@ namespace etl return circular_iterator(begin(), end()); } + //************************************************************************* + /// Returns a const iterator to the end of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_iterator cend() const ETL_NOEXCEPT + { + return pend; + } + //************************************************************************* /// Returns an iterator to the end of the span. //************************************************************************* @@ -576,6 +628,14 @@ namespace etl return reverse_iterator(pend); } + //************************************************************************* + // Returns a const reverse iterator to the reverse beginning of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crbegin() const ETL_NOEXCEPT + { + return const_reverse_iterator(pend); + } + //************************************************************************* /// Returns a reverse circular iterator to the end of the span. //************************************************************************* @@ -584,6 +644,14 @@ namespace etl return reverse_circular_iterator(rbegin(), rend()); } + //************************************************************************* + /// Returns a const reverse iterator to the end of the span. + //************************************************************************* + ETL_NODISCARD ETL_CONSTEXPR const_reverse_iterator crend() const ETL_NOEXCEPT + { + return const_reverse_iterator(pbegin); + } + //************************************************************************* /// Returns a reverse iterator to the end of the span. //************************************************************************* diff --git a/test/test_span_dynamic_extent.cpp b/test/test_span_dynamic_extent.cpp index 300ee58c5..7a1546700 100644 --- a/test/test_span_dynamic_extent.cpp +++ b/test/test_span_dynamic_extent.cpp @@ -409,15 +409,19 @@ namespace View view(etldata.begin(), etldata.end()); CView cview(etldata.begin(), etldata.end()); + CHECK_EQUAL(etldata.cbegin(), view.cbegin()); CHECK_EQUAL(etldata.begin(), view.begin()); CHECK_EQUAL(etldata.begin(), cview.begin()); + CHECK_EQUAL(etldata.cend(), view.crbegin().base()); CHECK_EQUAL(etldata.end(), view.rbegin().base()); CHECK_EQUAL(etldata.end(), cview.rbegin().base()); + CHECK_EQUAL(etldata.cend(), view.cend()); CHECK_EQUAL(etldata.end(), view.end()); CHECK_EQUAL(etldata.end(), cview.end()); + CHECK_EQUAL(etldata.cbegin(), view.crend().base()); CHECK_EQUAL(etldata.begin(), view.rend().base()); CHECK_EQUAL(etldata.begin(), cview.rend().base()); } diff --git a/test/test_span_fixed_extent.cpp b/test/test_span_fixed_extent.cpp index 2c760783a..33e8a6f56 100644 --- a/test/test_span_fixed_extent.cpp +++ b/test/test_span_fixed_extent.cpp @@ -397,15 +397,19 @@ namespace View view(etldata.begin(), etldata.end()); CView cview(etldata.begin(), etldata.end()); + CHECK_EQUAL(etldata.cbegin(), view.cbegin()); CHECK_EQUAL(etldata.begin(), view.begin()); CHECK_EQUAL(etldata.begin(), cview.begin()); + CHECK_EQUAL(etldata.cend(), view.crbegin().base()); CHECK_EQUAL(etldata.end(), view.rbegin().base()); CHECK_EQUAL(etldata.end(), cview.rbegin().base()); + CHECK_EQUAL(etldata.cend(), view.cend()); CHECK_EQUAL(etldata.end(), view.end()); CHECK_EQUAL(etldata.end(), cview.end()); + CHECK_EQUAL(etldata.cbegin(), view.crend().base()); CHECK_EQUAL(etldata.begin(), view.rend().base()); CHECK_EQUAL(etldata.begin(), cview.rend().base()); } From 1f43b2aa967c1e16ce9d2ce4b145edf386de7976 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 10 Dec 2024 11:25:54 +0000 Subject: [PATCH 44/55] Added constexpr --- include/etl/multi_span.h | 406 +++++++++++++++++++++++++++++++++++---- 1 file changed, 371 insertions(+), 35 deletions(-) diff --git a/include/etl/multi_span.h b/include/etl/multi_span.h index 4d93df42e..1affb8f07 100644 --- a/include/etl/multi_span.h +++ b/include/etl/multi_span.h @@ -38,7 +38,7 @@ SOFTWARE. #include "span.h" ///\defgroup multi_multi_span multi_span multi_span -/// Scatter/Gather functionality +/// Allows Scatter/Gather functionality ///\ingroup containers namespace etl @@ -62,36 +62,56 @@ namespace etl //************************************************************************* /// Iterator //************************************************************************* - class iterator : public etl::iterator + class iterator : public etl::iterator { public: friend class multi_span; + friend class const_iterator; - iterator() - : p_current(ETL_NULLPTR) - , p_end(ETL_NULLPTR) + //***************************************** + ETL_CONSTEXPR14 iterator() + : p_span_list(ETL_NULLPTR) + , p_current_span(ETL_NULLPTR) , p_value(ETL_NULLPTR) { } //***************************************** - iterator& operator ++() + ETL_CONSTEXPR14 iterator(const iterator& other) + : p_span_list(other.p_span_list) + , p_current_span(other.p_current_span) + , p_value(other.p_value) + { + } + + //***************************************** + ETL_CONSTEXPR14 iterator& operator =(const iterator& rhs) + { + p_span_list = rhs.p_span_list; + p_current_span = rhs.p_current_span; + p_value = rhs.p_value; + + return *this; + } + + //***************************************** + ETL_CONSTEXPR14 iterator& operator ++() { - if (p_current != p_end) + if (p_current_span != p_span_list->end()) { ++p_value; - if (p_value == p_current->end()) + if (p_value == p_current_span->end()) { do { - ++p_current; - } while ((p_current != p_end) && p_current->empty()); + ++p_current_span; + } while ((p_current_span != p_span_list->end()) && p_current_span->empty()); - if (p_current != p_end) + if (p_current_span != p_span_list->end()) { - p_value = p_current->begin(); + p_value = p_current_span->begin(); } else { @@ -104,7 +124,7 @@ namespace etl } //***************************************** - iterator operator ++(int) + ETL_CONSTEXPR14 iterator operator ++(int) { iterator temp = *this; @@ -113,10 +133,54 @@ namespace etl return temp; } + //***************************************** + ETL_CONSTEXPR14 iterator& operator --() + { + if (p_current_span == p_span_list->end()) + { + --p_current_span; + p_value = p_current_span->end(); + --p_value; + } + else if ((p_current_span != p_span_list->begin()) || (p_value != p_current_span->begin())) + { + if (p_value == p_current_span->begin()) + { + do + { + --p_current_span; + } while ((p_current_span != p_span_list->begin()) && p_current_span->empty()); + + p_value = p_current_span->end(); + --p_value; + } + else + { + --p_value; + } + } + else + { + p_value = ETL_NULLPTR; + } + + return *this; + } + + //***************************************** + ETL_CONSTEXPR14 iterator operator --(int) + { + iterator temp = *this; + + operator --(); + + return temp; + } + //************************************************************************* /// * operator //************************************************************************* - reference operator *() + ETL_CONSTEXPR14 reference operator *() { return *p_value; } @@ -124,7 +188,7 @@ namespace etl //************************************************************************* /// * operator //************************************************************************* - const_reference operator *() const + ETL_CONSTEXPR14 const_reference operator *() const { return *p_value; } @@ -132,7 +196,7 @@ namespace etl //************************************************************************* /// -> operator //************************************************************************* - pointer operator ->() + ETL_CONSTEXPR14 pointer operator ->() { return p_value; } @@ -140,7 +204,7 @@ namespace etl //************************************************************************* /// -> operator //************************************************************************* - const_pointer operator ->() const + ETL_CONSTEXPR14 const_pointer operator ->() const { return p_value; } @@ -148,39 +212,41 @@ namespace etl //************************************************************************* /// == operator //************************************************************************* - friend bool operator ==(const iterator& lhs, const iterator& rhs) + ETL_CONSTEXPR14 friend bool operator ==(const iterator& lhs, const iterator& rhs) { - return (lhs.p_current == rhs.p_current); + return (lhs.p_current_span == rhs.p_current_span) && (lhs.p_value == rhs.p_value); } //************************************************************************* /// != operator //************************************************************************* - friend bool operator !=(const iterator& lhs, const iterator& rhs) + ETL_CONSTEXPR14 friend bool operator !=(const iterator& lhs, const iterator& rhs) { return !(lhs == rhs); } private: + typedef const span_type* span_pointer; + typedef const span_list_type* span_list_pointer; typedef typename span_list_type::iterator span_list_iterator; //***************************************** - iterator(span_list_iterator p_current_, span_list_iterator p_end_) - : p_current(p_current_) - , p_end(p_end_) + ETL_CONSTEXPR14 iterator(const span_list_type& span_list_, span_list_iterator p_current_span_) + : p_span_list(&span_list_) + , p_current_span(p_current_span_) , p_value(ETL_NULLPTR) { - if (p_current != p_end) + if (p_current_span != p_span_list->end()) { - while ((p_current != p_end) && p_current->empty()) + while ((p_current_span != p_span_list->end()) && p_current_span->empty()) { - ++p_current; + ++p_current_span; } - if (p_current != p_end) + if (p_current_span != p_span_list->end()) { - p_value = p_current->begin(); + p_value = p_current_span->begin(); } else { @@ -189,13 +255,216 @@ namespace etl } } - typedef const span_type* span_list_pointer; - - span_list_pointer p_current; - span_list_pointer p_end; + span_list_pointer p_span_list; + span_pointer p_current_span; pointer p_value; }; + //************************************************************************* + /// Const Iterator + //************************************************************************* + class const_iterator : public etl::iterator + { + public: + + friend class multi_span; + + //***************************************** + ETL_CONSTEXPR14 const_iterator() + : p_span_list(ETL_NULLPTR) + , p_current_span(ETL_NULLPTR) + , p_value(ETL_NULLPTR) + { + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator(const const_iterator& other) + : p_span_list(other.p_span_list) + , p_current_span(other.p_current_span) + , p_value(other.p_value) + { + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator& operator =(const const_iterator& rhs) + { + p_span_list = rhs.p_span_list; + p_current_span = rhs.p_current_span; + p_value = rhs.p_value; + + return *this; + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator(const etl::multi_span::iterator& other) + : p_span_list(other.p_span_list) + , p_current_span(other.p_current_span) + , p_value(other.p_value) + { + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator& operator =(const etl::multi_span::iterator& rhs) + { + p_span_list = rhs.p_span_list; + p_current_span = rhs.p_current_span; + p_value = rhs.p_value; + + return *this; + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator& operator ++() + { + if (p_current_span != p_span_list->end()) + { + ++p_value; + + if (p_value == p_current_span->end()) + { + do + { + ++p_current_span; + } while ((p_current_span != p_span_list->end()) && p_current_span->empty()); + + if (p_current_span != p_span_list->end()) + { + p_value = p_current_span->begin(); + } + else + { + p_value = ETL_NULLPTR; + } + } + } + + return *this; + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator operator ++(int) + { + const_iterator temp = *this; + + operator ++(); + + return temp; + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator& operator --() + { + if (p_current_span == p_span_list->end()) + { + --p_current_span; + p_value = p_current_span->end(); + --p_value; + } + else if ((p_current_span != p_span_list->begin()) || (p_value != p_current_span->begin())) + { + if (p_value == p_current_span->begin()) + { + do + { + --p_current_span; + } while ((p_current_span != p_span_list->begin()) && p_current_span->empty()); + + p_value = p_current_span->end(); + --p_value; + } + else + { + --p_value; + } + } + else + { + p_value = ETL_NULLPTR; + } + + return *this; + } + + //***************************************** + ETL_CONSTEXPR14 const_iterator operator --(int) + { + const_iterator temp = *this; + + operator --(); + + return temp; + } + + //************************************************************************* + /// * operator + //************************************************************************* + ETL_CONSTEXPR14 const_reference operator *() const + { + return *p_value; + } + + //************************************************************************* + /// -> operator + //************************************************************************* + ETL_CONSTEXPR14 const_pointer operator ->() const + { + return p_value; + } + + //************************************************************************* + /// == operator + //************************************************************************* + ETL_CONSTEXPR14 friend bool operator ==(const const_iterator& lhs, const const_iterator& rhs) + { + return (lhs.p_current_span == rhs.p_current_span) && (lhs.p_value == rhs.p_value); + } + + //************************************************************************* + /// != operator + //************************************************************************* + ETL_CONSTEXPR14 friend bool operator !=(const const_iterator& lhs, const const_iterator& rhs) + { + return !(lhs == rhs); + } + + private: + + typedef const span_type* span_pointer; + typedef const span_list_type* span_list_pointer; + typedef const typename span_list_type::iterator span_list_iterator; + + //***************************************** + ETL_CONSTEXPR14 const_iterator(const span_list_type& span_list_, span_list_iterator p_current_span_) + : p_span_list(&span_list_) + , p_current_span(p_current_span_) + , p_value(ETL_NULLPTR) + { + if (p_current_span != p_span_list->end()) + { + while ((p_current_span != p_span_list->end()) && p_current_span->empty()) + { + ++p_current_span; + } + + if (p_current_span != p_span_list->end()) + { + p_value = p_current_span->begin(); + } + else + { + p_value = ETL_NULLPTR; + } + } + } + + span_list_pointer p_span_list; + span_pointer p_current_span; + const_pointer p_value; + }; + + typedef ETL_OR_STD::reverse_iterator reverse_iterator; + typedef ETL_OR_STD::reverse_iterator const_reverse_iterator; + //************************************************************************* /// Constructor. //************************************************************************* @@ -253,7 +522,7 @@ namespace etl //************************************************************************* /// Assignment operator //************************************************************************* - ETL_CONSTEXPR14 multi_span& operator = (const multi_span & other) + ETL_CONSTEXPR14 multi_span& operator =(const multi_span & other) { span_list = other.span_list; @@ -265,7 +534,15 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 iterator begin() const { - return iterator(span_list.begin(), span_list.end()); + return iterator(span_list, span_list.begin()); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 const_iterator cbegin() const + { + return const_iterator(span_list, span_list.cbegin()); } //************************************************************************* @@ -273,7 +550,66 @@ namespace etl //************************************************************************* ETL_CONSTEXPR14 iterator end() const { - return iterator(span_list.end(), span_list.end()); + return iterator(span_list, span_list.end()); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 const_iterator cend() const + { + return const_iterator(span_list, span_list.cend()); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 reverse_iterator rbegin() const + { + return reverse_iterator(end()); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 reverse_iterator crbegin() const + { + return const_reverse_iterator(cend()); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 reverse_iterator rend() const + { + return reverse_iterator(begin()); + } + + //************************************************************************* + /// + //************************************************************************* + ETL_CONSTEXPR14 const_reverse_iterator crend() const + { + return const_reverse_iterator(cbegin()); + } + + //************************************************************************* + /// Returns a reference to the indexed value. + //************************************************************************* + ETL_CONSTEXPR14 reference operator[](size_t i) const + { + // Find the span in the span list. + size_t number_of_spans = span_list.size(); + + size_t index = 0; + + while ((i >= span_list[index].size()) && (index < number_of_spans)) + { + i -= span_list[index].size(); + ++index; + } + + return span_list[index][i]; } //************************************************************************* From cd7fd98b0bd7edb24094235c1a4a4e748fc1657b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 10 Dec 2024 11:26:30 +0000 Subject: [PATCH 45/55] Modified test data to have sentinel data --- test/test_multi_span.cpp | 603 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 579 insertions(+), 24 deletions(-) diff --git a/test/test_multi_span.cpp b/test/test_multi_span.cpp index 8658630b3..11c77196f 100644 --- a/test/test_multi_span.cpp +++ b/test/test_multi_span.cpp @@ -28,7 +28,6 @@ SOFTWARE. #include "unit_test_framework.h" -#include "etl/multi_span.h" #include "etl/multi_span.h" #include @@ -37,15 +36,20 @@ SOFTWARE. namespace { - const int data1[] = { 0, 1, 2, 3 }; - const int data2[] = { 4, 5, 6 }; - const int data3[] = { 7 }; - const int data4[] = { 8, 9 }; + constexpr int Sentinal1 = 91; + constexpr int Sentinal2 = 92; + constexpr int Sentinal3 = 93; + constexpr int Sentinal4 = 94; + + const std::array data1 = { 0, 1, 2, 3, Sentinal1 }; + const std::array data2 = { 4, 5, 6, Sentinal2 }; + const std::array data3 = { 7, Sentinal3 }; + const std::array data4 = { 8, 9, Sentinal4 }; - int data5[4]; - int data6[3]; - int data7[1]; - int data8[2]; + int data5[] = { 0, 0, 0, 0 }; + int data6[] = { 0, 0, 0 }; + int data7[] = { 0 }; + int data8[] = { 0, 0 }; struct Data { @@ -58,18 +62,100 @@ namespace SUITE(test_multi_span) { //************************************************************************* - TEST(test_constructor) + TEST(test_construct_from_span_list) + { + std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + etl::multi_span::span_list_type list(span_list.data(), span_list.size()); + + etl::multi_span ms_int(list); + + CHECK(!ms_int.empty()); + CHECK_EQUAL(5U, ms_int.size_spans()); + CHECK_EQUAL(40U, ms_int.size_bytes()); + CHECK_EQUAL(10U, ms_int.size()); + } + + //************************************************************************* + TEST(test_construct_from_container) + { + std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + etl::multi_span ms_int(span_list); + + CHECK(!ms_int.empty()); + CHECK_EQUAL(5U, ms_int.size_spans()); + CHECK_EQUAL(40U, ms_int.size_bytes()); + CHECK_EQUAL(10U, ms_int.size()); + } + + //************************************************************************* + TEST(test_construct_from_const_container) + { + const std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + etl::multi_span ms_int(span_list); + + CHECK(!ms_int.empty()); + CHECK_EQUAL(5U, ms_int.size_spans()); + CHECK_EQUAL(40U, ms_int.size_bytes()); + CHECK_EQUAL(10U, ms_int.size()); + } + + //************************************************************************* + TEST(test_construct_from_iterators) { std::vector> span_list = { - etl::span(data1), - etl::span(data2), + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), etl::span(), // Empty span. - etl::span(data3), - etl::span(data4) + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) }; - etl::multi_span ms_int(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + etl::multi_span ms_int(span_list.data(), span_list.size()); + + CHECK(!ms_int.empty()); + CHECK_EQUAL(5U, ms_int.size_spans()); + CHECK_EQUAL(40U, ms_int.size_bytes()); + CHECK_EQUAL(10U, ms_int.size()); + } + + //************************************************************************* + TEST(test_construct_from_iterators_and_length) + { + std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + etl::multi_span ms_int(span_list.data(), span_list.size()); CHECK(!ms_int.empty()); CHECK_EQUAL(5U, ms_int.size_spans()); @@ -85,7 +171,7 @@ namespace etl::span() // Empty span. }; - etl::multi_span ms_int(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + etl::multi_span ms_int(span_list.data(), span_list.size()); CHECK(ms_int.empty()); CHECK_EQUAL(1U, ms_int.size_spans()); @@ -113,14 +199,14 @@ namespace { std::vector> span_list = { - etl::span(data1), - etl::span(data2), + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), etl::span(), // Empty span. - etl::span(data3), - etl::span(data4) + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) }; - etl::multi_span ms_int(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + etl::multi_span ms_int(span_list.data(), span_list.size()); std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; std::vector result; @@ -142,7 +228,7 @@ namespace etl::span(data8) }; - etl::multi_span ms_int(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + etl::multi_span ms_int(span_list.data(), span_list.size()); std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; @@ -159,7 +245,7 @@ namespace etl::span(struct_data2) }; - etl::multi_span ms_data(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + etl::multi_span ms_data(span_list.data(), span_list.size()); etl::multi_span::iterator itr = ms_data.begin(); CHECK_EQUAL(struct_data1[0].i, itr->i); @@ -187,7 +273,7 @@ namespace etl::span() }; - etl::multi_span ms_data(etl::multi_span::span_list_type(std::begin(span_list), std::end(span_list))); + etl::multi_span ms_data(span_list.data(), span_list.size()); etl::multi_span::iterator itr = ms_data.begin(); @@ -205,5 +291,474 @@ namespace ++itr; CHECK(ETL_NULLPTR == itr.operator->()); } + + //************************************************************************* + TEST(test_increment_iterator_read) + { + std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::iterator exp_itr = expected.begin(); + + etl::multi_span::iterator ms_itr = ms_int.begin(); + etl::multi_span::iterator ms_end_itr = ms_int.end(); + + while (ms_itr != ms_end_itr) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + ++ms_itr; + ++exp_itr; + } + } + + //************************************************************************* + TEST(test_increment_iterator_write) + { + std::vector> span_list = + { + etl::span(data5), + etl::span(data6), + etl::span(), // Empty span. + etl::span(data7), + etl::span(data8) + }; + + etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::iterator exp_itr = expected.begin(); + + etl::multi_span::iterator ms_itr = ms_int.begin(); + etl::multi_span::iterator ms_end_itr = ms_int.end(); + + while (ms_itr != ms_end_itr) + { + // Fill the multi span + *ms_itr++ = *exp_itr++; + } + + ms_itr = ms_int.begin(); + exp_itr = expected.begin(); + + while (ms_itr != ms_end_itr) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + ++ms_itr; + ++exp_itr; + } + } + + //************************************************************************* + TEST(test_decrement_iterator_read) + { + std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::iterator exp_itr = expected.begin() + expected.size() - 1; + + etl::multi_span::iterator ms_itr = ms_int.begin(); + std::advance(ms_itr, ms_int.size() - 1); + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + if (i != 0) + { + --ms_itr; + --exp_itr; + } + } + } + + //************************************************************************* + TEST(test_decrement_iterator_write) + { + std::vector> span_list = + { + etl::span(data5), + etl::span(data6), + etl::span(), // Empty span. + etl::span(data7), + etl::span(data8) + }; + + etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::iterator exp_itr = expected.begin() + expected.size() - 1; + + etl::multi_span::iterator ms_itr = ms_int.begin(); + std::advance(ms_itr, ms_int.size() - 1); + + for (size_t i = 0; i < expected.size(); ++i) + { + *ms_itr = *exp_itr; + + if (i != 0) + { + --ms_itr; + --exp_itr; + } + } + + ms_itr = ms_int.begin(); + std::advance(ms_itr, ms_int.size() - 1); + exp_itr = expected.begin() + expected.size() - 1; + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + if (i != 0) + { + --ms_itr; + --exp_itr; + } + } + } + + //************************************************************************* + TEST(test_increment_const_iterator_read) + { + const std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + const etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::iterator exp_itr = expected.begin(); + + etl::multi_span::const_iterator ms_itr = ms_int.begin(); + etl::multi_span::const_iterator ms_end_itr = ms_int.end(); + + while (ms_itr != ms_end_itr) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + ++ms_itr; + ++exp_itr; + } + } + + //************************************************************************* + TEST(test_decrement_const_iterator_read) + { + const std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + const etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::iterator exp_itr = expected.begin() + expected.size() - 1; + + etl::multi_span::const_iterator ms_itr = ms_int.begin(); + std::advance(ms_itr, ms_int.size() - 1); + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + if (i != 0) + { + --ms_itr; + --exp_itr; + } + } + } + + //************************************************************************* + TEST(test_reverse_increment_iterator_read) + { + using span_type = etl::span; + using multi_span_type = etl::multi_span; + + std::vector span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + multi_span_type ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::reverse_iterator exp_itr = expected.rbegin(); + + multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); + multi_span_type::reverse_iterator ms_end_itr = ms_int.rend(); + + while (ms_itr != ms_end_itr) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + ++ms_itr; + ++exp_itr; + } + } + + //************************************************************************* + TEST(test_reverse_increment_iterator_write) + { + using span_type = etl::span; + using multi_span_type = etl::multi_span; + + std::vector span_list = + { + span_type(data5), + span_type(data6), + span_type(), // Empty span. + span_type(data7), + span_type(data8) + }; + + multi_span_type ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::reverse_iterator exp_itr = expected.rbegin(); + + multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); + multi_span_type::reverse_iterator ms_end_itr = ms_int.rend(); + + while (ms_itr != ms_end_itr) + { + *ms_itr++ = *exp_itr++; + } + + while (ms_itr != ms_end_itr) + { + CHECK_EQUAL(*++exp_itr, *++ms_itr); + } + } + + //************************************************************************* + TEST(test_reverse_decrement_iterator_read) + { + using multi_span_type = etl::multi_span; + + std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + multi_span_type ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::reverse_iterator exp_itr = expected.rbegin() + expected.size() - 1; + + multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); + std::advance(ms_itr, ms_int.size() - 1); + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + if (i < expected.size() - 1) + { + --ms_itr; + --exp_itr; + } + } + } + + //************************************************************************* + TEST(test_reverse_decrement_iterator_write) + { + using span_type = etl::span; + using multi_span_type = etl::multi_span; + + std::vector> span_list = + { + span_type(data5), + span_type(data6), + span_type(), // Empty span. + span_type(data7), + span_type(data8) + }; + + multi_span_type ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::reverse_iterator exp_itr = expected.rbegin() + expected.size() - 1; + + multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); + std::advance(ms_itr, ms_int.size() - 1); + + for (size_t i = 0; i < expected.size(); ++i) + { + *ms_itr = *exp_itr; + + if (i < expected.size() - 1) + { + --ms_itr; + --exp_itr; + } + } + + ms_itr = ms_int.rbegin(); + std::advance(ms_itr, ms_int.size() - 1); + exp_itr = expected.rbegin() + expected.size() - 1; + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + if (i < expected.size() - 1) + { + --ms_itr; + --exp_itr; + } + } + } + + //************************************************************************* + TEST(test_const_reverse_increment_iterator_read) + { + using span_type = etl::span; + using multi_span_type = etl::multi_span; + + const std::vector span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + const multi_span_type ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::reverse_iterator exp_itr = expected.rbegin(); + + multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); + multi_span_type::reverse_iterator ms_end_itr = ms_int.rend(); + + while (ms_itr != ms_end_itr) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + ++ms_itr; + ++exp_itr; + } + } + + //************************************************************************* + TEST(test_const_reverse_decrement_iterator_read) + { + using multi_span_type = etl::multi_span; + + const std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + const multi_span_type ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + std::vector::reverse_iterator exp_itr = expected.rbegin() + expected.size() - 1; + + multi_span_type::reverse_iterator ms_itr = ms_int.rbegin(); + std::advance(ms_itr, ms_int.size() - 1); + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(*exp_itr, *ms_itr); + + if (i < expected.size() - 1) + { + --ms_itr; + --exp_itr; + } + } + } + + //************************************************************************* + TEST(test_index_operator_read) + { + const std::vector> span_list = + { + etl::span(data1.data(), data1.size() - 1), + etl::span(data2.data(), data2.size() - 1), + etl::span(), // Empty span. + etl::span(data3.data(), data3.size() - 1), + etl::span(data4.data(), data4.size() - 1) + }; + + const etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + for (size_t i = 0; i < expected.size(); ++i) + { + CHECK_EQUAL(expected[i], ms_int[i]); + } + } + + //************************************************************************* + TEST(test_index_operator_write) + { + const std::vector> span_list = + { + etl::span(data5), + etl::span(data6), + etl::span(), // Empty span. + etl::span(data7), + etl::span(data8) + }; + + const etl::multi_span ms_int(span_list.data(), span_list.size()); + + std::vector expected = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + + for (size_t i = 0; i < expected.size(); ++i) + { + ms_int[i] = expected[i]; + + CHECK_EQUAL(expected[i], ms_int[i]); + } + } }; } From 72a2ad3fe91ad6c2c0f6e7a76a2dfce70eb756ba Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Tue, 10 Dec 2024 17:23:54 +0100 Subject: [PATCH 46/55] Add uncopyable.h, class uncopyable (#985) * Add uncopyable.h, class uncopyable * Added destructor and unit tests for etl::uncopyable --- include/etl/uncopyable.h | 57 ++++++++++++++++++++++++++++++++++ test/CMakeLists.txt | 1 + test/test_uncopyable.cpp | 66 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+) create mode 100644 include/etl/uncopyable.h create mode 100644 test/test_uncopyable.cpp diff --git a/include/etl/uncopyable.h b/include/etl/uncopyable.h new file mode 100644 index 000000000..92ca8392c --- /dev/null +++ b/include/etl/uncopyable.h @@ -0,0 +1,57 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2024 BMW AG + +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_UNCOPYABLE_INCLUDED +#define ETL_UNCOPYABLE_INCLUDED + +#include "platform.h" + +namespace etl +{ +#if ETL_USING_CPP11 + //*************************************************************************** + /// An uncopyable base class. + /// Can be used to make a class uncopyable by deriving from it. + //*************************************************************************** + class uncopyable + { + public: + uncopyable(uncopyable const&) = delete; + uncopyable& operator=(uncopyable const&) = delete; + + protected: + uncopyable() = default; + ~uncopyable() = default; + }; + +#endif +} + +#endif diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ce9e2a664..7441ae4ce 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -288,6 +288,7 @@ add_executable(etl_tests test_type_traits.cpp test_unaligned_type.cpp test_unaligned_type_constexpr.cpp + test_uncopyable.cpp test_unordered_map.cpp test_unordered_multimap.cpp test_unordered_multiset.cpp diff --git a/test/test_uncopyable.cpp b/test/test_uncopyable.cpp new file mode 100644 index 000000000..f059dfa75 --- /dev/null +++ b/test/test_uncopyable.cpp @@ -0,0 +1,66 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2024 BMW AG + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include "unit_test_framework.h" + +#include "etl/uncopyable.h" + +namespace +{ + class UncopyableClass: public etl::uncopyable + { + }; + + SUITE(test_uncopyable) + { + //************************************************************************* + TEST(test_construct) + { + UncopyableClass uc; + + (void) uc; + } + + //************************************************************************* + // This code is intentionally not compilable when activated +#if 0 + TEST(test_copy) + { + UncopyableClass uc1; + + // Can't be copied by construction + UncopyableClass uc2{uc1}; // compile error + (void) uc2; + + // Can't be copied by copy assignment + UncopyableClass uc3; + uc3 = uc1; // compile error + } +#endif + }; +} From 6b88bef8ab031a85572bc1618310afbd88e8604b Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 12 Dec 2024 18:15:31 +0000 Subject: [PATCH 47/55] Added uncopyable to VS2022 project and syntax-check scripts --- include/etl/uncopyable.h | 4 +++- test/syntax_check/c++03/CMakeLists.txt | 1 + test/syntax_check/c++11/CMakeLists.txt | 1 + test/syntax_check/c++14/CMakeLists.txt | 1 + test/syntax_check/c++17/CMakeLists.txt | 1 + test/syntax_check/c++20/CMakeLists.txt | 1 + test/syntax_check/uncopyable.h.t.cpp | 29 ++++++++++++++++++++++++++ test/vs2022/etl.vcxproj | 17 +++++++++++++++ test/vs2022/etl.vcxproj.filters | 9 ++++++++ 9 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 test/syntax_check/uncopyable.h.t.cpp diff --git a/include/etl/uncopyable.h b/include/etl/uncopyable.h index 92ca8392c..324e977d3 100644 --- a/include/etl/uncopyable.h +++ b/include/etl/uncopyable.h @@ -43,11 +43,13 @@ namespace etl class uncopyable { public: + uncopyable(uncopyable const&) = delete; uncopyable& operator=(uncopyable const&) = delete; protected: - uncopyable() = default; + + uncopyable() = default; ~uncopyable() = default; }; diff --git a/test/syntax_check/c++03/CMakeLists.txt b/test/syntax_check/c++03/CMakeLists.txt index fad0c6eb0..d03606bfd 100644 --- a/test/syntax_check/c++03/CMakeLists.txt +++ b/test/syntax_check/c++03/CMakeLists.txt @@ -296,6 +296,7 @@ target_sources(t98 PRIVATE etl_profile.h ../u8string.h.t.cpp ../u8string_stream.h.t.cpp ../unaligned_type.h.t.cpp + ../uncopyable.h.t.cpp ../unordered_map.h.t.cpp ../unordered_multimap.h.t.cpp ../unordered_multiset.h.t.cpp diff --git a/test/syntax_check/c++11/CMakeLists.txt b/test/syntax_check/c++11/CMakeLists.txt index f426cecca..28a692620 100644 --- a/test/syntax_check/c++11/CMakeLists.txt +++ b/test/syntax_check/c++11/CMakeLists.txt @@ -296,6 +296,7 @@ target_sources(t11 PRIVATE etl_profile.h ../u8string.h.t.cpp ../u8string_stream.h.t.cpp ../unaligned_type.h.t.cpp + ../uncopyable.h.t.cpp ../unordered_map.h.t.cpp ../unordered_multimap.h.t.cpp ../unordered_multiset.h.t.cpp diff --git a/test/syntax_check/c++14/CMakeLists.txt b/test/syntax_check/c++14/CMakeLists.txt index b7bc68b99..131ae2a2f 100644 --- a/test/syntax_check/c++14/CMakeLists.txt +++ b/test/syntax_check/c++14/CMakeLists.txt @@ -296,6 +296,7 @@ target_sources(t14 PRIVATE etl_profile.h ../u8string.h.t.cpp ../u8string_stream.h.t.cpp ../unaligned_type.h.t.cpp + ../uncopyable.h.t.cpp ../unordered_map.h.t.cpp ../unordered_multimap.h.t.cpp ../unordered_multiset.h.t.cpp diff --git a/test/syntax_check/c++17/CMakeLists.txt b/test/syntax_check/c++17/CMakeLists.txt index 5d8761ab2..f3fab390e 100644 --- a/test/syntax_check/c++17/CMakeLists.txt +++ b/test/syntax_check/c++17/CMakeLists.txt @@ -296,6 +296,7 @@ target_sources(t17 PRIVATE etl_profile.h ../u8string.h.t.cpp ../u8string_stream.h.t.cpp ../unaligned_type.h.t.cpp + ../uncopyable.h.t.cpp ../unordered_map.h.t.cpp ../unordered_multimap.h.t.cpp ../unordered_multiset.h.t.cpp diff --git a/test/syntax_check/c++20/CMakeLists.txt b/test/syntax_check/c++20/CMakeLists.txt index f38c48ada..98acefa9a 100644 --- a/test/syntax_check/c++20/CMakeLists.txt +++ b/test/syntax_check/c++20/CMakeLists.txt @@ -296,6 +296,7 @@ target_sources(t20 PRIVATE etl_profile.h ../u8string.h.t.cpp ../u8string_stream.h.t.cpp ../unaligned_type.h.t.cpp + ../uncopyable.h.t.cpp ../unordered_map.h.t.cpp ../unordered_multimap.h.t.cpp ../unordered_multiset.h.t.cpp diff --git a/test/syntax_check/uncopyable.h.t.cpp b/test/syntax_check/uncopyable.h.t.cpp new file mode 100644 index 000000000..90cc67eaf --- /dev/null +++ b/test/syntax_check/uncopyable.h.t.cpp @@ -0,0 +1,29 @@ +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2024 John Wellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#include diff --git a/test/vs2022/etl.vcxproj b/test/vs2022/etl.vcxproj index daac6aeae..a12b35aec 100644 --- a/test/vs2022/etl.vcxproj +++ b/test/vs2022/etl.vcxproj @@ -3257,6 +3257,7 @@ + @@ -7629,6 +7630,21 @@ true true + + true + true + true + true + true + true + true + true + true + true + true + true + true + true true @@ -8966,6 +8982,7 @@ + diff --git a/test/vs2022/etl.vcxproj.filters b/test/vs2022/etl.vcxproj.filters index 8344c20b1..582ef36c0 100644 --- a/test/vs2022/etl.vcxproj.filters +++ b/test/vs2022/etl.vcxproj.filters @@ -1413,6 +1413,9 @@ ETL\Private + + ETL\Utilities + @@ -3386,6 +3389,12 @@ Tests\Syntax Checks\Source + + Tests\Misc + + + Tests\Syntax Checks\Source + From 00b6c9fcb4c8231e8949462c146d315cdabe1086 Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Thu, 12 Dec 2024 20:04:40 +0100 Subject: [PATCH 48/55] Return reference from emplace() in etl::queue (#992) --- include/etl/queue.h | 55 +++++++++++++++++++++++++++++---------------- test/test_queue.cpp | 16 ++++++++----- 2 files changed, 47 insertions(+), 24 deletions(-) diff --git a/include/etl/queue.h b/include/etl/queue.h index b704d8a1c..99e4d50eb 100644 --- a/include/etl/queue.h +++ b/include/etl/queue.h @@ -337,90 +337,107 @@ namespace etl //************************************************************************* /// Constructs a value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. - ///\param value The value to use to construct the item to push to the queue. + ///\param args The arguments to the constructor for the new item to push to the queue. //************************************************************************* template - void emplace(Args && ... args) + reference emplace(Args && ... args) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - ::new (&p_buffer[in]) T(etl::forward(args)...); + reference value = p_buffer[in]; + ::new (&value) T(etl::forward(args)...); add_in(); + return value; } #else //************************************************************************* - /// Constructs a value in the queue 'in place'. + /// Constructs a default constructed value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. - ///\param value The value to use to construct the item to push to the queue. //************************************************************************* - void emplace() + reference emplace() { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - ::new (&p_buffer[in]) T(); + reference value = p_buffer[in]; + ::new (&value) T(); add_in(); + return value; } //************************************************************************* /// Constructs a value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. - ///\param value The value to use to construct the item to push to the queue. + ///\param value1 The argument to use to construct the item to push to the queue. //************************************************************************* template - void emplace(const T1& value1) + reference emplace(const T1& value1) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - ::new (&p_buffer[in]) T(value1); + reference value = p_buffer[in]; + ::new (&value) T(value1); add_in(); + return value; } //************************************************************************* /// Constructs a value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. - ///\param value The value to use to construct the item to push to the queue. + ///\param value1 The first argument to use to construct the item to push to the queue. + ///\param value2 The second argument to use to construct the item to push to the queue. //************************************************************************* template - void emplace(const T1& value1, const T2& value2) + reference emplace(const T1& value1, const T2& value2) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - ::new (&p_buffer[in]) T(value1, value2); + reference value = p_buffer[in]; + ::new (&value) T(value1, value2); add_in(); + return value; } //************************************************************************* /// Constructs a value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. - ///\param value The value to use to construct the item to push to the queue. + ///\param value1 The first argument to use to construct the item to push to the queue. + ///\param value2 The second argument to use to construct the item to push to the queue. + ///\param value3 The third argument to use to construct the item to push to the queue. //************************************************************************* template - void emplace(const T1& value1, const T2& value2, const T3& value3) + reference emplace(const T1& value1, const T2& value2, const T3& value3) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - ::new (&p_buffer[in]) T(value1, value2, value3); + reference value = p_buffer[in]; + ::new (&value) T(value1, value2, value3); add_in(); + return value; } //************************************************************************* /// Constructs a value in the queue 'in place'. /// If asserts or exceptions are enabled, throws an etl::queue_full if the queue if already full. - ///\param value The value to use to construct the item to push to the queue. + ///\param value1 The first argument to use to construct the item to push to the queue. + ///\param value2 The second argument to use to construct the item to push to the queue. + ///\param value3 The third argument to use to construct the item to push to the queue. + ///\param value4 The fourth argument to use to construct the item to push to the queue. //************************************************************************* template - void emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + reference emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(queue_full)); #endif - ::new (&p_buffer[in]) T(value1, value2, value3, value4); + reference value = p_buffer[in]; + ::new (&value) T(value1, value2, value3, value4); add_in(); + return value; } #endif diff --git a/test/test_queue.cpp b/test/test_queue.cpp index ff966e3f9..71d033f10 100644 --- a/test/test_queue.cpp +++ b/test/test_queue.cpp @@ -369,11 +369,17 @@ namespace { etl::queue queue; - queue.emplace(); - queue.emplace('b', 2, 2.3); - queue.emplace('c', 3, 3.4); - queue.emplace('d', 4, 4.5); - queue.emplace('e', 5, 5.6); + Item& item_a = queue.emplace(); + Item& item_b = queue.emplace('b', 2, 2.3); + Item& item_c = queue.emplace('c', 3, 3.4); + Item& item_d = queue.emplace('d', 4, 4.5); + Item& item_e = queue.emplace('e', 5, 5.6); + + CHECK(item_a == Item('a', 1, 1.2)); + CHECK(item_b == Item('b', 2, 2.3)); + CHECK(item_c == Item('c', 3, 3.4)); + CHECK(item_d == Item('d', 4, 4.5)); + CHECK(item_e == Item('e', 5, 5.6)); CHECK(queue.front() == Item('a', 1, 1.2)); queue.pop(); From 99b2dacb6cea4e74992eaf33deb565befdcfb9e7 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 12 Dec 2024 19:42:54 +0000 Subject: [PATCH 49/55] Added return reference from stack::emplace --- include/etl/stack.h | 24 ++++++++++++++++++------ test/test_stack.cpp | 20 +++++++++++++++----- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/include/etl/stack.h b/include/etl/stack.h index a292218a3..1c3759060 100644 --- a/include/etl/stack.h +++ b/include/etl/stack.h @@ -283,13 +283,15 @@ namespace etl ///\param value The value to push to the stack. //************************************************************************* template - void emplace(Args && ... args) + reference emplace(Args && ... args) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif base_t::add_in(); ::new (&p_buffer[top_index]) T(etl::forward(args)...); + + return p_buffer[top_index]; } #else //************************************************************************* @@ -297,13 +299,15 @@ namespace etl /// If asserts or exceptions are enabled, throws an etl::stack_full if the stack is already full. ///\param value The value to push to the stack. //************************************************************************* - void emplace() + reference emplace() { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif base_t::add_in(); ::new (&p_buffer[top_index]) T(); + + return p_buffer[top_index]; } //************************************************************************* @@ -312,13 +316,15 @@ namespace etl ///\param value The value to push to the stack. //************************************************************************* template - void emplace(const T1& value1) + reference emplace(const T1& value1) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif base_t::add_in(); ::new (&p_buffer[top_index]) T(value1); + + return p_buffer[top_index]; } //************************************************************************* @@ -327,13 +333,15 @@ namespace etl ///\param value The value to push to the stack. //************************************************************************* template - void emplace(const T1& value1, const T2& value2) + reference emplace(const T1& value1, const T2& value2) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif base_t::add_in(); ::new (&p_buffer[top_index]) T(value1, value2); + + return p_buffer[top_index]; } //************************************************************************* @@ -342,13 +350,15 @@ namespace etl ///\param value The value to push to the stack. //************************************************************************* template - void emplace(const T1& value1, const T2& value2, const T3& value3) + reference emplace(const T1& value1, const T2& value2, const T3& value3) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif base_t::add_in(); ::new (&p_buffer[top_index]) T(value1, value2, value3); + + return p_buffer[top_index]; } //************************************************************************* @@ -357,13 +367,15 @@ namespace etl ///\param value The value to push to the stack. //************************************************************************* template - void emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) + reference emplace(const T1& value1, const T2& value2, const T3& value3, const T4& value4) { #if defined(ETL_CHECK_PUSH_POP) ETL_ASSERT(!full(), ETL_ERROR(stack_full)); #endif base_t::add_in(); ::new (&p_buffer[top_index]) T(value1, value2, value3, value4); + + return p_buffer[top_index]; } #endif diff --git a/test/test_stack.cpp b/test/test_stack.cpp index b27f7e115..81d35b467 100644 --- a/test/test_stack.cpp +++ b/test/test_stack.cpp @@ -231,28 +231,38 @@ namespace { etl::stack stack; - stack.emplace(); + Item& item1 = stack.emplace(); CHECK_EQUAL(1U, stack.size()); - stack.emplace('b', 2, 2.3); + Item& item2 = stack.emplace('b', 2, 2.3); CHECK_EQUAL(2U, stack.size()); - stack.emplace('c', 3, 3.4); + Item& item3 = stack.emplace('c', 3, 3.4); CHECK_EQUAL(3U, stack.size()); - stack.emplace('d', 4, 4.5); + Item& item4 = stack.emplace('d', 4, 4.5); CHECK_EQUAL(4U, stack.size()); - stack.emplace('e', 5, 5.6); + Item& item5 = stack.emplace('e', 5, 5.6); CHECK_EQUAL(5U, stack.size()); + CHECK(item1 == Item('a', 1, 1.2)); + CHECK(item2 == Item('b', 2, 2.3)); + CHECK(item3 == Item('c', 3, 3.4)); + CHECK(item4 == Item('d', 4, 4.5)); + CHECK(item5 == Item('e', 5, 5.6)); + CHECK(stack.top() == Item('e', 5, 5.6)); + stack.pop(); CHECK(stack.top() == Item('d', 4, 4.5)); + stack.pop(); CHECK(stack.top() == Item('c', 3, 3.4)); + stack.pop(); CHECK(stack.top() == Item('b', 2, 2.3)); + stack.pop(); CHECK(stack.top() == Item('a', 1, 1.2)); } From bde0d7d58488fec83c2ec56368030d9c489c17b0 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Sat, 14 Dec 2024 20:10:33 +0000 Subject: [PATCH 50/55] Changed etl::mem_cast to support bidirectional iterators --- include/etl/mem_cast.h | 92 +++++++++++++++++++++----------------- test/test_mem_cast.cpp | 75 ++++++++++++++++++++++++------- test/test_mem_cast_ptr.cpp | 81 ++++++++++++++++++++++++++------- 3 files changed, 177 insertions(+), 71 deletions(-) diff --git a/include/etl/mem_cast.h b/include/etl/mem_cast.h index 33b790217..c45b99af9 100644 --- a/include/etl/mem_cast.h +++ b/include/etl/mem_cast.h @@ -139,7 +139,7 @@ namespace etl { ETL_STATIC_ASSERT(Size >= sizeof(T), "Type size is too large"); - ::new (static_cast(buffer)) T(value); + ::new (static_cast(buffer.raw)) T(value); } //*********************************** @@ -148,7 +148,7 @@ namespace etl template void assign_at_offset(size_t offset, const T& value) { - char* p = static_cast(buffer) + offset; + char* p = static_cast(buffer.raw) + offset; ETL_ASSERT(sizeof(T) <= (Size - offset), ETL_ERROR(etl::mem_cast_size_exception)); ::new (p) T(value); @@ -160,7 +160,7 @@ namespace etl template void assign_at_offset(const T& value) { - char* p = static_cast(buffer) + Offset; + char* p = static_cast(buffer.raw) + Offset; ETL_STATIC_ASSERT(sizeof(T) <= (Size - Offset), "Type size is too large"); ::new (p) T(value); @@ -171,35 +171,41 @@ namespace etl /// Emplace from parameters //*********************************** template - void emplace(TArgs... args) + T& emplace(TArgs... args) { ETL_STATIC_ASSERT(Size >= sizeof(T), "Type size is too large"); - ::new (static_cast(buffer)) T(etl::forward(args)...); + ::new (static_cast(buffer.raw)) T(etl::forward(args)...); + + return ref(); } //*********************************** /// Emplace from parameters at offset //*********************************** template - void emplace_at_offset(size_t offset, TArgs... args) + T& emplace_at_offset(size_t offset, TArgs... args) { - char* p = static_cast(buffer) + offset; + char* p = static_cast(buffer.raw) + offset; ETL_ASSERT(sizeof(T) <= (Size - offset), ETL_ERROR(etl::mem_cast_size_exception)); ::new (p) T(etl::forward(args)...); + + return ref_at_offset(offset); } //*********************************** /// Emplace from parameters at offset //*********************************** template - void emplace_at_offset(TArgs... args) + T& emplace_at_offset(TArgs... args) { - char* p = static_cast(buffer) + Offset; + char* p = static_cast(buffer.raw) + Offset; ETL_STATIC_ASSERT(sizeof(T) <= (Size - Offset), "Type size is too large"); ::new (p) T(etl::forward(args)...); + + return ref_at_offset(); } #endif @@ -209,9 +215,9 @@ namespace etl template ETL_NODISCARD T& ref() { - ETL_STATIC_ASSERT(sizeof(T) <= Size, "Size of T is too large"); + ETL_STATIC_ASSERT(sizeof(T) <= Size, "Size of type too large for storage"); - return *static_cast(buffer); + return *reinterpret_cast(buffer.raw); } //*********************************** @@ -220,9 +226,9 @@ namespace etl template ETL_NODISCARD const T& ref() const { - ETL_STATIC_ASSERT(sizeof(T) <= Size, "Size of T is too large"); + ETL_STATIC_ASSERT(sizeof(T) <= Size, "Size of type too large for storage"); - return *static_cast(buffer); + return *reinterpret_cast(buffer.raw); } //*********************************** @@ -233,9 +239,7 @@ namespace etl { ETL_ASSERT(sizeof(T) <= (Size - offset), ETL_ERROR(etl::mem_cast_size_exception)); - char* p = buffer + offset; - - return *static_cast(p); + return *reinterpret_cast(buffer.raw + offset); } //*********************************** @@ -246,9 +250,7 @@ namespace etl { ETL_ASSERT(sizeof(T) <= (Size - offset), ETL_ERROR(etl::mem_cast_size_exception)); - char* p = buffer + offset; - - return *static_cast(p); + return *reinterpret_cast(buffer.raw + offset); } //*********************************** @@ -257,11 +259,9 @@ namespace etl template ETL_NODISCARD T& ref_at_offset() { - ETL_STATIC_ASSERT(sizeof(T) <= (Size - Offset), "Size of T is too large"); + ETL_STATIC_ASSERT(sizeof(T) <= (Size - Offset), "Size of type too large for storage"); - char* p = buffer + Offset; - - return *static_cast(p); + return *reinterpret_cast(buffer.raw + Offset); } //*********************************** @@ -270,11 +270,9 @@ namespace etl template ETL_NODISCARD const T& ref_at_offset() const { - ETL_STATIC_ASSERT(sizeof(T) <= (Size - Offset), "Size of T is too large"); - - char* p = buffer + Offset; + ETL_STATIC_ASSERT(sizeof(T) <= (Size - Offset), "Size of type too large for storage"); - return *static_cast(p); + return *reinterpret_cast(buffer.raw + Offset); } //*********************************** @@ -411,38 +409,44 @@ namespace etl /// Emplace from parameters //*********************************** template - void emplace(TArgs... args) + T& emplace(TArgs... args) { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); ETL_ASSERT(sizeof(T) <= buffer_size, ETL_ERROR(etl::mem_cast_size_exception)); ::new (pbuffer) T(etl::forward(args)...); + + return ref(); } //*********************************** /// Emplace from parameters at offset //*********************************** template - void emplace_at_offset(size_t offset, TArgs... args) + T& emplace_at_offset(size_t offset, TArgs... args) { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); char* p = pbuffer + offset; ETL_ASSERT(sizeof(T) <= (buffer_size - offset), ETL_ERROR(etl::mem_cast_size_exception)); ::new (p) T(etl::forward(args)...); + + return ref_at_offset(offset); } //*********************************** /// Emplace from parameters at offset //*********************************** template - void emplace_at_offset(TArgs... args) + T& emplace_at_offset(TArgs... args) { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); char* p = pbuffer + Offset; ETL_ASSERT(sizeof(T) <= (buffer_size - Offset), ETL_ERROR(etl::mem_cast_size_exception)); ::new (p) T(etl::forward(args)...); + + return ref_at_offset(); } #endif @@ -455,7 +459,9 @@ namespace etl ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); ETL_ASSERT(sizeof(T) <= buffer_size, ETL_ERROR(etl::mem_cast_size_exception)); - return *reinterpret_cast(pbuffer); + T* p = reinterpret_cast(pbuffer); + + return *p; } //*********************************** @@ -467,7 +473,9 @@ namespace etl ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); ETL_ASSERT(sizeof(T) <= buffer_size, ETL_ERROR(etl::mem_cast_size_exception)); - return *reinterpret_cast(pbuffer); + const T* p = reinterpret_cast(pbuffer); + + return *p; } //*********************************** @@ -477,10 +485,11 @@ namespace etl ETL_NODISCARD T& ref_at_offset(size_t offset) { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); - char* p = pbuffer + offset; ETL_ASSERT(sizeof(T) <= (buffer_size - offset), ETL_ERROR(etl::mem_cast_size_exception)); - return *reinterpret_cast(p); + T* p = reinterpret_cast(pbuffer + offset); + + return *p; } //*********************************** @@ -490,10 +499,11 @@ namespace etl ETL_NODISCARD const T& ref_at_offset(size_t offset) const { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); - char* p = pbuffer + offset; ETL_ASSERT(sizeof(T) <= (buffer_size - offset), ETL_ERROR(etl::mem_cast_size_exception)); - return *reinterpret_cast(p); + const T* p = reinterpret_cast(pbuffer + offset); + + return *p; } //*********************************** @@ -503,10 +513,11 @@ namespace etl ETL_NODISCARD T& ref_at_offset() { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); - char* p = pbuffer + Offset; ETL_ASSERT(sizeof(T) <= (buffer_size - Offset), ETL_ERROR(etl::mem_cast_size_exception)); - return *reinterpret_cast(p); + T* p = reinterpret_cast(pbuffer + Offset); + + return *p; } //*********************************** @@ -516,10 +527,11 @@ namespace etl ETL_NODISCARD const T& ref_at_offset() const { ETL_ASSERT((pbuffer != ETL_NULLPTR), ETL_ERROR(etl::mem_cast_nullptr_exception)); - char* p = pbuffer + Offset; ETL_ASSERT(sizeof(T) <= (buffer_size - Offset), ETL_ERROR(etl::mem_cast_size_exception)); - return *reinterpret_cast(p); + const T* p = reinterpret_cast(pbuffer + Offset); + + return *p; } //*********************************** diff --git a/test/test_mem_cast.cpp b/test/test_mem_cast.cpp index e8f5d986e..406231e9f 100644 --- a/test/test_mem_cast.cpp +++ b/test/test_mem_cast.cpp @@ -189,13 +189,22 @@ namespace { MemCast memCast; - memCast.emplace(123); + char mc1 = memCast.emplace(123); CHECK_EQUAL(123, memCast.ref()); + CHECK_EQUAL(123, mc1); - memCast.emplace(1.23); + double mc2 = memCast.emplace(1.23); CHECK_EQUAL(1.23, memCast.ref()); + CHECK_EQUAL(1.23, mc2); + + Data& mc3 = memCast.emplace(123, 1.23, std::array{ 1, 2, 3 }); + + CHECK_EQUAL(123, mc3.c); + CHECK_EQUAL(1.23, mc3.d); + CHECK_EQUAL(1, mc3.a[0]); + CHECK_EQUAL(2, mc3.a[1]); + CHECK_EQUAL(3, mc3.a[2]); - memCast.emplace(123, 1.23, std::array{ 1, 2, 3 }); CHECK_EQUAL(123, memCast.ref().c); CHECK_EQUAL(1.23, memCast.ref().d); CHECK_EQUAL(1, memCast.ref().a[0]); @@ -209,14 +218,32 @@ namespace MemCast memCast; using Array = std::array; - Array a{ 1, 2, 3 }; + Array compare{ 4, 5, 6 }; - size_t offset = offsetof(Data, a); + constexpr size_t ArrayOffset = offsetof(Data, a); - memCast.emplace_at_offset(offset, a); - CHECK_EQUAL(a[0], memCast.ref().a[0]); - CHECK_EQUAL(a[1], memCast.ref().a[1]); - CHECK_EQUAL(a[2], memCast.ref().a[2]); + Array& data = memCast.emplace_at_offset(ArrayOffset, compare); + const MemCast& constMemCastRef = memCast; + + CHECK_EQUAL(compare[0], memCast.ref().a[0]); + CHECK_EQUAL(compare[1], memCast.ref().a[1]); + CHECK_EQUAL(compare[2], memCast.ref().a[2]); + + CHECK_EQUAL(compare[0], (memCast.ref_at_offset(ArrayOffset)[0])); + CHECK_EQUAL(compare[1], (memCast.ref_at_offset(ArrayOffset)[1])); + CHECK_EQUAL(compare[2], (memCast.ref_at_offset(ArrayOffset)[2])); + + CHECK_EQUAL(compare[0], constMemCastRef.ref().a[0]); + CHECK_EQUAL(compare[1], constMemCastRef.ref().a[1]); + CHECK_EQUAL(compare[2], constMemCastRef.ref().a[2]); + + CHECK_EQUAL(compare[0], (constMemCastRef.ref_at_offset(ArrayOffset)[0])); + CHECK_EQUAL(compare[1], (constMemCastRef.ref_at_offset(ArrayOffset)[1])); + CHECK_EQUAL(compare[2], (constMemCastRef.ref_at_offset(ArrayOffset)[2])); + + CHECK_EQUAL(compare[0], data[0]); + CHECK_EQUAL(compare[1], data[1]); + CHECK_EQUAL(compare[2], data[2]); } //************************************************************************* @@ -225,14 +252,32 @@ namespace MemCast memCast; using Array = std::array; - Array a{ 1, 2, 3 }; + Array compare{ 4, 5, 6 }; - constexpr size_t Offset = offsetof(Data, a); + constexpr size_t ArrayOffset = offsetof(Data, a); - memCast.emplace_at_offset(a); - CHECK_EQUAL(a[0], memCast.ref().a[0]); - CHECK_EQUAL(a[1], memCast.ref().a[1]); - CHECK_EQUAL(a[2], memCast.ref().a[2]); + Array& data = memCast.emplace_at_offset(compare); + const MemCast& constMemCastRef = memCast; + + CHECK_EQUAL(compare[0], memCast.ref().a[0]); + CHECK_EQUAL(compare[1], memCast.ref().a[1]); + CHECK_EQUAL(compare[2], memCast.ref().a[2]); + + CHECK_EQUAL(compare[0], (memCast.ref_at_offset()[0])); + CHECK_EQUAL(compare[1], (memCast.ref_at_offset()[1])); + CHECK_EQUAL(compare[2], (memCast.ref_at_offset()[2])); + + CHECK_EQUAL(compare[0], constMemCastRef.ref().a[0]); + CHECK_EQUAL(compare[1], constMemCastRef.ref().a[1]); + CHECK_EQUAL(compare[2], constMemCastRef.ref().a[2]); + + CHECK_EQUAL(compare[0], (constMemCastRef.ref_at_offset()[0])); + CHECK_EQUAL(compare[1], (constMemCastRef.ref_at_offset()[1])); + CHECK_EQUAL(compare[2], (constMemCastRef.ref_at_offset()[2])); + + CHECK_EQUAL(compare[0], data[0]); + CHECK_EQUAL(compare[1], data[1]); + CHECK_EQUAL(compare[2], data[2]); } //************************************************************************* diff --git a/test/test_mem_cast_ptr.cpp b/test/test_mem_cast_ptr.cpp index ec8eadefd..e22c43222 100644 --- a/test/test_mem_cast_ptr.cpp +++ b/test/test_mem_cast_ptr.cpp @@ -237,20 +237,29 @@ namespace { char* pbuffer = reinterpret_cast(&buffer); - using Array = std::array; - MemCast memCast(pbuffer); - memCast.emplace(123); + char mc1 = memCast.emplace(123); CHECK_EQUAL(123, memCast.ref()); + CHECK_EQUAL(123, mc1); - memCast.emplace(1.23); + double mc2 = memCast.emplace(1.23); CHECK_EQUAL(1.23, memCast.ref()); + CHECK_EQUAL(1.23, mc2); - memCast.emplace(123, 1.23, std::array{ 1, 2, 3 }); - CHECK_EQUAL(123, memCast.ref().c); + Data& mc3 = memCast.emplace(123, 1.23, std::array{ 1, 2, 3 }); + + CHECK_EQUAL(123, mc3.c); + CHECK_EQUAL(1.23, mc3.d); + CHECK_EQUAL(1, mc3.a[0]); + CHECK_EQUAL(2, mc3.a[1]); + CHECK_EQUAL(3, mc3.a[2]); + + CHECK_EQUAL(123, memCast.ref().c); CHECK_EQUAL(1.23, memCast.ref().d); - CHECK((Array{ 1, 2, 3 }) == memCast.ref().a); + CHECK_EQUAL(1, memCast.ref().a[0]); + CHECK_EQUAL(2, memCast.ref().a[1]); + CHECK_EQUAL(3, memCast.ref().a[2]); } //************************************************************************* @@ -261,12 +270,32 @@ namespace MemCast memCast(pbuffer); using Array = std::array; - Array a{ 1, 2, 3 }; + Array compare{ 4, 5, 6 }; - size_t offset = offsetof(Data, a); + constexpr size_t ArrayOffset = offsetof(Data, a); - memCast.emplace_at_offset(offset, a); - CHECK(a == memCast.ref().a); + Array& data = memCast.emplace_at_offset(ArrayOffset, compare); + const MemCast& constMemCastRef = memCast; + + CHECK_EQUAL(compare[0], memCast.ref().a[0]); + CHECK_EQUAL(compare[1], memCast.ref().a[1]); + CHECK_EQUAL(compare[2], memCast.ref().a[2]); + + CHECK_EQUAL(compare[0], (memCast.ref_at_offset(ArrayOffset)[0])); + CHECK_EQUAL(compare[1], (memCast.ref_at_offset(ArrayOffset)[1])); + CHECK_EQUAL(compare[2], (memCast.ref_at_offset(ArrayOffset)[2])); + + CHECK_EQUAL(compare[0], constMemCastRef.ref().a[0]); + CHECK_EQUAL(compare[1], constMemCastRef.ref().a[1]); + CHECK_EQUAL(compare[2], constMemCastRef.ref().a[2]); + + CHECK_EQUAL(compare[0], (constMemCastRef.ref_at_offset(ArrayOffset)[0])); + CHECK_EQUAL(compare[1], (constMemCastRef.ref_at_offset(ArrayOffset)[1])); + CHECK_EQUAL(compare[2], (constMemCastRef.ref_at_offset(ArrayOffset)[2])); + + CHECK_EQUAL(compare[0], data[0]); + CHECK_EQUAL(compare[1], data[1]); + CHECK_EQUAL(compare[2], data[2]); } //************************************************************************* @@ -274,15 +303,35 @@ namespace { char* pbuffer = reinterpret_cast(&buffer); - MemCast memCast(pbuffer); + MemCast memCast(pbuffer); using Array = std::array; - Array a{ 1, 2, 3 }; + Array compare{ 4, 5, 6 }; - constexpr size_t Offset = offsetof(Data, a); + constexpr size_t ArrayOffset = offsetof(Data, a); - memCast.emplace_at_offset(a); - CHECK(a == memCast.ref().a); + Array& data = memCast.emplace_at_offset(compare); + const MemCast& constMemCastRef = memCast; + + CHECK_EQUAL(compare[0], memCast.ref().a[0]); + CHECK_EQUAL(compare[1], memCast.ref().a[1]); + CHECK_EQUAL(compare[2], memCast.ref().a[2]); + + CHECK_EQUAL(compare[0], (memCast.ref_at_offset()[0])); + CHECK_EQUAL(compare[1], (memCast.ref_at_offset()[1])); + CHECK_EQUAL(compare[2], (memCast.ref_at_offset()[2])); + + CHECK_EQUAL(compare[0], constMemCastRef.ref().a[0]); + CHECK_EQUAL(compare[1], constMemCastRef.ref().a[1]); + CHECK_EQUAL(compare[2], constMemCastRef.ref().a[2]); + + CHECK_EQUAL(compare[0], (constMemCastRef.ref_at_offset()[0])); + CHECK_EQUAL(compare[1], (constMemCastRef.ref_at_offset()[1])); + CHECK_EQUAL(compare[2], (constMemCastRef.ref_at_offset()[2])); + + CHECK_EQUAL(compare[0], data[0]); + CHECK_EQUAL(compare[1], data[1]); + CHECK_EQUAL(compare[2], data[2]); } //************************************************************************* From 22c1ed40583c355456c76e486e973072963daaa0 Mon Sep 17 00:00:00 2001 From: rolandreichweinbmw Date: Sat, 14 Dec 2024 22:36:15 +0100 Subject: [PATCH 51/55] Packed unaligned_type (#989) This way, unaligned_types like etl::be_uint32_t can be used in places where POD types are expected. --- include/etl/platform.h | 8 ++++++++ include/etl/unaligned_type.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/include/etl/platform.h b/include/etl/platform.h index 56ab83103..6ea92d362 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -460,6 +460,14 @@ SOFTWARE. #define ETL_HAS_INITIALIZER_LIST 0 #endif +//************************************* +// Determine if the ETL should use __attribute__((packed). +#if defined(ETL_COMPILER_CLANG) || defined(ETL_COMPILER_GCC) || defined(ETL_COMPILER_INTEL) + #define ETL_PACKED __attribute__((packed)) +#else + #define ETL_PACKED +#endif + //************************************* // Check for availability of certain builtins #include "profiles/determine_builtin_support.h" diff --git a/include/etl/unaligned_type.h b/include/etl/unaligned_type.h index 9b4ae6629..77e38ce12 100644 --- a/include/etl/unaligned_type.h +++ b/include/etl/unaligned_type.h @@ -227,7 +227,7 @@ namespace etl ///\tparam Endian The endianness of the arithmetic type. //************************************************************************* template - class unaligned_type : public private_unaligned_type::unaligned_type_common + class ETL_PACKED unaligned_type : public private_unaligned_type::unaligned_type_common { public: From 0f487fa12673a6aab406c1ed0bc23d5602eb406d Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Mon, 16 Dec 2024 14:58:16 +0000 Subject: [PATCH 52/55] Make 'packed' have better cross platform functionality --- include/etl/platform.h | 13 +++++++++++-- include/etl/unaligned_type.h | 6 +++--- test/test_etl_traits.cpp | 1 + test/test_utility.cpp | 26 ++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 5 deletions(-) diff --git a/include/etl/platform.h b/include/etl/platform.h index 6ea92d362..0583d17ae 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -462,10 +462,18 @@ SOFTWARE. //************************************* // Determine if the ETL should use __attribute__((packed). -#if defined(ETL_COMPILER_CLANG) || defined(ETL_COMPILER_GCC) || defined(ETL_COMPILER_INTEL) - #define ETL_PACKED __attribute__((packed)) +#if defined(ETL_COMPILER_CLANG) || defined(ETL_COMPILER_GCC) || defined(ETL_COMPILER_INTEL) || defined(ETL_COMPILER_ARM6) + #define ETL_PACKED __attribute__((packed)) + #define ETL_END_PACKED + #define ETL_HAS_PACKED 1 +#elif defined(ETL_COMPILER_MICROSOFT) + #define ETL_PACKED __pragma(pack(push, 1)) + #define ETL_END_PACKED __pragma(pack(pop)) + #define ETL_HAS_PACKED 1 #else #define ETL_PACKED + #define ETL_END_PACKED + #define ETL_HAS_PACKED 0 #endif //************************************* @@ -526,6 +534,7 @@ namespace etl static ETL_CONSTANT bool has_mutable_array_view = (ETL_HAS_MUTABLE_ARRAY_VIEW == 1); static ETL_CONSTANT bool has_ideque_repair = (ETL_HAS_IDEQUE_REPAIR == 1); static ETL_CONSTANT bool has_virtual_messages = (ETL_HAS_VIRTUAL_MESSAGES == 1); + static ETL_CONSTANT bool has_packed = (ETL_HAS_PACKED == 1); // Is... static ETL_CONSTANT bool is_debug_build = (ETL_IS_DEBUG_BUILD == 1); diff --git a/include/etl/unaligned_type.h b/include/etl/unaligned_type.h index 77e38ce12..1c406ba3c 100644 --- a/include/etl/unaligned_type.h +++ b/include/etl/unaligned_type.h @@ -53,7 +53,7 @@ namespace etl /// Contains all functionality that doesn't require the type. //************************************************************************* template - class unaligned_type_common + class ETL_PACKED unaligned_type_common { public: @@ -214,7 +214,7 @@ namespace etl protected: unsigned char storage[Size]; - }; + }; ETL_END_PACKED template ETL_CONSTANT size_t unaligned_type_common::Size; @@ -729,7 +729,7 @@ namespace etl } } }; - }; + }; ETL_END_PACKED template ETL_CONSTANT int unaligned_type::Endian; diff --git a/test/test_etl_traits.cpp b/test/test_etl_traits.cpp index a071960e4..24123ad3a 100644 --- a/test/test_etl_traits.cpp +++ b/test/test_etl_traits.cpp @@ -77,6 +77,7 @@ namespace CHECK_EQUAL((ETL_HAS_IDEQUE_REPAIR == 1), etl::traits::has_ideque_repair); CHECK_EQUAL((ETL_HAS_MUTABLE_ARRAY_VIEW == 1), etl::traits::has_mutable_array_view); CHECK_EQUAL((ETL_HAS_VIRTUAL_MESSAGES == 1), etl::traits::has_virtual_messages); + CHECK_EQUAL((ETL_HAS_PACKED == 1), etl::traits::has_packed); CHECK_EQUAL((ETL_IS_DEBUG_BUILD == 1), etl::traits::is_debug_build); CHECK_EQUAL(__cplusplus, etl::traits::cplusplus); diff --git a/test/test_utility.cpp b/test/test_utility.cpp index 223058547..5d7e28091 100644 --- a/test/test_utility.cpp +++ b/test/test_utility.cpp @@ -718,5 +718,31 @@ namespace CHECK_EQUAL(forward_like_call_type::ConstRValue, template_function_fl(etl::move(u4))); CHECK_EQUAL(forward_like_call_type::ConstRValue, template_function_fl(etl::move(u4))); } + +#if ETL_HAS_PACKED + //********************************* + TEST(test_packed) + { + struct Unpacked + { + uint32_t a = 0x12345678; + uint8_t b = 0x9A; + uint32_t c = 0x87654321; + }; + + struct ETL_PACKED Packed + { + uint32_t a = 0x12345678; + uint8_t b = 0x9A; + uint32_t c = 0x87654321; + }; ETL_END_PACKED + + Unpacked unpacked; + Packed packed; + + CHECK_TRUE(sizeof(unpacked) > sizeof(packed)); + CHECK_EQUAL(9U, sizeof(packed)); + } +#endif }; } From 784d95acaf2174e54b26047b1d6f462c42864a02 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Tue, 17 Dec 2024 17:10:48 +0000 Subject: [PATCH 53/55] Added additional transparent comparators to unordered containers --- include/etl/unordered_multiset.h | 74 ++++++++++++++++++++++++++++---- test/test_unordered_map.cpp | 18 ++++---- test/test_unordered_multimap.cpp | 8 ++-- test/test_unordered_multiset.cpp | 54 +++++++++++------------ test/test_unordered_set.cpp | 38 ++++++++-------- 5 files changed, 125 insertions(+), 67 deletions(-) diff --git a/include/etl/unordered_multiset.h b/include/etl/unordered_multiset.h index 9a91a16e3..a71ae1099 100644 --- a/include/etl/unordered_multiset.h +++ b/include/etl/unordered_multiset.h @@ -1164,12 +1164,14 @@ namespace etl return end(); } +#if ETL_USING_CPP11 //********************************************************************* /// Finds an element. ///\param key The key to search for. ///\return An iterator to the element if the key exists, otherwise end(). //********************************************************************* - const_iterator find(key_parameter_t key) const + template ::value, int> = 0> + iterator find(const K& key) { size_t index = get_bucket_index(key); @@ -1197,15 +1199,14 @@ namespace etl return end(); } +#endif -#if ETL_USING_CPP11 //********************************************************************* /// Finds an element. ///\param key The key to search for. ///\return An iterator to the element if the key exists, otherwise end(). //********************************************************************* - template ::value, int> = 0> - iterator find(const K& key) + const_iterator find(key_parameter_t key) const { size_t index = get_bucket_index(key); @@ -1224,7 +1225,7 @@ namespace etl // Do we have this one? if (key_equal_function(key, inode->key)) { - return iterator(pbuckets + number_of_buckets, pbucket, inode); + return iterator((pbuckets + number_of_buckets), pbucket, inode); } ++inode; @@ -1233,7 +1234,6 @@ namespace etl return end(); } -#endif #if ETL_USING_CPP11 //********************************************************************* @@ -1261,7 +1261,7 @@ namespace etl // Do we have this one? if (key_equal_function(key, inode->key)) { - return iterator(pbuckets + number_of_buckets, pbucket, inode); + return iterator((pbuckets + number_of_buckets), pbucket, inode); } ++inode; @@ -1271,7 +1271,7 @@ namespace etl return end(); } #endif - + //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1298,6 +1298,35 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a range containing all elements with key key in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return An iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) + { + iterator f = find(key); + iterator l = f; + + if (l != end()) + { + ++l; + + while ((l != end()) && key_equal_function(key, *l)) + { + ++l; + } + } + + return ETL_OR_STD::pair(f, l); + } +#endif + //********************************************************************* /// Returns a range containing all elements with key key in the container. /// The range is defined by two iterators, the first pointing to the first @@ -1324,6 +1353,35 @@ namespace etl return ETL_OR_STD::pair(f, l); } +#if ETL_USING_CPP11 + //********************************************************************* + /// Returns a range containing all elements with key key in the container. + /// The range is defined by two iterators, the first pointing to the first + /// element of the wanted range and the second pointing past the last + /// element of the range. + ///\param key The key to search for. + ///\return A const iterator pair to the range of elements if the key exists, otherwise end(). + //********************************************************************* + template ::value, int> = 0> + ETL_OR_STD::pair equal_range(const K& key) const + { + const_iterator f = find(key); + const_iterator l = f; + + if (l != end()) + { + ++l; + + while ((l != end()) && key_equal_function(key, *l)) + { + ++l; + } + } + + return ETL_OR_STD::pair(f, l); + } +#endif + //************************************************************************* /// Gets the size of the unordered_multiset. //************************************************************************* diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 34767d698..1c3ac5320 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -149,11 +149,11 @@ namespace } }; - typedef TestDataDC DC; - typedef TestDataNDC NDC; + using DC = TestDataDC; + using NDC = TestDataNDC; - typedef ETL_OR_STD::pair ElementDC; - typedef ETL_OR_STD::pair ElementNDC; + using ElementDC = ETL_OR_STD::pair; + using ElementNDC = ETL_OR_STD::pair; } namespace etl @@ -220,11 +220,11 @@ namespace using ItemM = TestDataM; using DataM = etl::unordered_map>; - typedef etl::unordered_map DataDC; - typedef etl::unordered_map DataNDC; - typedef etl::iunordered_map IDataNDC; - typedef etl::unordered_map> DataNDCTransparent; - typedef etl::unordered_map> DataDCTransparent; + using DataDC = etl::unordered_map; + using DataNDC = etl::unordered_map; + using IDataNDC = etl::iunordered_map; + using DataNDCTransparent = etl::unordered_map>; + using DataDCTransparent = etl::unordered_map>; NDC N0 = NDC("A"); NDC N1 = NDC("B"); diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index 9789af61e..f072d54a1 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -104,11 +104,11 @@ namespace } }; - typedef TestDataDC DC; - typedef TestDataNDC NDC; + using DC = TestDataDC; + using NDC = TestDataNDC; - typedef ETL_OR_STD::pair ElementDC; - typedef ETL_OR_STD::pair ElementNDC; + using ElementDC = ETL_OR_STD::pair; + using ElementNDC = ETL_OR_STD::pair; //*************************************************************************** struct CustomHashFunction diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index 49b8f59f0..4f5d520af 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -45,8 +45,8 @@ SOFTWARE. namespace { - typedef TestDataDC DC; - typedef TestDataNDC NDC; + using DC = TestDataDC; + using NDC = TestDataNDC; } namespace etl @@ -151,6 +151,7 @@ namespace } }; + //*************************************************************************** SUITE(test_unordered_multiset) { static const size_t SIZE = 10; @@ -177,11 +178,10 @@ namespace using DataM = etl::unordered_multiset; - typedef etl::unordered_multiset DataDC; - typedef etl::unordered_multiset DataNDC; - typedef etl::iunordered_multiset IDataNDC; - - typedef etl::unordered_multiset> DataTransparent; + using DataDC = etl::unordered_multiset; + using DataNDC = etl::unordered_multiset; + using IDataNDC = etl::iunordered_multiset; + using DataTransparent = etl::unordered_multiset>; const char* CK0 = "FF"; // 0 const char* CK1 = "FG"; // 1 @@ -204,26 +204,26 @@ namespace const char* CK18 = "FX"; // 8 const char* CK19 = "FY"; // 9 - NDC N0 = NDC(CK0); - NDC N1 = NDC(CK1); - NDC N2 = NDC(CK2); - NDC N3 = NDC(CK3); - NDC N4 = NDC(CK4); - NDC N5 = NDC(CK5); - NDC N6 = NDC(CK6); - NDC N7 = NDC(CK7); - NDC N8 = NDC(CK8); - NDC N9 = NDC(CK9); - NDC N10 = NDC(CK10); - NDC N11 = NDC(CK11); - NDC N12 = NDC(CK12); - NDC N13 = NDC(CK13); - NDC N14 = NDC(CK14); - NDC N15 = NDC(CK15); - NDC N16 = NDC(CK16); - NDC N17 = NDC(CK17); - NDC N18 = NDC(CK18); - NDC N19 = NDC(CK19); + NDC N0 = NDC("FF"); + NDC N1 = NDC("FG"); + NDC N2 = NDC("FH"); + NDC N3 = NDC("FI"); + NDC N4 = NDC("FJ"); + NDC N5 = NDC("FK"); + NDC N6 = NDC("FL"); + NDC N7 = NDC("FM"); + NDC N8 = NDC("FN"); + NDC N9 = NDC("FO"); + NDC N10 = NDC("FP"); + NDC N11 = NDC("FQ"); + NDC N12 = NDC("FR"); + NDC N13 = NDC("FS"); + NDC N14 = NDC("FT"); + NDC N15 = NDC("FU"); + NDC N16 = NDC("FV"); + NDC N17 = NDC("FW"); + NDC N18 = NDC("FX"); + NDC N19 = NDC("FY"); std::vector initial_data; std::vector excess_data; diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index 4336b4a79..0bf4b4315 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -45,8 +45,8 @@ SOFTWARE. namespace { - typedef TestDataDC DC; - typedef TestDataNDC NDC; + using DC = TestDataDC; + using NDC = TestDataNDC; } namespace etl @@ -178,10 +178,10 @@ namespace using DataM = etl::unordered_set; - typedef etl::unordered_set DataDC; - typedef etl::unordered_set DataNDC; - typedef etl::iunordered_set IDataNDC; - typedef etl::unordered_set> DataTransparent; + using DataDC = etl::unordered_set; + using DataNDC = etl::unordered_set; + using IDataNDC = etl::iunordered_set; + using DataTransparent = etl::unordered_set>; const char* CK0 = "FF"; // 0 const char* CK1 = "FG"; // 1 @@ -520,23 +520,23 @@ namespace } } - //************************************************************************* - TEST_FIXTURE(SetupFixture, test_insert_range_using_transparent_comparator) - { - std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_insert_range_using_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; - DataTransparent data; + DataTransparent data; - data.insert(initial.begin(), initial.end()); + data.insert(initial.begin(), initial.end()); - DataTransparent::iterator idata; + DataTransparent::iterator idata; - for (size_t i = 0UL; i < 8; ++i) - { - idata = data.find(initial[i]); - CHECK(idata != data.end()); - } - } + for (size_t i = 0UL; i < 8; ++i) + { + idata = data.find(initial[i]); + CHECK(idata != data.end()); + } + } //************************************************************************* TEST_FIXTURE(SetupFixture, test_insert_range_excess) From 1daa345038d941fa499f2671b494d5f93dea86a4 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 19 Dec 2024 10:21:59 +0000 Subject: [PATCH 54/55] Fix unused variables in test --- test/test_unordered_multiset.cpp | 40 ++++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index 4f5d520af..ad65e3642 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -204,26 +204,26 @@ namespace const char* CK18 = "FX"; // 8 const char* CK19 = "FY"; // 9 - NDC N0 = NDC("FF"); - NDC N1 = NDC("FG"); - NDC N2 = NDC("FH"); - NDC N3 = NDC("FI"); - NDC N4 = NDC("FJ"); - NDC N5 = NDC("FK"); - NDC N6 = NDC("FL"); - NDC N7 = NDC("FM"); - NDC N8 = NDC("FN"); - NDC N9 = NDC("FO"); - NDC N10 = NDC("FP"); - NDC N11 = NDC("FQ"); - NDC N12 = NDC("FR"); - NDC N13 = NDC("FS"); - NDC N14 = NDC("FT"); - NDC N15 = NDC("FU"); - NDC N16 = NDC("FV"); - NDC N17 = NDC("FW"); - NDC N18 = NDC("FX"); - NDC N19 = NDC("FY"); + NDC N0 = NDC(CK0); + NDC N1 = NDC(CK1); + NDC N2 = NDC(CK2); + NDC N3 = NDC(CK3); + NDC N4 = NDC(CK4); + NDC N5 = NDC(CK5); + NDC N6 = NDC(CK6); + NDC N7 = NDC(CK7); + NDC N8 = NDC(CK8); + NDC N9 = NDC(CK9); + NDC N10 = NDC(CK10); + NDC N11 = NDC(CK11); + NDC N12 = NDC(CK12); + NDC N13 = NDC(CK13); + NDC N14 = NDC(CK14); + NDC N15 = NDC(CK15); + NDC N16 = NDC(CK16); + NDC N17 = NDC(CK17); + NDC N18 = NDC(CK18); + NDC N19 = NDC(CK19); std::vector initial_data; std::vector excess_data; From 191eaae22502e28edde2a86a5ce05d15fb3838a5 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Thu, 19 Dec 2024 16:20:48 +0000 Subject: [PATCH 55/55] Added transparent comparator overloads of contains() --- include/etl/unordered_map.h | 11 +++++++++++ include/etl/unordered_multimap.h | 11 +++++++++++ include/etl/unordered_multiset.h | 11 +++++++++++ include/etl/unordered_set.h | 11 +++++++++++ test/test_unordered_map.cpp | 15 +++++++++++++-- test/test_unordered_multimap.cpp | 15 +++++++++++++-- test/test_unordered_multiset.cpp | 13 +++++++++++++ test/test_unordered_set.cpp | 13 +++++++++++++ 8 files changed, 96 insertions(+), 4 deletions(-) diff --git a/include/etl/unordered_map.h b/include/etl/unordered_map.h index b9d73d2f4..54d0bafaa 100644 --- a/include/etl/unordered_map.h +++ b/include/etl/unordered_map.h @@ -1689,6 +1689,17 @@ namespace etl return find(key) != end(); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Check if the unordered_map contains the key. + //************************************************************************* + template ::value, int> = 0> + bool contains(const K& key) const + { + return find(key) != end(); + } +#endif + protected: //********************************************************************* diff --git a/include/etl/unordered_multimap.h b/include/etl/unordered_multimap.h index b75eb84b3..3db0d1f5c 100644 --- a/include/etl/unordered_multimap.h +++ b/include/etl/unordered_multimap.h @@ -1450,6 +1450,17 @@ namespace etl return find(key) != end(); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Check if the unordered_map contains the key. + //************************************************************************* + template ::value, int> = 0> + bool contains(const K& key) const + { + return find(key) != end(); + } +#endif + protected: //********************************************************************* diff --git a/include/etl/unordered_multiset.h b/include/etl/unordered_multiset.h index a71ae1099..e0cf15909 100644 --- a/include/etl/unordered_multiset.h +++ b/include/etl/unordered_multiset.h @@ -1501,6 +1501,17 @@ namespace etl return find(key) != end(); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Check if the unordered_map contains the key. + //************************************************************************* + template ::value, int> = 0> + bool contains(const K& key) const + { + return find(key) != end(); + } +#endif + protected: //********************************************************************* diff --git a/include/etl/unordered_set.h b/include/etl/unordered_set.h index fd365102b..795eabfd6 100644 --- a/include/etl/unordered_set.h +++ b/include/etl/unordered_set.h @@ -1510,6 +1510,17 @@ namespace etl return find(key) != end(); } +#if ETL_USING_CPP11 + //************************************************************************* + /// Check if the unordered_map contains the key. + //************************************************************************* + template ::value, int> = 0> + bool contains(const K& key) const + { + return find(key) != end(); + } +#endif + protected: //********************************************************************* diff --git a/test/test_unordered_map.cpp b/test/test_unordered_map.cpp index 1c3ac5320..c38fb0dd9 100644 --- a/test/test_unordered_map.cpp +++ b/test/test_unordered_map.cpp @@ -1417,8 +1417,19 @@ namespace const char* not_inserted = "ZZ"; - CHECK(data.contains(std::string(K0))); - CHECK(!data.contains(std::string(not_inserted))); + CHECK_TRUE(data.contains(K0)); + CHECK_FALSE(data.contains(std::string(not_inserted))); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { + DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + const char* not_inserted = "ZZ"; + + CHECK_TRUE(data.contains("FF")); + CHECK_FALSE(data.contains(not_inserted)); } }; } diff --git a/test/test_unordered_multimap.cpp b/test/test_unordered_multimap.cpp index f072d54a1..716636e0e 100644 --- a/test/test_unordered_multimap.cpp +++ b/test/test_unordered_multimap.cpp @@ -1234,8 +1234,19 @@ namespace const char* not_inserted = "ZZ"; - CHECK(data.contains(K0)); - CHECK(!data.contains(not_inserted)); + CHECK_TRUE(data.contains(K0)); + CHECK_FALSE(data.contains(not_inserted)); + } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { + DataNDCTransparent data(initial_data.begin(), initial_data.end()); + + const char* not_inserted = "ZZ"; + + CHECK_TRUE(data.contains("FF")); + CHECK_FALSE(data.contains(not_inserted)); } }; } diff --git a/test/test_unordered_multiset.cpp b/test/test_unordered_multiset.cpp index ad65e3642..27bfe310e 100644 --- a/test/test_unordered_multiset.cpp +++ b/test/test_unordered_multiset.cpp @@ -1090,5 +1090,18 @@ namespace CHECK_TRUE(data.contains(N0)); CHECK_FALSE(data.contains(not_inserted)); } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data(initial.begin(), initial.end()); + + const char* not_inserted = "ZZ"; + + CHECK_TRUE(data.contains("FF")); + CHECK_FALSE(data.contains(not_inserted)); + } }; } diff --git a/test/test_unordered_set.cpp b/test/test_unordered_set.cpp index 0bf4b4315..189f97615 100644 --- a/test/test_unordered_set.cpp +++ b/test/test_unordered_set.cpp @@ -1055,5 +1055,18 @@ namespace CHECK_TRUE(data.contains(N0)); CHECK_FALSE(data.contains(not_inserted)); } + + //************************************************************************* + TEST(test_contains_with_transparent_comparator) + { + std::array initial = { "AA", "BB", "CC", "DD", "EE", "FF", "GG", "HH" }; + + DataTransparent data(initial.begin(), initial.end()); + + const char* not_inserted = "ZZ"; + + CHECK_TRUE(data.contains("FF")); + CHECK_FALSE(data.contains(not_inserted)); + } }; }