diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index f83e622e..462faec1 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -2705,10 +2705,10 @@ namespace etl /// Copy characters using pointers. /// Returns a pointer to the character after the last copied. //********************************************************************* - template + template static - typename etl::enable_if::value && etl::is_pointer::value, TIterator2>::type - copy_characters(TIterator1 from, size_t n, TIterator2 to) + typename etl::enable_if::type>::value && sizeof(typename etl::remove_pointer::type>::type) == sizeof(value_type), iterator>::type + copy_characters(TIterator1 from, size_t n, iterator to) { etl::mem_move(from, n, to); @@ -2719,10 +2719,10 @@ namespace etl /// Copy characters using non-pointers. /// Returns an iterator to the character after the last copied. //********************************************************************* - template + template static - typename etl::enable_if::value || !etl::is_pointer::value, TIterator2>::type - copy_characters(TIterator1 from, size_t n, TIterator2 to) + typename etl::enable_if::type>::value && sizeof(typename etl::remove_pointer::type>::type) == sizeof(value_type)), iterator>::type + copy_characters(TIterator1 from, size_t n, iterator to) { size_t count = 0; diff --git a/include/etl/u16string.h b/include/etl/u16string.h index 78ce3953..74eddeb2 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -441,7 +441,7 @@ namespace etl u16string_ext(TIterator first, TIterator last, value_type* buffer, size_type buffer_size, typename etl::enable_if::value, int>::type = 0) : iu16string(buffer, buffer_size - 1U) { - if (this->is_within_buffer(etl::addressof(*first))) + if (this->is_within_buffer(reinterpret_cast(etl::addressof(*first)))) { this->current_size = etl::distance(first, last); } diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 100cb2ec..2399b910 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -441,7 +441,7 @@ namespace etl u32string_ext(TIterator first, TIterator last, value_type* buffer, size_type buffer_size, typename etl::enable_if::value, int>::type = 0) : iu32string(buffer, buffer_size - 1U) { - if (this->is_within_buffer(etl::addressof(*first))) + if (this->is_within_buffer(reinterpret_cast(etl::addressof(*first)))) { this->current_size = etl::distance(first, last); } diff --git a/include/etl/wstring.h b/include/etl/wstring.h index b6cc173c..d683a160 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -441,7 +441,7 @@ namespace etl wstring_ext(TIterator first, TIterator last, value_type* buffer, size_type buffer_size, typename etl::enable_if::value, int>::type = 0) : iwstring(buffer, buffer_size - 1U) { - if (this->is_within_buffer(etl::addressof(*first))) + if (this->is_within_buffer(reinterpret_cast(etl::addressof(*first)))) { this->current_size = etl::distance(first, last); } diff --git a/test/test_string_u16.cpp b/test/test_string_u16.cpp index 9e683ac6..6662a82c 100644 --- a/test/test_string_u16.cpp +++ b/test/test_string_u16.cpp @@ -303,6 +303,36 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_8bit_range) + { + std::string text8Bit{"8-bit"}; + TextSTD compare_text(text8Bit.begin(), text8Bit.end()); + + Text text(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_EQUAL(text8Bit.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_8bit_const_range) + { + std::string const text8Bit{"8-bit"}; + TextSTD compare_text(text8Bit.begin(), text8Bit.end()); + + Text text(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_EQUAL(text8Bit.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_literal) { @@ -1202,6 +1232,34 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_8bit) + { + std::string text8Bit{"8-bit"}; + + Text text; + + text.assign(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_8bit_const) + { + std::string const text8Bit{"8-bit"}; + + Text text; + + text.assign(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { diff --git a/test/test_string_u16_external_buffer.cpp b/test/test_string_u16_external_buffer.cpp index 436b8651..a7a3279c 100644 --- a/test/test_string_u16_external_buffer.cpp +++ b/test/test_string_u16_external_buffer.cpp @@ -405,6 +405,61 @@ namespace CHECK(!text.empty()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_range_16bit) + { + TextBuffer buffer{0}; + Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK_EQUAL(SIZE, text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_range_16bit_const) + { + const View u16View{STR("16-bit")}; + TextBuffer buffer{0}; + Text text(u16View.begin(), u16View.end(), buffer.data(), buffer.size()); + + bool is_equal = Equal(u16View, text); + CHECK(is_equal); + CHECK_EQUAL(u16View.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_range_8bit) + { + std::string text8Bit{"8-bit"}; + TextBuffer buffer{0}; + Text text(text8Bit.begin(), text8Bit.end(), buffer.data(), buffer.size()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_EQUAL(text8Bit.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_range_8bit_const) + { + std::string const text8Bit{"8-bit"}; + TextBuffer buffer{0}; + Text text(text8Bit.begin(), text8Bit.end(), buffer.data(), buffer.size()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_EQUAL(text8Bit.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { @@ -1396,6 +1451,38 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_8bit) + { + std::string text8Bit{"8-bit"}; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text.assign(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + CHECK_EQUAL(text8Bit.size(), text.size()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_8bit_const) + { + std::string const text8Bit{"8-bit"}; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text.assign(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + CHECK_EQUAL(text8Bit.size(), text.size()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { diff --git a/test/test_string_u32.cpp b/test/test_string_u32.cpp index 97c01ab2..7b6be11d 100644 --- a/test/test_string_u32.cpp +++ b/test/test_string_u32.cpp @@ -303,6 +303,36 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_8bit_range) + { + std::string text8Bit{"8-bit"}; + TextSTD compare_text(text8Bit.begin(), text8Bit.end()); + + Text text(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_EQUAL(text8Bit.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_8bit_const_range) + { + std::string const text8Bit{"8-bit"}; + TextSTD compare_text(text8Bit.begin(), text8Bit.end()); + + Text text(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_EQUAL(text8Bit.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_literal) { @@ -1202,6 +1232,34 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_8bit) + { + std::string text8Bit{"8-bit"}; + + Text text; + + text.assign(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_8bit_const) + { + std::string const text8Bit{"8-bit"}; + + Text text; + + text.assign(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { diff --git a/test/test_string_u32_external_buffer.cpp b/test/test_string_u32_external_buffer.cpp index 56e82b54..fb7d2104 100644 --- a/test/test_string_u32_external_buffer.cpp +++ b/test/test_string_u32_external_buffer.cpp @@ -405,6 +405,61 @@ namespace CHECK(!text.empty()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_range_32bit) + { + TextBuffer buffer{0}; + Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK_EQUAL(SIZE, text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_range_32bit_const) + { + const View u32View{STR("32-bit")}; + TextBuffer buffer{0}; + Text text(u32View.begin(), u32View.end(), buffer.data(), buffer.size()); + + bool is_equal = Equal(u32View, text); + CHECK(is_equal); + CHECK_EQUAL(u32View.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_range_8bit) + { + std::string text8Bit{"8-bit"}; + TextBuffer buffer{0}; + Text text(text8Bit.begin(), text8Bit.end(), buffer.data(), buffer.size()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_EQUAL(text8Bit.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_range_8bit_const) + { + std::string const text8Bit{"8-bit"}; + TextBuffer buffer{0}; + Text text(text8Bit.begin(), text8Bit.end(), buffer.data(), buffer.size()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_EQUAL(text8Bit.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { @@ -1396,6 +1451,38 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_8bit) + { + std::string text8Bit{"8-bit"}; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text.assign(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + CHECK_EQUAL(text8Bit.size(), text.size()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_8bit_const) + { + std::string const text8Bit{"8-bit"}; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text.assign(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + CHECK_EQUAL(text8Bit.size(), text.size()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { diff --git a/test/test_string_wchar_t.cpp b/test/test_string_wchar_t.cpp index 9a572988..b269b70c 100644 --- a/test/test_string_wchar_t.cpp +++ b/test/test_string_wchar_t.cpp @@ -304,6 +304,36 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_8bit_range) + { + std::string text8Bit{"8-bit"}; + TextSTD compare_text(text8Bit.begin(), text8Bit.end()); + + Text text(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_EQUAL(text8Bit.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_8bit_const_range) + { + std::string const text8Bit{"8-bit"}; + TextSTD compare_text(text8Bit.begin(), text8Bit.end()); + + Text text(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_EQUAL(text8Bit.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_constructor_from_literal) { @@ -1203,6 +1233,34 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_8bit) + { + std::string text8Bit{"8-bit"}; + + Text text; + + text.assign(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_8bit_const) + { + std::string const text8Bit{"8-bit"}; + + Text text; + + text.assign(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) { diff --git a/test/test_string_wchar_t_external_buffer.cpp b/test/test_string_wchar_t_external_buffer.cpp index ad7efb12..2926beb2 100644 --- a/test/test_string_wchar_t_external_buffer.cpp +++ b/test/test_string_wchar_t_external_buffer.cpp @@ -408,6 +408,61 @@ namespace CHECK(!text.empty()); } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_range_32bit) + { + TextBuffer buffer{0}; + Text text(initial_text.begin(), initial_text.end(), buffer.data(), buffer.size()); + + bool is_equal = Equal(initial_text, text); + CHECK(is_equal); + CHECK_EQUAL(SIZE, text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_range_32bit_const) + { + const View wstrView{STR("wchar")}; + TextBuffer buffer{0}; + Text text(wstrView.begin(), wstrView.end(), buffer.data(), buffer.size()); + + bool is_equal = Equal(wstrView, text); + CHECK(is_equal); + CHECK_EQUAL(wstrView.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_range_8bit) + { + std::string text8Bit{"8-bit"}; + TextBuffer buffer{0}; + Text text(text8Bit.begin(), text8Bit.end(), buffer.data(), buffer.size()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_EQUAL(text8Bit.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_constructor_from_range_8bit_const) + { + std::string const text8Bit{"8-bit"}; + TextBuffer buffer{0}; + Text text(text8Bit.begin(), text8Bit.end(), buffer.data(), buffer.size()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_EQUAL(text8Bit.size(), text.size()); + CHECK_FALSE(text.empty()); + CHECK_FALSE(text.is_truncated()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_copy_constructor) { @@ -1399,6 +1454,38 @@ namespace #endif } + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_8bit) + { + std::string text8Bit{"8-bit"}; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text.assign(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + CHECK_EQUAL(text8Bit.size(), text.size()); + } + + //************************************************************************* + TEST_FIXTURE(SetupFixture, test_assign_range_8bit_const) + { + std::string const text8Bit{"8-bit"}; + + TextBuffer buffer{0}; + Text text(buffer.data(), buffer.size()); + + text.assign(text8Bit.begin(), text8Bit.end()); + + bool is_equal = Equal(text8Bit, text); + CHECK(is_equal); + CHECK_FALSE(text.is_truncated()); + CHECK_EQUAL(text8Bit.size(), text.size()); + } + //************************************************************************* TEST_FIXTURE(SetupFixture, test_assign_size_value) {