31#ifndef ETL_U8STRING_INCLUDED
32#define ETL_U8STRING_INCLUDED
47 #if ETL_USING_CPP11 && ETL_HAS_NATIVE_CHAR8_T
48 inline namespace literals
50 inline namespace string_literals
52 inline constexpr etl::u8string_view
operator""_sv(
const char8_t* str,
size_t length) ETL_NOEXCEPT
54 return etl::u8string_view{str, length};
60 typedef etl::ibasic_string<char8_t> iu8string;
67 template <
size_t MAX_SIZE_>
72 typedef iu8string base_type;
73 typedef iu8string interface_type;
75 typedef iu8string::value_type value_type;
77 static ETL_CONSTANT
size_t MAX_SIZE = MAX_SIZE_;
83 : iu8string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
93 : iu8string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
103 : iu8string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
115 : iu8string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
126 ETL_EXPLICIT_STRING_FROM_CHAR
u8string(
const value_type* text)
127 : iu8string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
138 : iu8string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
140 this->
assign(text, text + count);
149 : iu8string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
161 template <
typename TIterator>
162 u8string(TIterator first, TIterator last,
typename etl::enable_if<!etl::is_integral<TIterator>::value,
int>
::type = 0)
163 : iu8string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
165 this->
assign(first, last);
168 #if ETL_HAS_INITIALIZER_LIST
172 u8string(std::initializer_list<value_type> init)
173 : iu8string(reinterpret_cast<
value_type*>(&buffer), MAX_SIZE)
175 this->
assign(init.begin(), init.end());
184 : iu8string(reinterpret_cast<value_type*>(&buffer), MAX_SIZE)
198 if (position != this->
size())
202 length_ = etl::min(length_, this->
size() - position);
204 new_string.
assign(buffer + position, buffer + position + length_);
259 #if ETL_HAS_ISTRING_REPAIR
260 virtual void repair() ETL_OVERRIDE
273 template <
size_t MAX_SIZE_>
274 ETL_CONSTANT
size_t u8string<MAX_SIZE_>::MAX_SIZE;
284 typedef iu8string base_type;
285 typedef iu8string interface_type;
287 typedef iu8string::value_type value_type;
288 typedef iu8string::size_type size_type;
294 : iu8string(buffer, buffer_size - 1U)
303 template <
size_t Size>
305 : iu8string(buffer, Size - 1U)
315 : iu8string(buffer, buffer_size - 1U)
319 this->current_size = other.size();
331 u8string_ext(
const etl::iu8string& other, value_type* buffer, size_type buffer_size)
332 : iu8string(buffer, buffer_size - 1U)
336 this->current_size = other.size();
349 template <
size_t BufferSize>
350 u8string_ext(
const etl::iu8string& other, value_type (&buffer)[BufferSize])
351 : iu8string(buffer, BufferSize - 1U)
355 this->current_size = other.size();
369 u8string_ext(
const etl::iu8string& other, value_type* buffer, size_type buffer_size, size_type position, size_type
length = npos)
370 : iu8string(buffer, buffer_size - 1U)
391 template <
size_t BufferSize>
392 u8string_ext(
const etl::iu8string& other, value_type (&buffer)[BufferSize], size_type position, size_type
length = npos)
393 : iu8string(buffer, BufferSize - 1U)
411 template <
typename TPo
inter>
413 typename etl::enable_if<etl::is_same<const value_type*, TPointer>::value,
int>
::type* = ETL_NULLPTR)
414 : iu8string(buffer, buffer_size - 1U)
431 template <
typename TPo
inter,
size_t BufferSize>
433 typename etl::enable_if<etl::is_same<const value_type*, TPointer>::value,
int>
::type* = ETL_NULLPTR)
434 : iu8string(buffer, BufferSize - 1U)
450 template <
size_t Size>
451 u8string_ext(
const value_type (&literal)[Size], value_type* buffer, size_type buffer_size)
452 : iu8string(buffer, buffer_size - 1U)
469 template <
size_t LiteralSize,
size_t BufferSize>
470 u8string_ext(
const value_type (&literal)[LiteralSize], value_type (&buffer)[BufferSize])
471 : iu8string(buffer, BufferSize - 1U)
488 u8string_ext(
const value_type* text, size_type count, value_type* buffer, size_type buffer_size)
489 : iu8string(buffer, buffer_size - 1U)
497 this->
assign(text, text + count);
507 template <
size_t BufferSize>
508 u8string_ext(
const value_type* text, size_type count, value_type (&buffer)[BufferSize])
509 : iu8string(buffer, BufferSize - 1U)
517 this->
assign(text, text + count);
526 u8string_ext(size_type count, value_type c, value_type* buffer, size_type buffer_size)
527 : iu8string(buffer, buffer_size - 1U)
539 template <
size_t BufferSize>
540 u8string_ext(size_type count, value_type c, value_type (&buffer)[BufferSize])
541 : iu8string(buffer, BufferSize - 1U)
551 explicit u8string_ext(
const etl::u8string_view& view, value_type* buffer, size_type buffer_size)
552 : iu8string(buffer, buffer_size - 1U)
556 this->current_size = view.size();
560 this->assign(view.begin(), view.end());
569 template <
size_t BufferSize>
570 explicit u8string_ext(
const etl::u8string_view& view, value_type (&buffer)[BufferSize])
571 : iu8string(buffer, BufferSize - 1U)
575 this->current_size = view.size();
579 this->assign(view.begin(), view.end());
589 template <
typename TIterator>
590 u8string_ext(TIterator first, TIterator last, value_type* buffer, size_type buffer_size,
591 typename etl::enable_if<!etl::is_integral<TIterator>::value,
int>
::type = 0)
592 : iu8string(buffer, buffer_size - 1U)
596 this->
current_size =
static_cast<size_type
>(etl::distance(first, last));
600 this->
assign(first, last);
611 template <
typename TIterator,
size_t BufferSize>
612 u8string_ext(TIterator first, TIterator last, value_type (&buffer)[BufferSize],
613 typename etl::enable_if<!etl::is_integral<TIterator>::value,
int>
::type = 0)
614 : iu8string(buffer, BufferSize - 1U)
618 this->
current_size =
static_cast<size_type
>(etl::distance(first, last));
622 this->
assign(first, last);
626 #if ETL_HAS_INITIALIZER_LIST
631 : iu8string(buffer, buffer_size - 1U)
633 this->
assign(init.begin(), init.end());
641 template <
size_t BufferSize>
642 u8string_ext(std::initializer_list<value_type> init, value_type (&buffer)[BufferSize])
643 : iu8string(buffer, BufferSize - 1U)
645 this->
assign(init.begin(), init.end());
698 #if ETL_HAS_ISTRING_REPAIR
699 virtual void repair() ETL_OVERRIDE
717 #if ETL_USING_8BIT_TYPES
720 struct hash<
etl::iu8string>
722 size_t operator()(
const etl::iu8string& text)
const
724 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(text.
data()),
725 reinterpret_cast<const uint8_t*
>(text.
data() + text.
size()));
729 template <
size_t SIZE>
732 size_t operator()(
const etl::u8string<SIZE>& text)
const
734 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(text.
data()),
735 reinterpret_cast<const uint8_t*
>(text.
data() + text.
size()));
742 size_t operator()(
const etl::u8string_ext& text)
const
744 return etl::private_hash::generic_hash<size_t>(
reinterpret_cast<const uint8_t*
>(text.
data()),
745 reinterpret_cast<const uint8_t*
>(text.
data() + text.
size()));
754 template <
size_t Array_Size>
763 template <
size_t MAX_SIZE,
size_t SIZE>
ETL_CONSTEXPR const_pointer data() const ETL_NOEXCEPT
Returns a const pointer to the first element of the internal storage.
Definition string_view.h:223
ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
Returns a const iterator to the end of the array.
Definition string_view.h:247
ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the array.
Definition string_view.h:231
bool is_within_buffer(const_pointer ptr) const
Definition basic_string.h:2711
void resize(size_type new_size)
Definition basic_string.h:480
void assign(const etl::ibasic_string< char8_t > &other)
Definition basic_string.h:685
pointer data()
Definition basic_string.h:648
void initialise()
Definition basic_string.h:2482
void repair_buffer(char8_t *p_buffer_)
Definition basic_string.h:2494
size_type length() const
Definition basic_string.h:202
size_type current_size
The current number of elements in the string.
Definition basic_string.h:334
size_type size() const
Definition basic_string.h:193
Definition basic_string.h:115
Definition u8string.h:281
u8string_ext(TIterator first, TIterator last, value_type *buffer, size_type buffer_size, typename etl::enable_if<!etl::is_integral< TIterator >::value, int >::type=0)
Definition u8string.h:590
u8string_ext(TPointer text, value_type *buffer, size_type buffer_size, typename etl::enable_if< etl::is_same< const value_type *, TPointer >::value, int >::type *=ETL_NULLPTR)
Definition u8string.h:412
u8string_ext & operator=(const u8string_ext &rhs)
Assignment operator.
Definition u8string.h:652
u8string_ext(const etl::iu8string &other, value_type(&buffer)[BufferSize])
Definition u8string.h:350
u8string_ext & operator=(const value_type *text)
Assignment operator.
Definition u8string.h:678
u8string_ext(const etl::u8string_ext &other, value_type *buffer, size_type buffer_size)
Definition u8string.h:314
u8string_ext(const etl::iu8string &other, value_type *buffer, size_type buffer_size, size_type position, size_type length=npos)
Definition u8string.h:369
u8string_ext(TIterator first, TIterator last, value_type(&buffer)[BufferSize], typename etl::enable_if<!etl::is_integral< TIterator >::value, int >::type=0)
Definition u8string.h:612
u8string_ext(size_type count, value_type c, value_type(&buffer)[BufferSize])
Definition u8string.h:540
u8string_ext(const etl::iu8string &other, value_type(&buffer)[BufferSize], size_type position, size_type length=npos)
Definition u8string.h:392
void repair()
Fix the internal pointers after a low level memory copy.
Definition u8string.h:701
u8string_ext(value_type(&buffer)[Size])
Definition u8string.h:304
u8string_ext(const value_type *text, size_type count, value_type(&buffer)[BufferSize])
Definition u8string.h:508
u8string_ext(value_type *buffer, size_type buffer_size)
Constructor.
Definition u8string.h:293
u8string_ext & operator=(const etl::u8string_view &view)
Assignment operator.
Definition u8string.h:688
u8string_ext(const value_type *text, size_type count, value_type *buffer, size_type buffer_size)
Definition u8string.h:488
u8string_ext(const etl::iu8string &other, value_type *buffer, size_type buffer_size)
Definition u8string.h:331
u8string_ext(TPointer text, value_type(&buffer)[BufferSize], typename etl::enable_if< etl::is_same< const value_type *, TPointer >::value, int >::type *=ETL_NULLPTR)
Definition u8string.h:432
u8string_ext(const value_type(&literal)[Size], value_type *buffer, size_type buffer_size)
Definition u8string.h:451
u8string_ext & operator=(const iu8string &rhs)
Assignment operator.
Definition u8string.h:665
u8string_ext(const etl::u8string_view &view, value_type(&buffer)[BufferSize])
Definition u8string.h:570
u8string_ext(size_type count, value_type c, value_type *buffer, size_type buffer_size)
Definition u8string.h:526
u8string_ext(const value_type(&literal)[LiteralSize], value_type(&buffer)[BufferSize])
Definition u8string.h:470
u8string_ext(const etl::u8string_view &view, value_type *buffer, size_type buffer_size)
Definition u8string.h:551
u8string & operator=(const u8string &rhs)
Assignment operator.
Definition u8string.h:213
u8string(const value_type *text, size_t count)
Definition u8string.h:137
u8string(size_type count, value_type c)
Definition u8string.h:148
void repair()
Fix the internal pointers after a low level memory copy.
Definition u8string.h:262
etl::u8string< MAX_SIZE_ > substr(size_type position=0, size_type length_=npos) const
Definition u8string.h:194
u8string(const etl::u8string_view &view)
Definition u8string.h:183
u8string & operator=(const iu8string &rhs)
Assignment operator.
Definition u8string.h:226
u8string(const etl::iu8string &other, size_t position, size_t length=npos)
Definition u8string.h:114
u8string(const etl::u8string< MAX_SIZE_ > &other)
Definition u8string.h:92
u8string & operator=(const etl::u8string_view &view)
Assignment operator.
Definition u8string.h:249
ETL_EXPLICIT_STRING_FROM_CHAR u8string(const value_type *text)
Definition u8string.h:126
u8string & operator=(const value_type *text)
Assignment operator.
Definition u8string.h:239
u8string()
Constructor.
Definition u8string.h:82
u8string(TIterator first, TIterator last, typename etl::enable_if<!etl::is_integral< TIterator >::value, int >::type=0)
Definition u8string.h:162
u8string(const etl::iu8string &other)
Definition u8string.h:102
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
ETL_CONSTEXPR17 etl::enable_if<!etl::is_same< T, etl::nullptr_t >::value, T >::type * addressof(T &t)
Definition addressof.h:52
bitset_ext
Definition absolute.h:40
etl::string< Array_Size - 1U > make_string(const char(&text)[Array_Size])
Hash function.
Definition string.h:753
etl::string< MAX_SIZE > make_string_with_capacity(const char(&text)[SIZE])
Make string with max capacity from string literal or array.
Definition string.h:762
ETL_CONSTEXPR14 size_t strlen(const T *t) ETL_NOEXCEPT
Alternative strlen for all character types.
Definition char_traits.h:293