diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index 7232a6d0..9dd93ead 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -2757,10 +2757,11 @@ namespace etl } //********************************************************************* - /// Common implementation for 'assign' and 'append' for iterators. + /// Common implementation for 'assign' and 'append' for non-pointer iterators. //********************************************************************* template - void append_impl(iterator position, TIterator first, TIterator last, bool truncated, bool secure) + typename etl::enable_if::type>::value>::type + append_impl(iterator position, TIterator first, TIterator last, bool truncated, bool secure) { difference_type start = etl::distance(p_buffer, position); difference_type count = etl::distance(first, last); @@ -2809,20 +2810,29 @@ namespace etl return; } - difference_type start = etl::distance(p_buffer, position); - difference_type free_space = etl::distance(position, p_buffer + CAPACITY); + append_impl(position, src, get_string_length(src), truncated, secure); + } - pointer dst = position; - size_t length = get_string_length(src); - size_t count = (length < size_t(free_space)) ? length : size_t(free_space); - etl::mem_move(src, count, dst); + //********************************************************************* + /// Core non-template implementation for 'assign' and 'append'. + //********************************************************************* + void append_impl(iterator position, const_pointer src, size_t length, bool truncated, bool secure) + { + size_t start = static_cast(etl::distance(p_buffer, position)); + size_t free_space = static_cast(etl::distance(position, p_buffer + CAPACITY)); + size_t count = etl::min(length, free_space); - truncated |= (src[count] != 0); - current_size = size_t(start) + count; +#if ETL_IS_DEBUG_BUILD + ETL_ASSERT(start <= CAPACITY, ETL_ERROR(string_iterator)); +#endif + + etl::mem_move(src, count, position); + + current_size = start + count; p_buffer[current_size] = 0; #if ETL_HAS_STRING_TRUNCATION_CHECKS - set_truncated(truncated); + set_truncated((length > free_space) || truncated); #if ETL_HAS_ERROR_ON_STRING_TRUNCATION ETL_ASSERT(is_truncated() == false, ETL_ERROR(string_truncation)); #endif @@ -2842,6 +2852,16 @@ namespace etl cleanup(); } + //********************************************************************* + /// Common implementation for 'assign' and 'append' for pointer iterators. + //********************************************************************* + template + typename etl::enable_if::type>::value>::type + append_impl(iterator position, TIterator first, TIterator last, bool truncated, bool secure) + { + append_impl(position, first, size_t(etl::distance(first, last)), truncated || is_truncated(), secure); + } + //************************************************************************* /// Common implementation for 'find'. //************************************************************************* diff --git a/include/etl/string.h b/include/etl/string.h index 6fa1fccf..a0a0dd29 100644 --- a/include/etl/string.h +++ b/include/etl/string.h @@ -92,7 +92,6 @@ namespace etl string(const etl::string& other) : istring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(other); } @@ -103,7 +102,6 @@ namespace etl string(const etl::istring& other) : istring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(other); } @@ -118,7 +116,6 @@ namespace etl { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->initialise(); this->assign(other, position, length); } @@ -129,7 +126,6 @@ namespace etl ETL_EXPLICIT_STRING_FROM_CHAR string(const value_type* text) : istring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(text); } @@ -141,7 +137,6 @@ namespace etl string(const value_type* text, size_t count) : istring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(text, text + count); } @@ -167,7 +162,6 @@ namespace etl string(TIterator first, TIterator last, typename etl::enable_if::value, int>::type = 0) : istring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(first, last); } @@ -178,7 +172,6 @@ namespace etl string(std::initializer_list init) : istring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(init.begin(), init.end()); } #endif @@ -190,7 +183,6 @@ namespace etl explicit string(const etl::string_view& view) : istring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(view.begin(), view.end()); } @@ -329,7 +321,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -347,7 +338,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -367,7 +357,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -389,7 +378,6 @@ namespace etl } else { - this->initialise(); this->assign(other, position, length); } } @@ -413,7 +401,6 @@ namespace etl } else { - this->initialise(); this->assign(other, position, length); } } @@ -433,8 +420,7 @@ namespace etl } else { - this->initialise(); - this->assign(text, text + etl::strlen(text)); + this->assign(text); } } @@ -454,8 +440,7 @@ namespace etl } else { - this->initialise(); - this->assign(text, text + etl::strlen(text)); + this->assign(text); } } @@ -473,7 +458,6 @@ namespace etl } else { - this->initialise(); this->assign(literal); } } @@ -493,7 +477,6 @@ namespace etl } else { - this->initialise(); this->assign(literal); } } @@ -512,7 +495,6 @@ namespace etl } else { - this->initialise(); this->assign(text, text + count); } } @@ -533,7 +515,6 @@ namespace etl } else { - this->initialise(); this->assign(text, text + count); } } @@ -577,7 +558,6 @@ namespace etl } else { - this->initialise(); this->assign(view.begin(), view.end()); } } @@ -597,7 +577,6 @@ namespace etl } else { - this->initialise(); this->assign(view.begin(), view.end()); } } @@ -618,7 +597,6 @@ namespace etl } else { - this->initialise(); this->assign(first, last); } } @@ -640,7 +618,6 @@ namespace etl } else { - this->initialise(); this->assign(first, last); } } @@ -652,7 +629,6 @@ namespace etl string_ext(std::initializer_list init, value_type* buffer, size_type buffer_size) : istring(buffer, buffer_size - 1U) { - this->initialise(); this->assign(init.begin(), init.end()); } @@ -665,7 +641,6 @@ namespace etl string_ext(std::initializer_list init, value_type (&buffer)[BufferSize]) : istring(buffer, BufferSize - 1U) { - this->initialise(); this->assign(init.begin(), init.end()); } #endif diff --git a/include/etl/u16string.h b/include/etl/u16string.h index 6cc22299..eccb78be 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -89,7 +89,6 @@ namespace etl u16string(const etl::u16string& other) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(other); } @@ -100,7 +99,6 @@ namespace etl u16string(const etl::iu16string& other) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(other); } @@ -115,7 +113,6 @@ namespace etl { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->initialise(); this->assign(other, position, length); } @@ -126,7 +123,6 @@ namespace etl ETL_EXPLICIT_STRING_FROM_CHAR u16string(const value_type* text) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(text); } @@ -138,7 +134,6 @@ namespace etl u16string(const value_type* text, size_type count) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(text, text + count); } @@ -164,7 +159,6 @@ namespace etl u16string(TIterator first, TIterator last, typename etl::enable_if::value, int>::type = 0) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(first, last); } @@ -175,7 +169,6 @@ namespace etl u16string(std::initializer_list init) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(init.begin(), init.end()); } #endif @@ -187,7 +180,6 @@ namespace etl explicit u16string(const etl::u16string_view& view) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(view.begin(), view.end()); } @@ -309,7 +301,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -327,7 +318,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -347,7 +337,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -369,7 +358,6 @@ namespace etl } else { - this->initialise(); this->assign(other, position, length); } } @@ -393,7 +381,6 @@ namespace etl } else { - this->initialise(); this->assign(other, position, length); } } @@ -413,8 +400,7 @@ namespace etl } else { - this->initialise(); - this->assign(text, text + etl::strlen(text)); + this->assign(text); } } @@ -434,8 +420,7 @@ namespace etl } else { - this->initialise(); - this->assign(text, text + etl::strlen(text)); + this->assign(text); } } @@ -453,7 +438,6 @@ namespace etl } else { - this->initialise(); this->assign(literal); } } @@ -473,7 +457,6 @@ namespace etl } else { - this->initialise(); this->assign(literal); } } @@ -492,7 +475,6 @@ namespace etl } else { - this->initialise(); this->assign(text, text + count); } } @@ -513,7 +495,6 @@ namespace etl } else { - this->initialise(); this->assign(text, text + count); } } @@ -557,7 +538,6 @@ namespace etl } else { - this->initialise(); this->assign(view.begin(), view.end()); } } @@ -577,7 +557,6 @@ namespace etl } else { - this->initialise(); this->assign(view.begin(), view.end()); } } @@ -598,7 +577,6 @@ namespace etl } else { - this->initialise(); this->assign(first, last); } } @@ -620,7 +598,6 @@ namespace etl } else { - this->initialise(); this->assign(first, last); } } @@ -632,7 +609,6 @@ namespace etl u16string_ext(std::initializer_list init, value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) { - this->initialise(); this->assign(init.begin(), init.end()); } @@ -645,7 +621,6 @@ namespace etl u16string_ext(std::initializer_list init, value_type (&buffer)[BufferSize]) : iu16string(buffer, BufferSize - 1U) { - this->initialise(); this->assign(init.begin(), init.end()); } #endif diff --git a/include/etl/u32string.h b/include/etl/u32string.h index c4dc60e5..4776f91d 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -89,7 +89,6 @@ namespace etl u32string(const etl::u32string& other) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(other); } @@ -100,7 +99,6 @@ namespace etl u32string(const etl::iu32string& other) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(other); } @@ -115,7 +113,6 @@ namespace etl { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->initialise(); this->assign(other, position, length); } @@ -126,7 +123,6 @@ namespace etl ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(text); } @@ -138,7 +134,6 @@ namespace etl u32string(const value_type* text, size_type count) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(text, text + count); } @@ -164,7 +159,6 @@ namespace etl u32string(TIterator first, TIterator last, typename etl::enable_if::value, int>::type = 0) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(first, last); } @@ -175,7 +169,6 @@ namespace etl u32string(std::initializer_list init) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(init.begin(), init.end()); } #endif @@ -187,7 +180,6 @@ namespace etl explicit u32string(const etl::u32string_view& view) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(view.begin(), view.end()); } @@ -309,7 +301,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -327,7 +318,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -347,7 +337,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -369,7 +358,6 @@ namespace etl } else { - this->initialise(); this->assign(other, position, length); } } @@ -393,7 +381,6 @@ namespace etl } else { - this->initialise(); this->assign(other, position, length); } } @@ -413,8 +400,7 @@ namespace etl } else { - this->initialise(); - this->assign(text, text + etl::strlen(text)); + this->assign(text); } } @@ -434,8 +420,7 @@ namespace etl } else { - this->initialise(); - this->assign(text, text + etl::strlen(text)); + this->assign(text); } } @@ -453,7 +438,6 @@ namespace etl } else { - this->initialise(); this->assign(literal); } } @@ -473,7 +457,6 @@ namespace etl } else { - this->initialise(); this->assign(literal); } } @@ -492,7 +475,6 @@ namespace etl } else { - this->initialise(); this->assign(text, text + count); } } @@ -513,7 +495,6 @@ namespace etl } else { - this->initialise(); this->assign(text, text + count); } } @@ -557,7 +538,6 @@ namespace etl } else { - this->initialise(); this->assign(view.begin(), view.end()); } } @@ -577,7 +557,6 @@ namespace etl } else { - this->initialise(); this->assign(view.begin(), view.end()); } } @@ -598,7 +577,6 @@ namespace etl } else { - this->initialise(); this->assign(first, last); } } @@ -620,7 +598,6 @@ namespace etl } else { - this->initialise(); this->assign(first, last); } } @@ -632,7 +609,6 @@ namespace etl u32string_ext(std::initializer_list init, value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) { - this->initialise(); this->assign(init.begin(), init.end()); } @@ -645,7 +621,6 @@ namespace etl u32string_ext(std::initializer_list init, value_type (&buffer)[BufferSize]) : iu32string(buffer, BufferSize - 1U) { - this->initialise(); this->assign(init.begin(), init.end()); } #endif diff --git a/include/etl/u8string.h b/include/etl/u8string.h index 26199773..7f027808 100644 --- a/include/etl/u8string.h +++ b/include/etl/u8string.h @@ -92,7 +92,6 @@ namespace etl u8string(const etl::u8string& other) : iu8string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(other); } @@ -103,7 +102,6 @@ namespace etl u8string(const etl::iu8string& other) : iu8string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(other); } @@ -118,7 +116,6 @@ namespace etl { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->initialise(); this->assign(other, position, length); } @@ -129,7 +126,6 @@ namespace etl ETL_EXPLICIT_STRING_FROM_CHAR u8string(const value_type* text) : iu8string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(text); } @@ -141,7 +137,6 @@ namespace etl u8string(const value_type* text, size_t count) : iu8string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(text, text + count); } @@ -167,7 +162,6 @@ namespace etl u8string(TIterator first, TIterator last, typename etl::enable_if::value, int>::type = 0) : iu8string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(first, last); } @@ -178,7 +172,6 @@ namespace etl u8string(std::initializer_list init) : iu8string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(init.begin(), init.end()); } #endif @@ -190,7 +183,6 @@ namespace etl explicit u8string(const etl::u8string_view& view) : iu8string(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(view.begin(), view.end()); } @@ -329,7 +321,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -347,7 +338,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -367,7 +357,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -389,7 +378,6 @@ namespace etl } else { - this->initialise(); this->assign(other, position, length); } } @@ -413,7 +401,6 @@ namespace etl } else { - this->initialise(); this->assign(other, position, length); } } @@ -433,8 +420,7 @@ namespace etl } else { - this->initialise(); - this->assign(text, text + etl::strlen(text)); + this->assign(text); } } @@ -454,8 +440,7 @@ namespace etl } else { - this->initialise(); - this->assign(text, text + etl::strlen(text)); + this->assign(text); } } @@ -473,7 +458,6 @@ namespace etl } else { - this->initialise(); this->assign(literal); } } @@ -493,7 +477,6 @@ namespace etl } else { - this->initialise(); this->assign(literal); } } @@ -512,7 +495,6 @@ namespace etl } else { - this->initialise(); this->assign(text, text + count); } } @@ -533,7 +515,6 @@ namespace etl } else { - this->initialise(); this->assign(text, text + count); } } @@ -577,7 +558,6 @@ namespace etl } else { - this->initialise(); this->assign(view.begin(), view.end()); } } @@ -597,7 +577,6 @@ namespace etl } else { - this->initialise(); this->assign(view.begin(), view.end()); } } @@ -618,7 +597,6 @@ namespace etl } else { - this->initialise(); this->assign(first, last); } } @@ -640,7 +618,6 @@ namespace etl } else { - this->initialise(); this->assign(first, last); } } @@ -652,7 +629,6 @@ namespace etl u8string_ext(std::initializer_list init, value_type* buffer, size_type buffer_size) : iu8string(buffer, buffer_size - 1U) { - this->initialise(); this->assign(init.begin(), init.end()); } @@ -665,7 +641,6 @@ namespace etl u8string_ext(std::initializer_list init, value_type (&buffer)[BufferSize]) : iu8string(buffer, BufferSize - 1U) { - this->initialise(); this->assign(init.begin(), init.end()); } #endif diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 91405be7..f3f2256b 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -89,7 +89,6 @@ namespace etl wstring(const etl::wstring& other) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(other); } @@ -100,7 +99,6 @@ namespace etl wstring(const etl::iwstring& other) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(other); } @@ -115,7 +113,6 @@ namespace etl { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); - this->initialise(); this->assign(other, position, length); } @@ -126,7 +123,6 @@ namespace etl ETL_EXPLICIT_STRING_FROM_CHAR wstring(const value_type* text) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(text); } @@ -138,7 +134,6 @@ namespace etl wstring(const value_type* text, size_type count) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(text, text + count); } @@ -164,7 +159,6 @@ namespace etl wstring(TIterator first, TIterator last, typename etl::enable_if::value, int>::type = 0) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(first, last); } @@ -175,7 +169,6 @@ namespace etl wstring(std::initializer_list init) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(init.begin(), init.end()); } #endif @@ -187,7 +180,6 @@ namespace etl explicit wstring(const etl::wstring_view& view) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { - this->initialise(); this->assign(view.begin(), view.end()); } @@ -309,7 +301,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -327,7 +318,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -347,7 +337,6 @@ namespace etl } else { - this->initialise(); this->assign(other); } } @@ -369,7 +358,6 @@ namespace etl } else { - this->initialise(); this->assign(other, position, length); } } @@ -393,7 +381,6 @@ namespace etl } else { - this->initialise(); this->assign(other, position, length); } } @@ -413,8 +400,7 @@ namespace etl } else { - this->initialise(); - this->assign(text, text + etl::strlen(text)); + this->assign(text); } } @@ -434,8 +420,7 @@ namespace etl } else { - this->initialise(); - this->assign(text, text + etl::strlen(text)); + this->assign(text); } } @@ -453,7 +438,6 @@ namespace etl } else { - this->initialise(); this->assign(literal); } } @@ -473,7 +457,6 @@ namespace etl } else { - this->initialise(); this->assign(literal); } } @@ -492,7 +475,6 @@ namespace etl } else { - this->initialise(); this->assign(text, text + count); } } @@ -513,7 +495,6 @@ namespace etl } else { - this->initialise(); this->assign(text, text + count); } } @@ -557,7 +538,6 @@ namespace etl } else { - this->initialise(); this->assign(view.begin(), view.end()); } } @@ -577,7 +557,6 @@ namespace etl } else { - this->initialise(); this->assign(view.begin(), view.end()); } } @@ -598,7 +577,6 @@ namespace etl } else { - this->initialise(); this->assign(first, last); } } @@ -620,7 +598,6 @@ namespace etl } else { - this->initialise(); this->assign(first, last); } } @@ -632,7 +609,6 @@ namespace etl wstring_ext(std::initializer_list init, value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) { - this->initialise(); this->assign(init.begin(), init.end()); } @@ -645,7 +621,6 @@ namespace etl wstring_ext(std::initializer_list init, value_type (&buffer)[BufferSize]) : iwstring(buffer, BufferSize - 1U) { - this->initialise(); this->assign(init.begin(), init.end()); } #endif