diff --git a/include/etl/basic_string.h b/include/etl/basic_string.h index efadab47..805222d5 100644 --- a/include/etl/basic_string.h +++ b/include/etl/basic_string.h @@ -50,6 +50,9 @@ SOFTWARE. #include "integral_limits.h" #include "exception.h" #include "memory.h" +#include "exception.h" +#include "binary.h" +#include "flags.h" #undef ETL_FILE #define ETL_FILE "27" @@ -149,10 +152,7 @@ namespace etl typedef size_t size_type; - enum - { - npos = etl::integral_limits::max - }; + static const size_type npos = etl::integral_limits::max; //************************************************************************* /// Gets the current size of the string. @@ -212,18 +212,30 @@ namespace etl /// Returns the remaining capacity. ///\return The remaining capacity. //************************************************************************* - size_t available() const + size_type available() const { return max_size() - size(); } +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + //************************************************************************* + /// Returns whether the string was truncated by the last operation. + /// Deprecated. Use is_truncated() + ///\return Whether the string was truncated by the last operation. + //************************************************************************* + ETL_DEPRECATED + bool truncated() const + { + return flags.test(); + } + //************************************************************************* /// Returns whether the string was truncated by the last operation. ///\return Whether the string was truncated by the last operation. //************************************************************************* - size_t truncated() const + bool is_truncated() const { - return is_truncated; + return flags.test(); } //************************************************************************* @@ -231,15 +243,17 @@ namespace etl //************************************************************************* void clear_truncated() { - is_truncated = false; + flags.set(); } +#endif +#if ETL_STRING_CLEAR_AFTER_USE_ENABLED //************************************************************************* /// Sets the 'secure' flag to the requested state. //************************************************************************* void set_secure() { - clear_afer_use = true; + flags.set(); } //************************************************************************* @@ -247,22 +261,31 @@ namespace etl //************************************************************************* bool is_secure() const { - return clear_afer_use; + return flags.test(); } +#endif protected: //************************************************************************* /// Constructor. //************************************************************************* - string_base(size_t max_size_) - : is_truncated(false) - , clear_afer_use(false) - , current_size(0) + string_base(size_type max_size_) + : current_size(0) , CAPACITY(max_size_) { } +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + //************************************************************************* + /// Sets the 'truncated' flag. + //************************************************************************* + void set_truncated(bool status) + { + flags.set(status); + } +#endif + //************************************************************************* /// Destructor. //************************************************************************* @@ -270,10 +293,15 @@ namespace etl { } - bool is_truncated; ///< Set to true if the operation truncated the string. - bool clear_afer_use; ///< Set to true if the string must be cleared after use. + static const uint_least8_t IS_TRUNCATED = etl::bit<0>::value; + static const uint_least8_t CLEAR_AFTER_USE = etl::bit<1>::value; + size_type current_size; ///< The current number of elements in the string. const size_type CAPACITY; ///< The maximum number of elements in the string. + +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED || ETL_STRING_CLEAR_AFTER_USE_ENABLED + etl::flags flags; +#endif }; //*************************************************************************** @@ -297,7 +325,6 @@ namespace etl typedef const T* const_iterator; typedef ETL_OR_STD::reverse_iterator reverse_iterator; typedef ETL_OR_STD::reverse_iterator const_reverse_iterator; - typedef size_t size_type; typedef typename etl::iterator_traits::difference_type difference_type; @@ -414,7 +441,7 @@ namespace etl /// If asserts or exceptions are enabled and the new size is larger than the ///\param new_size The new size. //********************************************************************* - void resize(size_t new_size) + void resize(size_type new_size) { resize(new_size, 0); } @@ -424,14 +451,16 @@ namespace etl ///\param new_size The new size. ///\param value The value to fill new elements with. Default = default constructed value. //********************************************************************* - void resize(size_t new_size, T value) + void resize(size_type new_size, T value) { if (new_size > CAPACITY) { - is_truncated = true; +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif #endif } @@ -453,7 +482,7 @@ namespace etl ///\param i The index. ///\return A reference to the value at index 'i' //********************************************************************* - reference operator [](size_t i) + reference operator [](size_type i) { return p_buffer[i]; } @@ -463,7 +492,7 @@ namespace etl ///\param i The index. ///\return A const reference to the value at index 'i' //********************************************************************* - const_reference operator [](size_t i) const + const_reference operator [](size_type i) const { return p_buffer[i]; } @@ -474,7 +503,7 @@ namespace etl ///\param i The index. ///\return A reference to the value at index 'i' //********************************************************************* - reference at(size_t i) + reference at(size_type i) { ETL_ASSERT(i < size(), ETL_ERROR(string_out_of_bounds)); return p_buffer[i]; @@ -486,7 +515,7 @@ namespace etl ///\param i The index. ///\return A const reference to the value at index 'i' //********************************************************************* - const_reference at(size_t i) const + const_reference at(size_type i) const { ETL_ASSERT(i < size(), ETL_ERROR(string_out_of_bounds)); return p_buffer[i]; @@ -555,14 +584,16 @@ namespace etl { assign(other.begin(), other.end()); - if (other.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (other.is_truncated()) { - is_truncated = true; + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif } +#endif cleanup(); } @@ -574,7 +605,7 @@ namespace etl ///\param subposition The position to start from. ///\param sublength The length to copy. //********************************************************************* - void assign(const etl::ibasic_string& other, size_t subposition, size_t sublength) + void assign(const etl::ibasic_string& other, size_type subposition, size_type sublength) { if (sublength == npos) { @@ -600,10 +631,12 @@ namespace etl p_buffer[current_size++] = *other++; } - is_truncated = (*other != 0); +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(*other != 0); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ASSERT(is_truncated == false, ETL_ERROR(string_truncation)) + ETL_ASSERT(flags.test() == false, ETL_ERROR(string_truncation)) +#endif #endif p_buffer[current_size] = 0; @@ -615,14 +648,16 @@ namespace etl ///\param other The other string. ///\param length The length to copy. //********************************************************************* - void assign(const_pointer other, size_t length_) + void assign(const_pointer other, size_type length_) { initialise(); - is_truncated = (length_ > CAPACITY); +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(length_ > CAPACITY); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ASSERT(is_truncated == false, ETL_ERROR(string_truncation)) + ETL_ASSERT(flags.test() == false, ETL_ERROR(string_truncation)) +#endif #endif length_ = etl::min(length_, CAPACITY); @@ -657,10 +692,12 @@ namespace etl p_buffer[current_size] = 0; - is_truncated = (first != last); +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(first != last); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ASSERT(is_truncated == false, ETL_ERROR(string_truncation)) + ETL_ASSERT(flags.test() == false, ETL_ERROR(string_truncation)) +#endif #endif } @@ -670,14 +707,16 @@ namespace etl ///\param n The number of elements to add. ///\param value The value to insert for each element. //********************************************************************* - void assign(size_t n, T value) + void assign(size_type n, T value) { initialise(); - is_truncated = (n > CAPACITY); +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(n > CAPACITY); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) - ETL_ASSERT(is_truncated == false, ETL_ERROR(string_truncation)) + ETL_ASSERT(flags.test() == false, ETL_ERROR(string_truncation)) +#endif #endif n = etl::min(n, CAPACITY); @@ -709,10 +748,12 @@ namespace etl } else { - is_truncated = true; +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif #endif } } @@ -737,14 +778,16 @@ namespace etl { insert(end(), str.begin(), str.end()); - if (str.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (str.is_truncated()) { - is_truncated = true; + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif } +#endif return *this; } @@ -755,7 +798,7 @@ namespace etl ///\param subposition The position in str. ///\param sublength The number of characters. //********************************************************************* - ibasic_string& append(const ibasic_string& str, size_t subposition, size_t sublength = npos) + ibasic_string& append(const ibasic_string& str, size_type subposition, size_type sublength = npos) { ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); @@ -779,7 +822,7 @@ namespace etl ///\param str The string to append. ///\param n The number of characters. //********************************************************************* - ibasic_string& append(const T* str, size_t n) + ibasic_string& append(const T* str, size_type n) { insert(size(), str, n); return *this; @@ -790,7 +833,7 @@ namespace etl ///\param n The number of characters. ///\param c The character. //********************************************************************* - ibasic_string& append(size_t n, T c) + ibasic_string& append(size_type n, T c) { insert(size(), n, c); return *this; @@ -845,10 +888,12 @@ namespace etl *insert_position = value; } - is_truncated = true; +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif #endif } @@ -863,7 +908,7 @@ namespace etl ///\param n The number of elements to add. ///\param value The value to insert. //********************************************************************* - void insert(const_iterator position, size_t n, T value) + void insert(const_iterator position, size_type n, T value) { if (n == 0) { @@ -872,15 +917,17 @@ namespace etl // Quick hack, as iterators are pointers. iterator insert_position = const_cast(position); - const size_t start = etl::distance(cbegin(), position); + const size_type start = etl::distance(cbegin(), position); // No effect. if (start >= CAPACITY) { - is_truncated = true; +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif #endif return; } @@ -890,10 +937,12 @@ namespace etl { if ((current_size + n) > CAPACITY) { - is_truncated = true; +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif #endif } @@ -903,20 +952,23 @@ namespace etl else { // Lets do some shifting. - const size_t shift_amount = n; - const size_t to_position = start + shift_amount; - const size_t remaining_characters = current_size - start; - const size_t max_shift_characters = CAPACITY - start - shift_amount; - const size_t characters_to_shift = etl::min(max_shift_characters, remaining_characters); + const size_type shift_amount = n; + const size_type to_position = start + shift_amount; + const size_type remaining_characters = current_size - start; + const size_type max_shift_characters = CAPACITY - start - shift_amount; + const size_type characters_to_shift = etl::min(max_shift_characters, remaining_characters); // Will the string truncate? if ((start + shift_amount + remaining_characters) > CAPACITY) { current_size = CAPACITY; - is_truncated = true; + +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif #endif } else @@ -946,16 +998,18 @@ namespace etl return; } - const size_t start = etl::distance(begin(), position); - const size_t n = etl::distance(first, last); + const size_type start = etl::distance(begin(), position); + const size_type n = etl::distance(first, last); // No effect. if (start >= CAPACITY) { - is_truncated = true; +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif #endif return; } @@ -965,10 +1019,12 @@ namespace etl { if (((current_size + n) > CAPACITY)) { - is_truncated = true; +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif #endif } @@ -982,20 +1038,23 @@ namespace etl else { // Lets do some shifting. - const size_t shift_amount = n; - const size_t to_position = start + shift_amount; - const size_t remaining_characters = current_size - start; - const size_t max_shift_characters = CAPACITY - start - shift_amount; - const size_t characters_to_shift = etl::min(max_shift_characters, remaining_characters); + const size_type shift_amount = n; + const size_type to_position = start + shift_amount; + const size_type remaining_characters = current_size - start; + const size_type max_shift_characters = CAPACITY - start - shift_amount; + const size_type characters_to_shift = etl::min(max_shift_characters, remaining_characters); // Will the string truncate? if ((start + shift_amount + remaining_characters) > CAPACITY) { current_size = CAPACITY; - is_truncated = true; + +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif #endif } else @@ -1019,20 +1078,22 @@ namespace etl ///\param position The position to insert before. ///\param str The string to insert. //********************************************************************* - etl::ibasic_string& insert(size_t position, const etl::ibasic_string& str) + etl::ibasic_string& insert(size_type position, const etl::ibasic_string& str) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); insert(begin() + position, str.cbegin(), str.cend()); - if (str.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (str.is_truncated()) { - is_truncated = true; + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif } +#endif return *this; } @@ -1044,7 +1105,7 @@ namespace etl ///\param subposition The subposition to start from. ///\param sublength The number of characters to insert. //********************************************************************* - etl::ibasic_string& insert(size_t position, const etl::ibasic_string& str, size_t subposition, size_t sublength) + 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(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); @@ -1056,14 +1117,16 @@ namespace etl insert(begin() + position, str.cbegin() + subposition, str.cbegin() + subposition + sublength); - if (str.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (str.is_truncated()) { - is_truncated = true; + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif } +#endif return *this; } @@ -1073,7 +1136,7 @@ namespace etl ///\param position The position to insert before. ///\param s The string to insert. //********************************************************************* - etl::ibasic_string& insert(size_t position, const_pointer s) + etl::ibasic_string& insert(size_type position, const_pointer s) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1087,7 +1150,7 @@ namespace etl ///\param s The string to insert. ///\param n The number of characters to insert. //********************************************************************* - etl::ibasic_string& insert(size_t position, const_pointer s, size_t n) + etl::ibasic_string& insert(size_type position, const_pointer s, size_type n) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1101,7 +1164,7 @@ namespace etl ///\param n The number of characters to insert. ///\param c The character to insert. //********************************************************************* - etl::ibasic_string& insert(size_t position, size_t n, value_type c) + etl::ibasic_string& insert(size_type position, size_type n, value_type c) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1115,7 +1178,7 @@ namespace etl ///\param length Number of characters. ///\return A refernce to this string. //********************************************************************* - etl::ibasic_string& erase(size_t position, size_t length_ = npos) + etl::ibasic_string& erase(size_type position, size_type length_ = npos) { // Limit the length. length_ = etl::min(length_, size() - position); @@ -1154,7 +1217,7 @@ namespace etl } etl::copy(last, end(), first); - size_t n_delete = etl::distance(first, last); + size_type n_delete = etl::distance(first, last); current_size -= n_delete; p_buffer[current_size] = 0; @@ -1177,20 +1240,22 @@ namespace etl ///\param len The number of characters to copy. ///\param pos The position to start copying from. //********************************************************************* - size_t copy(pointer s, size_t len, size_t pos = 0) + size_type copy(pointer s, size_type len, size_type pos = 0) { if ((pos + len > size())) { - is_truncated = true; +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); +#endif #endif } - size_t endpos = etl::min(pos + len, size()); + size_type endpos = etl::min(pos + len, size()); - for (size_t i = pos; i < endpos; ++i) + for (size_type i = pos; i < endpos; ++i) { *s++ = p_buffer[i]; } @@ -1203,7 +1268,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_t find(const ibasic_string& str, size_t pos = 0) const + size_type find(const ibasic_string& str, size_type pos = 0) const { if ((pos + str.size()) > size()) { @@ -1227,7 +1292,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - size_t find(const_pointer s, size_t pos = 0) const + size_type find(const_pointer s, size_type pos = 0) const { #if defined(ETL_DEBUG) if ((pos + etl::strlen(s)) > size()) @@ -1254,7 +1319,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - size_t find(const_pointer s, size_t pos, size_t n) const + size_type find(const_pointer s, size_type pos, size_type n) const { #if defined(ETL_DEBUG) if ((pos + etl::strlen(s) - n) > size()) @@ -1280,7 +1345,7 @@ namespace etl ///\param c The character to find. ///\param position The position to start searching from. //********************************************************************* - size_t find(T c, size_t position = 0) const + size_type find(T c, size_type position = 0) const { const_iterator i = etl::find(begin() + position, end(), c); @@ -1299,7 +1364,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_t rfind(const ibasic_string& str, size_t position = npos) const + size_type rfind(const ibasic_string& str, size_type position = npos) const { if ((str.size()) > size()) { @@ -1330,9 +1395,9 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_t rfind(const_pointer s, size_t position = npos) const + size_type rfind(const_pointer s, size_type position = npos) const { - size_t len = etl::strlen(s); + size_type len = etl::strlen(s); if (len > size()) { @@ -1366,7 +1431,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_t rfind(const_pointer s, size_t position, size_t length_) const + size_type rfind(const_pointer s, size_type position, size_type length_) const { if (length_ > size()) { @@ -1400,7 +1465,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - size_t rfind(T c, size_t position = npos) const + size_type rfind(T c, size_type position = npos) const { if (position >= size()) { @@ -1427,7 +1492,7 @@ namespace etl ///\param length The number of characters to replace. ///\param str The string to replace it with. //********************************************************************* - ibasic_string& replace(size_t position, size_t length_, const ibasic_string& str) + ibasic_string& replace(size_type position, size_type length_, const ibasic_string& str) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1461,14 +1526,16 @@ namespace etl // Insert the new stuff. insert(first_, str.begin(), str.end()); - if (str.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (str.is_truncated()) { - is_truncated = true; + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif } +#endif return *this; } @@ -1476,7 +1543,7 @@ namespace etl //********************************************************************* /// Replace characters from 'position' of 'length' with 'str' from 'subpsotion' of 'sublength'. //********************************************************************* - ibasic_string& replace(size_t position, size_t length_, const ibasic_string& str, size_t subposition, size_t sublength) + ibasic_string& replace(size_type position, size_type length_, const ibasic_string& str, size_type subposition, size_type sublength) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); @@ -1491,14 +1558,16 @@ namespace etl // Insert the new stuff. insert(position, str, subposition, sublength); - if (str.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (str.is_truncated()) { - is_truncated = true; + set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif } +#endif return *this; } @@ -1506,7 +1575,7 @@ namespace etl //********************************************************************* /// Replace characters from 'position' of 'length' with pointed to string. //********************************************************************* - ibasic_string& replace(size_t position, size_t length_, const_pointer s) + ibasic_string& replace(size_type position, size_type length_, const_pointer s) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1543,7 +1612,7 @@ namespace etl //********************************************************************* /// Replace characters from 'position' of 'length' with 'n' characters from pointed to string. //********************************************************************* - ibasic_string& replace(size_t position, size_t length_, const_pointer s, size_t n) + ibasic_string& replace(size_type position, size_type length_, const_pointer s, size_type n) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1562,7 +1631,7 @@ namespace etl //********************************************************************* /// Replace characters from 'first' to 'last' with 'n' characters from pointed to string. //********************************************************************* - ibasic_string& replace(const_iterator first, const_iterator last, const_pointer s, size_t n) + ibasic_string& replace(const_iterator first, const_iterator last, const_pointer s, size_type n) { // Quick hack, as iterators are pointers. iterator first_ = const_cast(first); @@ -1580,7 +1649,7 @@ namespace etl //********************************************************************* /// Replace characters from 'position' of 'length' with 'n' copies of 'c'. //********************************************************************* - ibasic_string& replace(size_t position, size_t length_, size_t n, value_type c) + ibasic_string& replace(size_type position, size_type length_, size_type n, value_type c) { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1599,7 +1668,7 @@ namespace etl //********************************************************************* /// Replace characters from 'first' of 'last' with 'n' copies of 'c'. //********************************************************************* - ibasic_string& replace(const_iterator first, const_iterator last, size_t n, value_type c) + ibasic_string& replace(const_iterator first, const_iterator last, size_type n, value_type c) { // Quick hack, as iterators are pointers. iterator first_ = const_cast(first); @@ -1647,7 +1716,7 @@ namespace etl //************************************************************************* /// Compare position / length with string. //************************************************************************* - int compare(size_t position, size_t length_, const ibasic_string& str) const + int compare(size_type position, size_type length_, const ibasic_string& str) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); @@ -1663,7 +1732,7 @@ namespace etl //************************************************************************* /// Compare position / length with string / subposition / sublength. //************************************************************************* - int compare(size_t position, size_t length_, const ibasic_string& str, size_t subposition, size_t sublength) const + int compare(size_type position, size_type length_, const ibasic_string& str, size_type subposition, size_type sublength) const { ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds)); ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds)); @@ -1692,7 +1761,7 @@ namespace etl //************************************************************************* /// Compare position / length with C string. //************************************************************************* - int compare(size_t position, size_t length_, const_pointer s) const + int compare(size_type position, size_type length_, const_pointer s) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -1703,7 +1772,7 @@ namespace etl //************************************************************************* /// Compare position / length with C string / n. //************************************************************************* - int compare(size_t position, size_t length_, const_pointer s, size_t n) const + int compare(size_type position, size_type length_, const_pointer s, size_type n) const { return compare(p_buffer + position, p_buffer + position + length_, @@ -1716,7 +1785,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_t find_first_of(const ibasic_string& str, size_t position = 0) const + size_type find_first_of(const ibasic_string& str, size_type position = 0) const { return find_first_of(str.c_str(), position, str.size()); } @@ -1726,7 +1795,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - size_t find_first_of(const_pointer s, size_t position = 0) const + size_type find_first_of(const_pointer s, size_type position = 0) const { return find_first_of(s, position, etl::strlen(s)); } @@ -1737,13 +1806,13 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - size_t find_first_of(const_pointer s, size_t position, size_t n) const + size_type find_first_of(const_pointer s, size_type position, size_type n) const { if (position < size()) { - for (size_t i = position; i < size(); ++i) + for (size_type i = position; i < size(); ++i) { - for (size_t j = 0; j < n; ++j) + for (size_type j = 0; j < n; ++j) { if (p_buffer[i] == s[j]) { @@ -1761,11 +1830,11 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - size_t find_first_of(value_type c, size_t position = 0) const + size_type find_first_of(value_type c, size_type position = 0) const { if (position < size()) { - for (size_t i = position; i < size(); ++i) + for (size_type i = position; i < size(); ++i) { if (p_buffer[i] == c) { @@ -1782,7 +1851,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_t find_last_of(const ibasic_string& str, size_t position = npos) const + size_type find_last_of(const ibasic_string& str, size_type position = npos) const { return find_last_of(str.c_str(), position, str.size()); } @@ -1792,7 +1861,7 @@ namespace etl ///\param s Pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - size_t find_last_of(const_pointer s, size_t position = npos) const + size_type find_last_of(const_pointer s, size_type position = npos) const { return find_last_of(s, position, etl::strlen(s)); } @@ -1803,7 +1872,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - size_t find_last_of(const_pointer s, size_t position, size_t n) const + size_type find_last_of(const_pointer s, size_type position, size_type n) const { if (empty()) { @@ -1816,7 +1885,7 @@ namespace etl while (it != rend()) { - for (size_t j = 0; j < n; ++j) + for (size_type j = 0; j < n; ++j) { if (p_buffer[position] == s[j]) { @@ -1836,7 +1905,7 @@ namespace etl ///\param c The character to find ///\param pos The position to start searching from. //********************************************************************* - size_t find_last_of(value_type c, size_t position = npos) const + size_type find_last_of(value_type c, size_type position = npos) const { if (empty()) { @@ -1866,7 +1935,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_t find_first_not_of(const ibasic_string& str, size_t position = 0) const + size_type find_first_not_of(const ibasic_string& str, size_type position = 0) const { return find_first_not_of(str.c_str(), position, str.size()); } @@ -1876,7 +1945,7 @@ namespace etl ///\param s Pointer to the content to not find ///\param pos The position to start searching from. //********************************************************************* - size_t find_first_not_of(const_pointer s, size_t position = 0) const + size_type find_first_not_of(const_pointer s, size_type position = 0) const { return find_first_not_of(s, position, etl::strlen(s)); } @@ -1887,15 +1956,15 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to search for. //********************************************************************* - size_t find_first_not_of(const_pointer s, size_t position, size_t n) const + size_type find_first_not_of(const_pointer s, size_type position, size_type n) const { if (position < size()) { - for (size_t i = position; i < size(); ++i) + for (size_type i = position; i < size(); ++i) { bool found = false; - for (size_t j = 0; j < n; ++j) + for (size_type j = 0; j < n; ++j) { if (p_buffer[i] == s[j]) { @@ -1918,11 +1987,11 @@ namespace etl ///\param c The character to not find ///\param pos The position to start searching from. //********************************************************************* - size_t find_first_not_of(value_type c, size_t position = 0) const + size_type find_first_not_of(value_type c, size_type position = 0) const { if (position < size()) { - for (size_t i = position; i < size(); ++i) + for (size_type i = position; i < size(); ++i) { if (p_buffer[i] != c) { @@ -1939,7 +2008,7 @@ namespace etl ///\param str The content to find ///\param pos The position to start searching from. //********************************************************************* - size_t find_last_not_of(const ibasic_string& str, size_t position = npos) const + size_type find_last_not_of(const ibasic_string& str, size_type position = npos) const { return find_last_not_of(str.c_str(), position, str.size()); } @@ -1949,7 +2018,7 @@ namespace etl ///\param s The pointer to the content to find ///\param pos The position to start searching from. //********************************************************************* - size_t find_last_not_of(const_pointer s, size_t position = npos) const + size_type find_last_not_of(const_pointer s, size_type position = npos) const { return find_last_not_of(s, position, etl::strlen(s)); } @@ -1960,7 +2029,7 @@ namespace etl ///\param pos The position to start searching from. ///\param n The number of characters to use. //********************************************************************* - size_t find_last_not_of(const_pointer s, size_t position, size_t n) const + size_type find_last_not_of(const_pointer s, size_type position, size_type n) const { if (empty()) { @@ -1975,7 +2044,7 @@ namespace etl { bool found = false; - for (size_t j = 0; j < n; ++j) + for (size_type j = 0; j < n; ++j) { if (p_buffer[position] == s[j]) { @@ -1998,7 +2067,7 @@ namespace etl //********************************************************************* // //********************************************************************* - size_t find_last_not_of(value_type c, size_t position = npos) const + size_type find_last_not_of(value_type c, size_type position = npos) const { if (empty()) { @@ -2071,7 +2140,7 @@ namespace etl //************************************************************************* ibasic_string& operator += (T rhs) { - append(size_t(1), rhs); + append(size_type(1), rhs); return *this; } @@ -2088,7 +2157,7 @@ namespace etl //********************************************************************* /// Constructor. //********************************************************************* - ibasic_string(T* p_buffer_, size_t MAX_SIZE_) + ibasic_string(T* p_buffer_, size_type MAX_SIZE_) : string_base(MAX_SIZE_), p_buffer(p_buffer_) { @@ -2102,7 +2171,9 @@ namespace etl current_size = 0; cleanup(); p_buffer[0] = 0; - is_truncated = false; +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + set_truncated(false); +#endif } //************************************************************************* @@ -2160,10 +2231,12 @@ namespace etl //************************************************************************* void cleanup() { +#if ETL_STRING_CLEAR_AFTER_USE_ENABLED if (is_secure()) { etl::memory_clear_range(&p_buffer[current_size], &p_buffer[CAPACITY]); } +#endif } //************************************************************************* @@ -2187,10 +2260,12 @@ namespace etl #endif ~ibasic_string() { +#if ETL_STRING_CLEAR_AFTER_USE_ENABLED if (is_secure()) { initialise(); } +#endif } }; diff --git a/include/etl/flags.h b/include/etl/flags.h new file mode 100644 index 00000000..6a83a298 --- /dev/null +++ b/include/etl/flags.h @@ -0,0 +1,417 @@ +///\file + +/****************************************************************************** +The MIT License(MIT) + +Embedded Template Library. +https://github.com/ETLCPP/etl +https://www.etlcpp.com + +Copyright(c) 2020 jwellbelove + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files(the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and / or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions : + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +******************************************************************************/ + +#ifndef ETL_FLAGS_INCLUDED +#define ETL_FLAGS_INCLUDED + +#include +#include +#include + +#include "platform.h" +#include "type_traits.h" +#include "integral_limits.h" +#include "static_assert.h" + +#if ETL_CPP11_SUPPORTED && ETL_NOT_USING_STLPORT && ETL_USING_STL + #include +#endif + +namespace etl +{ + //************************************************************************* + /// flags + /// Flags based around an integral value. + //************************************************************************* + template ::max> + class flags + { + public: + + ETL_STATIC_ASSERT(etl::is_integral::value && etl::is_unsigned::value, "Unsigned integral values only"); + + typedef T value_type; + + static ETL_CONSTANT value_type ALL_SET = etl::integral_limits::max & MASK; + static ETL_CONSTANT value_type ALL_CLEAR = 0; + + static const size_t NBITS = etl::integral_limits::bits; + + //************************************************************************* + /// Constructor + //************************************************************************* + flags() ETL_NOEXCEPT + : data(value_type(0)) + { + } + + flags(value_type initial) ETL_NOEXCEPT + : data(initial & MASK) + { + } + + flags(const flags& initial) ETL_NOEXCEPT + : data(initial.value()) + { + } + + //************************************************************************* + /// Tests bits. + //************************************************************************* + template + bool test() const ETL_NOEXCEPT + { + return (data & position) != value_type(0); + } + + //******************************************* + bool test(value_type position) const + { + return (data & position) != value_type(0); + } + + //************************************************************************* + /// Set the bits. + //************************************************************************* + template + flags& set() ETL_NOEXCEPT + { + if ETL_IF_CONSTEXPR(value) + { + data |= position; + } + else + { + data &= ~position; + } + + data &= MASK; + + return *this; + } + + //******************************************* + template + flags& set(bool value) ETL_NOEXCEPT + { + if (value) + { + data |= position; + } + else + { + data &= ~position; + } + + data &= MASK; + + return *this; + } + + //******************************************* + template + flags& set() ETL_NOEXCEPT + { + data |= position; + data &= MASK; + + return *this; + } + + //******************************************* + flags& set(value_type position) ETL_NOEXCEPT + { + data |= position; + data &= MASK; + + return *this; + } + + //******************************************* + flags& set(value_type position, bool value) ETL_NOEXCEPT + { + if (value) + { + data |= position; + } + else + { + data &= ~position; + } + + data &= MASK; + + return *this; + } + + //************************************************************************* + /// Clear all of the flags. + //************************************************************************* + flags& clear() ETL_NOEXCEPT + { + data = ALL_CLEAR; + + return *this; + } + + //************************************************************************* + /// Reset the bit at the position. + //************************************************************************* + template + flags& reset() ETL_NOEXCEPT + { + data &= ~position; + + return *this; + } + + //******************************************* + flags& reset(value_type position) ETL_NOEXCEPT + { + data &= ~position; + + return *this; + } + + //************************************************************************* + /// Flip bits. + //************************************************************************* + flags& flip() ETL_NOEXCEPT + { + data = ~data; + data &= MASK; + + return *this; + } + + //******************************************* + template + flags& flip() ETL_NOEXCEPT + { + data ^= position; + data &= MASK; + + return *this; + } + + //******************************************* + flags& flip(value_type position) ETL_NOEXCEPT + { + data ^= position; + data &= MASK; + + return *this; + } + + //************************************************************************* + // Are all the bits sets? + //************************************************************************* + bool all() const ETL_NOEXCEPT + { + return data == MASK; + } + + //******************************************* + template + bool all_of() const ETL_NOEXCEPT + { + return (data & (position & MASK)) == (position & MASK); + } + + //******************************************* + bool all_of(value_type position) const ETL_NOEXCEPT + { + position &= MASK; + return (data & position) == position; + } + + //************************************************************************* + /// Are none of the bits set? + //************************************************************************* + bool none() const ETL_NOEXCEPT + { + return (data & MASK) == ALL_CLEAR; + } + + //******************************************* + template + bool none_of() const ETL_NOEXCEPT + { + return !any_of(position); + } + + //******************************************* + bool none_of(value_type position) const ETL_NOEXCEPT + { + return !any_of(position); + } + + //************************************************************************* + /// Are any of the bits set? + //************************************************************************* + bool any() const ETL_NOEXCEPT + { + return (data & MASK) != value_type(0); + } + + //******************************************* + template + bool any_of() const ETL_NOEXCEPT + { + return (data & (position & MASK)) != value_type(0); + } + + //******************************************* + bool any_of(value_type position) const + { + return (data & (position & MASK)) != value_type(0); + } + + //************************************************************************* + /// Return the value of the flags. + //************************************************************************* + value_type value() const ETL_NOEXCEPT + { + return data; + } + + //************************************************************************* + /// Set the value of the flags. + //************************************************************************* + void value(value_type initial) ETL_NOEXCEPT + { + data = initial & MASK; + } + + //************************************************************************* + /// Return the value of the flags. + //************************************************************************* + operator value_type() const ETL_NOEXCEPT + { + return data; + } + + //************************************************************************* + /// operator &= + //************************************************************************* + flags& operator &=(value_type other) ETL_NOEXCEPT + { + data &= other; + + return *this; + } + + //************************************************************************* + /// operator |= + //************************************************************************* + flags& operator |=(value_type other) ETL_NOEXCEPT + { + data |= other; + data &= MASK; + + return *this; + } + + //************************************************************************* + /// operator ^= + //************************************************************************* + flags& operator ^=(value_type other) ETL_NOEXCEPT + { + data ^= other; + data &= MASK; + + return *this; + } + + //************************************************************************* + /// operator = + //************************************************************************* + flags& operator =(flags other) ETL_NOEXCEPT + { + if (this != &other) + { + data = other.data; + } + + return *this; + } + + //************************************************************************* + /// operator = + //************************************************************************* + flags& operator =(value_type other) ETL_NOEXCEPT + { + data = (other & MASK); + + return *this; + } + + //************************************************************************* + /// swap + //************************************************************************* + void swap(flags& other) ETL_NOEXCEPT + { + etl::swap(data, other.data); + } + + private: + + value_type data; + }; + + //*************************************************************************** + /// operator == + //*************************************************************************** + template + bool operator == (flags lhs, flags rhs) ETL_NOEXCEPT + { + return lhs.value() == rhs.value(); + } + + //*************************************************************************** + /// operator != + //*************************************************************************** + template + bool operator != (flags lhs, flags rhs) ETL_NOEXCEPT + { + return !(lhs == rhs); + } + + //************************************************************************* + /// swap + //************************************************************************* + template + void swap(etl::flags& lhs, etl::flags& rhs) ETL_NOEXCEPT + { + lhs.swap(rhs); + } +} + +#endif diff --git a/include/etl/generators/type_traits_generator.h b/include/etl/generators/type_traits_generator.h index 077b5f43..aefc48ba 100644 --- a/include/etl/generators/type_traits_generator.h +++ b/include/etl/generators/type_traits_generator.h @@ -1570,6 +1570,28 @@ namespace etl template inline constexpr size_t size_of_v = etl::size_of::value; #endif + +#if ETL_CPP11_SUPPORTED + //*************************************************************************** + /// are_all_same + template + struct are_all_same + { + static const bool value = etl::is_same::value && + etl::are_all_same::value; + }; + + template + struct are_all_same + { + static const bool value = etl::is_same::value; + }; +#endif + +#if ETL_CPP17_SUPPORTED + template + inline constexpr bool are_all_same_v = are_all_same::value; +#endif } #endif // ETL_TYPE_TRAITS_INCLUDED diff --git a/include/etl/platform.h b/include/etl/platform.h index 48d47665..e97a840e 100644 --- a/include/etl/platform.h +++ b/include/etl/platform.h @@ -101,6 +101,20 @@ SOFTWARE. #define ETL_EXPLICIT_STRING_FROM_CHAR #endif +// Option to disable truncation checks for strings. +#if defined(ETL_DISABLE_STRING_TRUNCATION_CHECKS) + #define ETL_STRING_TRUNCATION_CHECKS_ENABLED 0 +#else + #define ETL_STRING_TRUNCATION_CHECKS_ENABLED 1 +#endif + +// Option to disable clear-after-use functionality for strings. +#if defined(ETL_DISABLE_STRING_CLEAR_AFTER_USE) + #define ETL_STRING_CLEAR_AFTER_USE_ENABLED 0 +#else + #define ETL_STRING_CLEAR_AFTER_USE_ENABLED 1 +#endif + // The macros below are dependent on the profile. // C++11 #if ETL_CPP11_SUPPORTED && !defined(ETL_FORCE_NO_ADVANCED_CPP) diff --git a/include/etl/string.h b/include/etl/string.h index be996692..86c1dbc4 100644 --- a/include/etl/string.h +++ b/include/etl/string.h @@ -105,14 +105,16 @@ namespace etl this->assign(other.begin() + position, other.begin() + position + length_); - if (other.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (other.is_truncated()) { - this->is_truncated = true; + this->set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif } +#endif } //************************************************************************* @@ -141,7 +143,7 @@ namespace etl ///\param initialSize The initial size of the string. ///\param value The value to fill the string with. //************************************************************************* - string(size_t count, value_type c) + string(size_type count, value_type c) : istring(reinterpret_cast(&buffer), MAX_SIZE) { this->initialise(); @@ -187,7 +189,7 @@ namespace etl ///\param position The position of the first character. Default = 0. ///\param length The number of characters. Default = npos. //************************************************************************* - etl::string substr(size_t position = 0, size_t length_ = npos) const + etl::string substr(size_type position = 0, size_type length_ = npos) const { etl::string new_string; @@ -270,11 +272,12 @@ namespace etl typedef istring interface_type; typedef istring::value_type value_type; + typedef istring::size_type size_type; //************************************************************************* /// Constructor. //************************************************************************* - string(value_type* buffer, size_t buffer_size) + string(value_type* buffer, size_type buffer_size) : istring(buffer, buffer_size - 1U) { this->initialise(); @@ -284,7 +287,7 @@ namespace etl /// Copy constructor. ///\param other The other string. //************************************************************************* - string(const etl::string<0U>& other, value_type* buffer, size_t buffer_size) + string(const etl::string<0U>& other, value_type* buffer, size_type buffer_size) : istring(buffer, buffer_size - 1U) { this->assign(other); @@ -294,7 +297,7 @@ namespace etl /// From other istring. ///\param other The other istring. //************************************************************************* - string(const etl::istring& other, value_type* buffer, size_t buffer_size) + string(const etl::istring& other, value_type* buffer, size_type buffer_size) : istring(buffer, buffer_size - 1U) { this->assign(other); @@ -306,28 +309,30 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - string(const etl::istring& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + string(const etl::istring& other, value_type* buffer, size_type buffer_size, size_type position, size_type length_ = npos) : istring(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); this->assign(other.begin() + position, other.begin() + position + length_); - if (other.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (other.is_truncated()) { - this->is_truncated = true; + this->set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif } +#endif } //************************************************************************* /// Constructor, from null terminated text. ///\param text The initial text of the string. //************************************************************************* - string(const value_type* text, value_type* buffer, size_t buffer_size) + string(const value_type* text, value_type* buffer, size_type buffer_size) : istring(buffer, buffer_size - 1U) { // Is the initial text at the same address as the buffer? @@ -346,7 +351,7 @@ namespace etl ///\param text The initial text of the string. ///\param count The number of characters to copy. //************************************************************************* - string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + string(const value_type* text, size_type count, value_type* buffer, size_type buffer_size) : istring(buffer, buffer_size - 1U) { this->assign(text, text + count); @@ -357,7 +362,7 @@ namespace etl ///\param initialSize The initial size of the string. ///\param value The value to fill the string with. //************************************************************************* - string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + string(size_type count, value_type c, value_type* buffer, size_type buffer_size) : istring(buffer, buffer_size - 1U) { this->initialise(); @@ -371,7 +376,7 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + string(TIterator first, TIterator last, value_type* buffer, size_type buffer_size) : istring(buffer, buffer_size - 1U) { this->assign(first, last); @@ -381,7 +386,7 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - string(std::initializer_list init, value_type* buffer, size_t buffer_size) + string(std::initializer_list init, value_type* buffer, size_type buffer_size) : istring(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); @@ -392,7 +397,7 @@ namespace etl /// From string_view. ///\param view The string_view. //************************************************************************* - explicit string(const etl::string_view& view, value_type* buffer, size_t buffer_size) + explicit string(const etl::string_view& view, value_type* buffer, size_type buffer_size) : istring(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); @@ -456,7 +461,7 @@ namespace etl size_t operator()(const etl::istring& text) const { return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); + reinterpret_cast(&text[text.size()])); } }; @@ -466,7 +471,7 @@ namespace etl size_t operator()(const etl::string& text) const { return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); + reinterpret_cast(&text[text.size()])); } }; #endif diff --git a/include/etl/string_utilities.h b/include/etl/string_utilities.h index 6701b579..d17c9a5b 100644 --- a/include/etl/string_utilities.h +++ b/include/etl/string_utilities.h @@ -113,7 +113,7 @@ namespace etl template void trim_from_left(TIString& s, typename TIString::const_pointer trim_characters) { - size_t position = s.find_first_not_of(trim_characters); + typename TIString::size_type position = s.find_first_not_of(trim_characters); s.erase(0U, position); } @@ -134,7 +134,7 @@ namespace etl template TStringView trim_from_view_left(const TStringView& view, typename TStringView::const_pointer trim_characters) { - size_t first = view.find_first_not_of(trim_characters); + typename TStringView::size_type first = view.find_first_not_of(trim_characters); typename TStringView::const_pointer pbegin = view.data() + view.size(); @@ -163,7 +163,7 @@ namespace etl template void trim_left(TIString& s, typename TIString::const_pointer delimiters) { - size_t p = s.find_first_of(delimiters); + typename TIString::size_type p = s.find_first_of(delimiters); if (p == TIString::npos) { @@ -182,7 +182,7 @@ namespace etl template TStringView trim_view_left(const TStringView& view, typename TStringView::const_pointer delimiters) { - size_t first = view.find_first_of(delimiters); + typename TStringView::size_type first = view.find_first_of(delimiters); typename TStringView::const_pointer pbegin = view.data(); @@ -193,7 +193,7 @@ namespace etl } else { - return TStringView(pbegin, size_t(0U)); + return TStringView(pbegin, typename TStringView::size_type(0U)); } } @@ -224,7 +224,7 @@ namespace etl template TStringView trim_from_view_right(const TStringView& view, typename TStringView::const_pointer trim_characters) { - size_t last = view.find_last_not_of(trim_characters) + 1; + typename TStringView::size_type last = view.find_last_not_of(trim_characters) + 1; typename TStringView::const_pointer pend = view.data(); @@ -252,7 +252,7 @@ namespace etl template void trim_right(TIString& s, typename TIString::const_pointer delimiters) { - size_t p = s.find_last_of(delimiters); + typename TIString::size_type p = s.find_last_of(delimiters); if (p == TIString::npos) { @@ -275,7 +275,7 @@ namespace etl template TStringView trim_view_right(const TStringView& view, typename TStringView::const_pointer delimiters) { - size_t last = view.find_last_of(delimiters) + 1; + typename TStringView::size_type last = view.find_last_of(delimiters) + 1; typename TStringView::const_pointer pend = view.data(); @@ -286,7 +286,7 @@ namespace etl } else { - return TStringView(view.data(), size_t(0U)); + return TStringView(view.data(), typename TStringView::size_type(0U)); } } @@ -318,8 +318,8 @@ namespace etl template TStringView trim_from_view(const TStringView& view, typename TStringView::const_pointer trim_characters) { - size_t first = view.find_first_not_of(trim_characters); - size_t last = view.find_last_not_of(trim_characters) + 1; + typename TStringView::size_type first = view.find_first_not_of(trim_characters); + typename TStringView::size_type last = view.find_last_not_of(trim_characters) + 1; typename TStringView::const_pointer pbegin = view.data(); typename TStringView::const_pointer pend = view.data(); @@ -365,8 +365,8 @@ namespace etl template TStringView trim_view(const TStringView& view, typename TStringView::const_pointer delimiters) { - size_t first = view.find_first_of(delimiters); - size_t last = view.find_last_of(delimiters) + 1; + typename TStringView::size_type first = view.find_first_of(delimiters); + typename TStringView::size_type last = view.find_last_of(delimiters) + 1; typename TStringView::const_pointer pbegin = view.data(); typename TStringView::const_pointer pend = view.data(); @@ -388,7 +388,7 @@ namespace etl /// Get up to the first n characters. //*************************************************************************** template - void left_n(TIString& s, size_t n) + void left_n(TIString& s, typename TIString::size_type n) { n = (n > s.size()) ? s.size() : n; @@ -399,7 +399,7 @@ namespace etl /// Get a view of up to the first n characters. //*************************************************************************** template - TStringView left_n_view(const TStringView& view, size_t n) + TStringView left_n_view(const TStringView& view, typename TStringView::size_type n) { n = (n > view.size()) ? view.size() : n; @@ -410,7 +410,7 @@ namespace etl /// Get up to the last n characters. //*************************************************************************** template - void right_n(TIString& s, size_t n) + void right_n(TIString& s, typename TIString::size_type n) { n = (n > s.size()) ? s.size() : n; @@ -421,7 +421,7 @@ namespace etl /// Get a view of up to the last n characters. //*************************************************************************** template - TStringView right_n_view(const TStringView& view, size_t n) + TStringView right_n_view(const TStringView& view, typename TStringView::size_type n) { n = (n > view.size()) ? view.size() : n; @@ -466,15 +466,15 @@ namespace etl const typename TIString::value_type* p_old = pairsbegin->first; const typename TIString::value_type* p_new = pairsbegin->second; - size_t position = 0U; + typename TIString::size_type position = 0U; do { position = s.find(p_old, position); if (position != TIString::npos) { - s.replace(position, etl::strlen(p_old), p_new, etl::strlen(p_new)); - position += etl::strlen(p_new); + s.replace(position, typename TIString::size_type(etl::strlen(p_old)), p_new, typename TIString::size_type(etl::strlen(p_new))); + position += typename TIString::size_type(etl::strlen(p_new)); } } while (position != TIString::npos); @@ -703,7 +703,7 @@ namespace etl typedef typename TInput::const_pointer const_pointer; bool token_found = false; - size_t position = 0U; + typename TStringView::size_type position = 0U; TStringView view = last_view.value_or(TStringView()); const_pointer begin_ptr = input.data(); @@ -744,14 +744,14 @@ namespace etl /// pad_left //*************************************************************************** template - void pad_left(TIString& s, size_t required_size, typename TIString::value_type pad_char) + void pad_left(TIString& s, typename TIString::size_type required_size, typename TIString::value_type pad_char) { required_size = etl::min(required_size, s.max_size()); if (required_size > s.size()) { required_size -= s.size(); - s.insert(size_t(0U), required_size, pad_char); + s.insert(typename TIString::size_type(0U), required_size, pad_char); } } @@ -759,7 +759,7 @@ namespace etl /// pad_right //*************************************************************************** template - void pad_right(TIString& s, size_t required_size, typename TIString::value_type pad_char) + void pad_right(TIString& s, typename TIString::size_type required_size, typename TIString::value_type pad_char) { required_size = etl::min(required_size, s.max_size()); @@ -774,7 +774,7 @@ namespace etl /// pad //*************************************************************************** template - void pad(TIString& s, size_t required_size, string_pad_direction pad_direction, typename TIString::value_type pad_char) + void pad(TIString& s, typename TIString::size_type required_size, string_pad_direction pad_direction, typename TIString::value_type pad_char) { switch (int(pad_direction)) { diff --git a/include/etl/type_traits.h b/include/etl/type_traits.h index a9bf689c..91a58a11 100644 --- a/include/etl/type_traits.h +++ b/include/etl/type_traits.h @@ -756,7 +756,7 @@ namespace etl //*************************************************************************** /// Alignment templates. /// These require compiler specific intrinsics. -#if ETL_CPP11_SUPPORTED && !defined(ETL_COMPILER_ARM5) +#if ETL_CPP11_SUPPORTED template struct alignment_of : integral_constant { }; #elif ETL_COMPILER_MICROSOFT template struct alignment_of : integral_constant {}; @@ -1068,12 +1068,11 @@ namespace etl //*************************************************************************** /// is_pod ///\ingroup type_traits - template - struct is_pod : std::integral_constant::value && std::is_trivial::value> {}; + template struct is_pod : std::is_pod {}; #if ETL_CPP17_SUPPORTED template - inline constexpr bool is_pod_v = std::is_standard_layout_v && std::is_trivial_v; + inline constexpr bool is_pod_v = std::is_pod_v; #endif #if !defined(ARDUINO) && ETL_NOT_USING_STLPORT @@ -1563,6 +1562,28 @@ namespace etl template inline constexpr size_t size_of_v = etl::size_of::value; #endif + +#if ETL_CPP11_SUPPORTED + //*************************************************************************** + /// are_all_same + template + struct are_all_same + { + static const bool value = etl::is_same::value && + etl::are_all_same::value; + }; + + template + struct are_all_same + { + static const bool value = etl::is_same::value; + }; +#endif + +#if ETL_CPP17_SUPPORTED + template + inline constexpr bool are_all_same_v = are_all_same::value; +#endif } #endif // ETL_TYPE_TRAITS_INCLUDED diff --git a/include/etl/u16string.h b/include/etl/u16string.h index c2a7db6e..4843d6a3 100644 --- a/include/etl/u16string.h +++ b/include/etl/u16string.h @@ -98,21 +98,23 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u16string(const etl::iu16string& other, size_t position, size_t length_ = npos) + u16string(const etl::iu16string& other, size_type position, size_type length_ = npos) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); this->assign(other.begin() + position, other.begin() + position + length_); - if (other.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (other.is_truncated()) { - this->is_truncated = true; + this->set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif } +#endif } //************************************************************************* @@ -130,7 +132,7 @@ namespace etl ///\param text The initial text of the u16string. ///\param count The number of characters to copy. //************************************************************************* - u16string(const value_type* text, size_t count) + u16string(const value_type* text, size_type count) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { this->assign(text, text + count); @@ -141,7 +143,7 @@ namespace etl ///\param initialSize The initial size of the u16string. ///\param value The value to fill the u16string with. //************************************************************************* - u16string(size_t count, value_type c) + u16string(size_type count, value_type c) : iu16string(reinterpret_cast(&buffer), MAX_SIZE) { this->initialise(); @@ -187,7 +189,7 @@ namespace etl ///\param position The position of the first character. Default = 0. ///\param length The number of characters. Default = npos. //************************************************************************* - etl::u16string substr(size_t position = 0, size_t length_ = npos) const + etl::u16string substr(size_type position = 0, size_type length_ = npos) const { etl::u16string new_string; @@ -260,7 +262,7 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - u16string(value_type* buffer, size_t buffer_size) + u16string(value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) { this->initialise(); @@ -270,7 +272,7 @@ namespace etl /// Copy constructor. ///\param other The other u16string. //************************************************************************* - u16string(const etl::u16string<0U>& other, value_type* buffer, size_t buffer_size) + u16string(const etl::u16string<0U>& other, value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) { this->assign(other); @@ -280,7 +282,7 @@ namespace etl /// From other iu16string. ///\param other The other iu16string. //************************************************************************* - u16string(const etl::iu16string& other, value_type* buffer, size_t buffer_size) + u16string(const etl::iu16string& other, value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) { this->assign(other); @@ -292,28 +294,30 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u16string(const etl::iu16string& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + u16string(const etl::iu16string& other, value_type* buffer, size_type buffer_size, size_type position, size_type length_ = npos) : iu16string(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); this->assign(other.begin() + position, other.begin() + position + length_); - if (other.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (other.is_truncated()) { - this->is_truncated = true; + this->set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(u16string_truncation)); #endif } +#endif } //************************************************************************* /// Constructor, from null terminated text. ///\param text The initial text of the u16string. //************************************************************************* - u16string(const value_type* text, value_type* buffer, size_t buffer_size) + u16string(const value_type* text, value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) { // Is the initial text at the same address as the buffer? @@ -332,7 +336,7 @@ namespace etl ///\param text The initial text of the u16string. ///\param count The number of characters to copy. //************************************************************************* - u16string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + u16string(const value_type* text, size_type count, value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) { this->assign(text, text + count); @@ -343,7 +347,7 @@ namespace etl ///\param initialSize The initial size of the u16string. ///\param value The value to fill the u16string with. //************************************************************************* - u16string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + u16string(size_type count, value_type c, value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) { this->initialise(); @@ -357,7 +361,7 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - u16string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + u16string(TIterator first, TIterator last, value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) { this->assign(first, last); @@ -367,7 +371,7 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - u16string(std::initializer_list init, value_type* buffer, size_t buffer_size) + u16string(std::initializer_list init, value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); @@ -378,7 +382,7 @@ namespace etl /// From u16string_view. ///\param view The u16string_view. //************************************************************************* - explicit u16string(const etl::u16string_view& view, value_type* buffer, size_t buffer_size) + explicit u16string(const etl::u16string_view& view, value_type* buffer, size_type buffer_size) : iu16string(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); @@ -442,7 +446,7 @@ namespace etl size_t operator()(const etl::iu16string& text) const { return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); + reinterpret_cast(&text[text.size()])); } }; @@ -452,7 +456,7 @@ namespace etl size_t operator()(const etl::u16string& text) const { return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); + reinterpret_cast(&text[text.size()])); } }; #endif diff --git a/include/etl/u32string.h b/include/etl/u32string.h index 7e729260..95f128cf 100644 --- a/include/etl/u32string.h +++ b/include/etl/u32string.h @@ -98,21 +98,23 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u32string(const etl::iu32string& other, size_t position, size_t length_ = npos) + u32string(const etl::iu32string& other, size_type position, size_type length_ = npos) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); this->assign(other.begin() + position, other.begin() + position + length_); - if (other.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (other.is_truncated()) { - this->is_truncated = true; + this->set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif } +#endif } //************************************************************************* @@ -130,7 +132,7 @@ namespace etl ///\param text The initial text of the u32string. ///\param count The number of characters to copy. //************************************************************************* - u32string(const value_type* text, size_t count) + u32string(const value_type* text, size_type count) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { this->assign(text, text + count); @@ -141,7 +143,7 @@ namespace etl ///\param initialSize The initial size of the u32string. ///\param value The value to fill the u32string with. //************************************************************************* - u32string(size_t count, value_type c) + u32string(size_type count, value_type c) : iu32string(reinterpret_cast(&buffer), MAX_SIZE) { this->initialise(); @@ -187,7 +189,7 @@ namespace etl ///\param position The position of the first character. Default = 0. ///\param length The number of characters. Default = npos. //************************************************************************* - etl::u32string substr(size_t position = 0, size_t length_ = npos) const + etl::u32string substr(size_type position = 0, size_type length_ = npos) const { etl::u32string new_string; @@ -260,7 +262,7 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - u32string(value_type* buffer, size_t buffer_size) + u32string(value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) { this->initialise(); @@ -270,7 +272,7 @@ namespace etl /// Copy constructor. ///\param other The other u32string. //************************************************************************* - u32string(const etl::u32string<0U>& other, value_type* buffer, size_t buffer_size) + u32string(const etl::u32string<0U>& other, value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) { this->assign(other); @@ -280,7 +282,7 @@ namespace etl /// From other iu32string. ///\param other The other iu32string. //************************************************************************* - u32string(const etl::iu32string& other, value_type* buffer, size_t buffer_size) + u32string(const etl::iu32string& other, value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) { this->assign(other); @@ -292,34 +294,36 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - u32string(const etl::iu32string& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + u32string(const etl::iu32string& other, value_type* buffer, size_type buffer_size, size_type position, size_type length_ = npos) : iu32string(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); this->assign(other.begin() + position, other.begin() + position + length_); - if (other.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (other.is_truncated()) { - this->is_truncated = true; + this->set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(u32string_truncation)); #endif } +#endif } //************************************************************************* /// Constructor, from null terminated text. ///\param text The initial text of the u32string. //************************************************************************* - ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text, value_type* buffer, size_t buffer_size) + ETL_EXPLICIT_STRING_FROM_CHAR u32string(const value_type* text, value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) { // Is the initial text at the same address as the buffer? if (text == buffer) { - this->current_size = etl::strlen(buffer); + this->current_size = etl::strlen(buffer);; } else { @@ -332,7 +336,7 @@ namespace etl ///\param text The initial text of the u32string. ///\param count The number of characters to copy. //************************************************************************* - u32string(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + u32string(const value_type* text, size_type count, value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) { this->assign(text, text + count); @@ -343,7 +347,7 @@ namespace etl ///\param initialSize The initial size of the u32string. ///\param value The value to fill the u32string with. //************************************************************************* - u32string(size_t count, value_type c, value_type* buffer, size_t buffer_size) + u32string(size_type count, value_type c, value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) { this->initialise(); @@ -357,7 +361,7 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - u32string(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + u32string(TIterator first, TIterator last, value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) { this->assign(first, last); @@ -367,7 +371,7 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - u32string(std::initializer_list init, value_type* buffer, size_t buffer_size) + u32string(std::initializer_list init, value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); @@ -378,7 +382,7 @@ namespace etl /// From u32string_view. ///\param view The u32string_view. //************************************************************************* - explicit u32string(const etl::u32string_view& view, value_type* buffer, size_t buffer_size) + explicit u32string(const etl::u32string_view& view, value_type* buffer, size_type buffer_size) : iu32string(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); @@ -442,7 +446,7 @@ namespace etl size_t operator()(const etl::iu32string& text) const { return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); + reinterpret_cast(&text[text.size()])); } }; @@ -452,7 +456,7 @@ namespace etl size_t operator()(const etl::u32string& text) const { return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); + reinterpret_cast(&text[text.size()])); } }; #endif diff --git a/include/etl/wstring.h b/include/etl/wstring.h index 22403529..c56d34b6 100644 --- a/include/etl/wstring.h +++ b/include/etl/wstring.h @@ -92,28 +92,29 @@ namespace etl this->assign(other); } - //************************************************************************* /// From other string, position, length. ///\param other The other string. ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - wstring(const etl::iwstring& other, size_t position, size_t length_ = npos) + wstring(const etl::iwstring& other, size_type position, size_type length_ = npos) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); this->assign(other.begin() + position, other.begin() + position + length_); - if (other.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (other.is_truncated()) { - this->is_truncated = true; + this->set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(string_truncation)); #endif } +#endif } //************************************************************************* @@ -131,7 +132,7 @@ namespace etl ///\param text The initial text of the wstring. ///\param count The number of characters to copy. //************************************************************************* - wstring(const value_type* text, size_t count) + wstring(const value_type* text, size_type count) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { this->assign(text, text + count); @@ -142,7 +143,7 @@ namespace etl ///\param initialSize The initial size of the wstring. ///\param value The value to fill the wstring with. //************************************************************************* - wstring(size_t count, value_type c) + wstring(size_type count, value_type c) : iwstring(reinterpret_cast(&buffer), MAX_SIZE) { this->initialise(); @@ -188,7 +189,7 @@ namespace etl ///\param position The position of the first character. Default = 0. ///\param length The number of characters. Default = npos. //************************************************************************* - etl::wstring substr(size_t position = 0, size_t length_ = npos) const + etl::wstring substr(size_type position = 0, size_type length_ = npos) const { etl::wstring new_string; @@ -261,7 +262,7 @@ namespace etl //************************************************************************* /// Constructor. //************************************************************************* - wstring(value_type* buffer, size_t buffer_size) + wstring(value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) { this->initialise(); @@ -271,7 +272,7 @@ namespace etl /// Copy constructor. ///\param other The other wstring. //************************************************************************* - wstring(const etl::wstring<0U>& other, value_type* buffer, size_t buffer_size) + wstring(const etl::wstring<0U>& other, value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) { this->assign(other); @@ -281,7 +282,7 @@ namespace etl /// From other iwstring. ///\param other The other iwstring. //************************************************************************* - wstring(const etl::iwstring& other, value_type* buffer, size_t buffer_size) + wstring(const etl::iwstring& other, value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) { this->assign(other); @@ -293,28 +294,30 @@ namespace etl ///\param position The position of the first character. ///\param length The number of characters. Default = npos. //************************************************************************* - wstring(const etl::iwstring& other, value_type* buffer, size_t buffer_size, size_t position, size_t length_ = npos) + wstring(const etl::iwstring& other, value_type* buffer, size_type buffer_size, size_type position, size_type length_ = npos) : iwstring(buffer, buffer_size - 1U) { ETL_ASSERT(position < other.size(), ETL_ERROR(string_out_of_bounds)); this->assign(other.begin() + position, other.begin() + position + length_); - if (other.truncated()) +#if ETL_STRING_TRUNCATION_CHECKS_ENABLED + if (other.is_truncated()) { - this->is_truncated = true; + this->set_truncated(true); #if defined(ETL_STRING_TRUNCATION_IS_ERROR) ETL_ALWAYS_ASSERT(ETL_ERROR(wstring_truncation)); #endif } +#endif } //************************************************************************* /// Constructor, from null terminated text. ///\param text The initial text of the wstring. //************************************************************************* - wstring(const value_type* text, value_type* buffer, size_t buffer_size) + wstring(const value_type* text, value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) { // Is the initial text at the same address as the buffer? @@ -333,7 +336,7 @@ namespace etl ///\param text The initial text of the wstring. ///\param count The number of characters to copy. //************************************************************************* - wstring(const value_type* text, size_t count, value_type* buffer, size_t buffer_size) + wstring(const value_type* text, size_type count, value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) { this->assign(text, text + count); @@ -344,7 +347,7 @@ namespace etl ///\param initialSize The initial size of the wstring. ///\param value The value to fill the wstring with. //************************************************************************* - wstring(size_t count, value_type c, value_type* buffer, size_t buffer_size) + wstring(size_type count, value_type c, value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) { this->initialise(); @@ -358,7 +361,7 @@ namespace etl ///\param last The iterator to the last element + 1. //************************************************************************* template - wstring(TIterator first, TIterator last, value_type* buffer, size_t buffer_size) + wstring(TIterator first, TIterator last, value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) { this->assign(first, last); @@ -368,7 +371,7 @@ namespace etl //************************************************************************* /// Construct from initializer_list. //************************************************************************* - wstring(std::initializer_list init, value_type* buffer, size_t buffer_size) + wstring(std::initializer_list init, value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) { this->assign(init.begin(), init.end()); @@ -379,7 +382,7 @@ namespace etl /// From wstring_view. ///\param view The wstring_view. //************************************************************************* - explicit wstring(const etl::wstring_view& view, value_type* buffer, size_t buffer_size) + explicit wstring(const etl::wstring_view& view, value_type* buffer, size_type buffer_size) : iwstring(buffer, buffer_size - 1U) { this->assign(view.begin(), view.end()); @@ -443,7 +446,7 @@ namespace etl size_t operator()(const etl::iwstring& text) const { return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); + reinterpret_cast(&text[text.size()])); } }; @@ -453,7 +456,7 @@ namespace etl size_t operator()(const etl::wstring& text) const { return etl::private_hash::generic_hash(reinterpret_cast(&text[0]), - reinterpret_cast(&text[text.size()])); + reinterpret_cast(&text[text.size()])); } }; #endif diff --git a/test/codeblocks/ETL.cbp b/test/codeblocks/ETL.cbp index 52f76a84..65b731dd 100644 --- a/test/codeblocks/ETL.cbp +++ b/test/codeblocks/ETL.cbp @@ -127,6 +127,29 @@ + + @@ -211,6 +234,7 @@