Loading...
Searching...
No Matches
basic_string.h
Go to the documentation of this file.
/******************************************************************************
The MIT License(MIT)
Embedded Template Library.
https://github.com/ETLCPP/etl
https://www.etlcpp.com
Copyright(c) 2016 John Wellbelove
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/
#ifndef ETL_BASIC_STRING_INCLUDED
#define ETL_BASIC_STRING_INCLUDED
#include "platform.h"
#include "algorithm.h"
#include "alignment.h"
#include "array.h"
#include "binary.h"
#include "error_handler.h"
#include "exception.h"
#include "flags.h"
#include "integral_limits.h"
#include "iterator.h"
#include "memory.h"
#include "string_utilities.h"
#include "type_traits.h"
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#if ETL_USING_LIBC_WCHAR_H
#include <wchar.h>
#endif
#if ETL_USING_STL && ETL_USING_CPP17
#include <string_view>
#endif
#if ETL_USING_STD_OSTREAM
#include <ostream>
#endif
#include "private/minmax_push.h"
//*****************************************************************************
//*****************************************************************************
// Forward declaration of string_view
namespace etl
{
template <typename T, typename TTraits>
class basic_string_view;
}
namespace etl
{
//***************************************************************************
//***************************************************************************
class string_exception : public etl::exception
{
public:
string_exception(string_type reason_, string_type file_name_, numeric_type line_number_)
: exception(reason_, file_name_, line_number_)
{
}
};
//***************************************************************************
//***************************************************************************
class string_out_of_bounds : public etl::string_exception
{
public:
string_out_of_bounds(string_type file_name_, numeric_type line_number_)
: string_exception(ETL_ERROR_TEXT("string:bounds", ETL_BASIC_STRING_FILE_ID"B"), file_name_, line_number_)
{
}
};
//***************************************************************************
//***************************************************************************
class string_iterator : public etl::string_exception
{
public:
string_iterator(string_type file_name_, numeric_type line_number_)
: string_exception(ETL_ERROR_TEXT("string:iterator", ETL_BASIC_STRING_FILE_ID"C"), file_name_, line_number_)
{
}
};
//***************************************************************************
//***************************************************************************
class string_truncation : public etl::string_exception
{
public:
string_truncation(string_type file_name_, numeric_type line_number_)
: string_exception(ETL_ERROR_TEXT("string:truncation", ETL_BASIC_STRING_FILE_ID"D"), file_name_, line_number_)
{
}
};
//***************************************************************************
//***************************************************************************
namespace private_basic_string
{
//*************************************************************************
template <typename T = void>
class string_base_statics
{
public:
typedef size_t size_type;
static ETL_CONSTANT uint_least8_t IS_TRUNCATED = etl::bit<0>::value;
static ETL_CONSTANT uint_least8_t CLEAR_AFTER_USE = etl::bit<1>::value;
static ETL_CONSTANT size_type npos = etl::integral_limits<size_type>::max;
};
template <typename T>
ETL_CONSTANT uint_least8_t string_base_statics<T>::IS_TRUNCATED;
template <typename T>
ETL_CONSTANT uint_least8_t string_base_statics<T>::CLEAR_AFTER_USE;
template <typename T>
ETL_CONSTANT typename string_base_statics<T>::size_type string_base_statics<T>::npos;
} // namespace private_basic_string
//***************************************************************************
class string_base : public private_basic_string::string_base_statics<>
{
public:
typedef size_t size_type;
//*************************************************************************
//*************************************************************************
size_type size() const
{
return current_size;
}
//*************************************************************************
//*************************************************************************
size_type length() const
{
return current_size;
}
//*************************************************************************
//*************************************************************************
bool empty() const
{
return (current_size == 0);
}
//*************************************************************************
//*************************************************************************
bool full() const
{
return current_size == CAPACITY;
}
//*************************************************************************
//*************************************************************************
size_type capacity() const
{
return CAPACITY;
}
//*************************************************************************
//*************************************************************************
size_type max_size() const
{
return CAPACITY;
}
//*************************************************************************
//*************************************************************************
size_type available() const
{
return max_size() - size();
}
//*************************************************************************
//*************************************************************************
bool is_truncated() const
{
#if ETL_HAS_STRING_TRUNCATION_CHECKS
return flags.test<IS_TRUNCATED>();
#else
return false;
#endif
}
//*************************************************************************
//*************************************************************************
ETL_DEPRECATED
bool truncated() const
{
return is_truncated();
}
#if ETL_HAS_STRING_TRUNCATION_CHECKS
//*************************************************************************
//*************************************************************************
void clear_truncated()
{
flags.set<IS_TRUNCATED, false>();
}
#endif
#if ETL_HAS_STRING_CLEAR_AFTER_USE
//*************************************************************************
//*************************************************************************
void set_secure()
{
flags.set<CLEAR_AFTER_USE>();
}
#endif
//*************************************************************************
//*************************************************************************
bool is_secure() const
{
#if ETL_HAS_STRING_CLEAR_AFTER_USE
return flags.test<CLEAR_AFTER_USE>();
#else
return false;
#endif
}
protected:
//*************************************************************************
//*************************************************************************
string_base(size_type max_size_)
: current_size(0)
, CAPACITY(max_size_)
{
}
#if ETL_HAS_STRING_TRUNCATION_CHECKS
//*************************************************************************
//*************************************************************************
void set_truncated(bool status)
{
flags.set<IS_TRUNCATED>(status);
}
#endif
//*************************************************************************
//*************************************************************************
~string_base() {}
size_type current_size;
const size_type CAPACITY;
#if ETL_HAS_STRING_TRUNCATION_CHECKS || ETL_HAS_STRING_CLEAR_AFTER_USE
etl::flags<uint_least8_t> flags;
#endif
};
//***************************************************************************
//***************************************************************************
template <typename T>
class ibasic_string : public etl::string_base
{
public:
typedef ibasic_string<T> interface_type;
typedef T value_type;
typedef T& reference;
typedef const T& const_reference;
typedef T* pointer;
typedef const T* const_pointer;
typedef T* iterator;
typedef const T* const_iterator;
typedef ETL_OR_STD::reverse_iterator<iterator> reverse_iterator;
typedef ETL_OR_STD::reverse_iterator<const_iterator> const_reverse_iterator;
typedef typename etl::iterator_traits<iterator>::difference_type difference_type;
//*********************************************************************
//*********************************************************************
iterator begin()
{
return &p_buffer[0];
}
//*********************************************************************
//*********************************************************************
const_iterator begin() const
{
return &p_buffer[0];
}
//*********************************************************************
//*********************************************************************
iterator end()
{
return &p_buffer[current_size];
}
//*********************************************************************
//*********************************************************************
const_iterator end() const
{
return &p_buffer[current_size];
}
//*********************************************************************
//*********************************************************************
const_iterator cbegin() const
{
return &p_buffer[0];
}
//*********************************************************************
//*********************************************************************
const_iterator cend() const
{
return &p_buffer[current_size];
}
//*********************************************************************
//*********************************************************************
reverse_iterator rbegin()
{
return reverse_iterator(end());
}
//*********************************************************************
//*********************************************************************
const_reverse_iterator rbegin() const
{
return const_reverse_iterator(end());
}
//*********************************************************************
//*********************************************************************
reverse_iterator rend()
{
return reverse_iterator(begin());
}
//*********************************************************************
//*********************************************************************
const_reverse_iterator rend() const
{
return const_reverse_iterator(begin());
}
//*********************************************************************
//*********************************************************************
const_reverse_iterator crbegin() const
{
return const_reverse_iterator(cend());
}
//*********************************************************************
//*********************************************************************
const_reverse_iterator crend() const
{
return const_reverse_iterator(cbegin());
}
//*********************************************************************
//*********************************************************************
void resize(size_type new_size)
{
resize(new_size, 0);
}
//*********************************************************************
//*********************************************************************
void resize(size_type new_size, T value)
{
if (new_size > CAPACITY)
{
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(true);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
#endif
#endif
}
new_size = etl::min(new_size, CAPACITY);
// Size up?
if (new_size > current_size)
{
etl::fill(p_buffer + current_size, p_buffer + new_size, value);
}
current_size = new_size;
p_buffer[new_size] = 0;
cleanup();
}
//*********************************************************************
//*********************************************************************
template <typename TOperation>
void resize_and_overwrite(size_type new_size, TOperation operation)
{
if (new_size > CAPACITY)
{
ETL_ASSERT_FAIL(ETL_ERROR(string_out_of_bounds));
}
current_size = operation(p_buffer, new_size);
p_buffer[current_size] = '\0';
cleanup();
}
//*********************************************************************
//*********************************************************************
void uninitialized_resize(size_type new_size)
{
new_size = etl::min(new_size, CAPACITY);
current_size = new_size;
p_buffer[new_size] = 0;
}
//*********************************************************************
//*********************************************************************
void fill(T value)
{
etl::fill(begin(), end(), value);
}
//*********************************************************************
//*********************************************************************
reference operator[](size_type i)
{
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(string_out_of_bounds));
return p_buffer[i];
}
//*********************************************************************
//*********************************************************************
const_reference operator[](size_type i) const
{
ETL_ASSERT_CHECK_INDEX_OPERATOR(i < size(), ETL_ERROR(string_out_of_bounds));
return p_buffer[i];
}
//*********************************************************************
//*********************************************************************
reference at(size_type i)
{
ETL_ASSERT(i < size(), ETL_ERROR(string_out_of_bounds));
return p_buffer[i];
}
//*********************************************************************
//*********************************************************************
const_reference at(size_type i) const
{
ETL_ASSERT(i < size(), ETL_ERROR(string_out_of_bounds));
return p_buffer[i];
}
//*********************************************************************
//*********************************************************************
reference front()
{
ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(string_out_of_bounds));
return p_buffer[0];
}
//*********************************************************************
//*********************************************************************
const_reference front() const
{
ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(string_out_of_bounds));
return p_buffer[0];
}
//*********************************************************************
//*********************************************************************
reference back()
{
ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(string_out_of_bounds));
return p_buffer[size() - 1];
}
//*********************************************************************
//*********************************************************************
const_reference back() const
{
ETL_ASSERT_CHECK_EXTRA(size() > 0, ETL_ERROR(string_out_of_bounds));
return p_buffer[size() - 1];
}
//*********************************************************************
//*********************************************************************
pointer data()
{
return p_buffer;
}
//*********************************************************************
//*********************************************************************
ETL_CONSTEXPR const_pointer data() const
{
return p_buffer;
}
//*********************************************************************
//*********************************************************************
pointer data_end()
{
return p_buffer + current_size;
}
//*********************************************************************
//*********************************************************************
const_pointer data_end() const
{
return p_buffer + current_size;
}
//*********************************************************************
//*********************************************************************
void assign(const etl::ibasic_string<T>& other)
{
if (&other != this)
{
clear();
append_impl(begin(), other.begin(), other.end(), other.is_truncated(), other.is_secure());
}
}
//*********************************************************************
//*********************************************************************
void assign(const etl::ibasic_string<T>& other, size_type subposition, size_type sublength)
{
if (&other != this)
{
clear();
if (sublength == npos)
{
sublength = other.size() - subposition;
}
ETL_ASSERT(subposition <= other.size(), ETL_ERROR(string_out_of_bounds));
append_impl(begin(), other.begin() + subposition, other.begin() + subposition + sublength, other.is_truncated(), other.is_secure());
}
}
//*********************************************************************
//*********************************************************************
template <typename TIterator>
void assign(TIterator first, TIterator last)
{
append_impl(begin(), first, last, false, false);
}
//*********************************************************************
//*********************************************************************
void assign(const_pointer str)
{
append_impl(begin(), str, false, false);
}
//*********************************************************************
//*********************************************************************
void assign(const_pointer str, size_type n)
{
append_impl(begin(), str, str + n, false, false);
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
void assign(const etl::basic_string_view<T, TOtherTraits>& view)
{
append_impl(begin(), view.begin(), view.end(), false, false);
}
//*********************************************************************
//*********************************************************************
void assign(size_type n, T c)
{
clear();
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(n > CAPACITY);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT(is_truncated() == false, ETL_ERROR(string_truncation));
#endif
#endif
n = etl::min(n, CAPACITY);
etl::fill_n(begin(), n, c);
current_size = n;
p_buffer[current_size] = 0;
}
//*************************************************************************
//*************************************************************************
void clear()
{
initialise();
cleanup();
}
//*********************************************************************
//*********************************************************************
void push_back(T value)
{
if (current_size != CAPACITY)
{
p_buffer[current_size++] = value;
p_buffer[current_size] = 0;
}
else
{
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(true);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
#endif
#endif
}
}
//*************************************************************************
//*************************************************************************
void pop_back()
{
if (current_size != 0)
{
p_buffer[--current_size] = 0;
}
}
//*********************************************************************
//*********************************************************************
ibasic_string& append(const ibasic_string& str)
{
append_impl(end(), str.begin(), str.end(), str.is_truncated(), str.is_secure());
return *this;
}
//*********************************************************************
//*********************************************************************
ibasic_string& append(const ibasic_string& str, size_type subposition, size_type sublength = npos)
{
if (sublength == npos)
{
sublength = str.size() - subposition;
}
ETL_ASSERT(subposition <= str.size(), ETL_ERROR(string_out_of_bounds));
append_impl(end(), str.begin() + subposition, str.begin() + subposition + sublength, str.is_truncated(), str.is_secure());
return *this;
}
//*********************************************************************
//*********************************************************************
template <class TIterator>
ibasic_string& append(TIterator first, TIterator last)
{
append_impl(end(), first, last, false, false);
return *this;
}
//*********************************************************************
//*********************************************************************
ibasic_string& append(const_pointer str)
{
append_impl(end(), str, false, false);
return *this;
}
//*********************************************************************
//*********************************************************************
ibasic_string& append(const_pointer str, size_type n)
{
append_impl(end(), str, str + n, false, false);
return *this;
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
ibasic_string& append(const etl::basic_string_view<T, TOtherTraits>& view)
{
append_impl(end(), view.begin(), view.end(), false, false);
return *this;
}
//*********************************************************************
//*********************************************************************
ibasic_string& append(size_type n, T c)
{
size_type free_space = CAPACITY - current_size;
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(n > free_space);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT(is_truncated() == false, ETL_ERROR(string_truncation));
#endif
#endif
n = etl::min(n, size_t(free_space));
etl::fill_n(end(), n, c);
current_size += n;
p_buffer[current_size] = 0;
return *this;
}
//*********************************************************************
//*********************************************************************
iterator insert(const_iterator position, T value)
{
ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(string_out_of_bounds));
// Quick hack, as iterators are pointers.
iterator insert_position = to_iterator(position);
if (current_size < CAPACITY)
{
// Not full yet.
if (position != end())
{
// Insert in the middle.
++current_size;
etl::mem_move(insert_position, end() - 1, insert_position + 1);
*insert_position = value;
}
else
{
// Insert at the end.
*insert_position = value;
++current_size;
}
}
else
{
// Already full.
if (position != end())
{
// Insert in the middle.
etl::mem_move(insert_position, end() - 1, insert_position + 1);
*insert_position = value;
}
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(true);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
#endif
#endif
}
p_buffer[current_size] = 0;
return insert_position;
}
//*********************************************************************
//*********************************************************************
iterator insert(const_iterator position, size_type n, T value)
{
ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(string_out_of_bounds));
iterator position_ = to_iterator(position);
if (n == 0)
{
return position_;
}
// Quick hack, as iterators are pointers.
iterator insert_position = to_iterator(position);
const size_type start = static_cast<size_type>(etl::distance(cbegin(), position));
// No effect.
if (start >= CAPACITY)
{
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(true);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
#endif
#endif
return to_iterator(position);
}
// Fills the string to the end?
if ((start + n) >= CAPACITY)
{
if ((current_size + n) > CAPACITY)
{
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(true);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
#endif
#endif
}
current_size = CAPACITY;
etl::fill(insert_position, end(), value);
}
else
{
// Lets do some shifting.
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;
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(true);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
#endif
#endif
}
else
{
current_size += shift_amount;
}
etl::mem_move(insert_position, insert_position + characters_to_shift, begin() + to_position);
etl::fill(insert_position, insert_position + shift_amount, value);
}
p_buffer[current_size] = 0;
return position_;
}
//*********************************************************************
//*********************************************************************
template <typename TIterator>
iterator insert(const_iterator position, TIterator first, TIterator last)
{
ETL_ASSERT_CHECK_EXTRA(cbegin() <= position && position <= cend(), ETL_ERROR(string_out_of_bounds));
ETL_ASSERT_CHECK_EXTRA(first <= last, ETL_ERROR(string_iterator));
iterator position_ = to_iterator(position);
if (first == last)
{
return position_;
}
const size_type start = static_cast<size_type>(etl::distance(begin(), position_));
const size_type n = static_cast<size_type>(etl::distance(first, last));
// No effect.
if (start >= CAPACITY)
{
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(true);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
#endif
#endif
return position_;
}
// Fills the string to the end?
if ((start + n) >= CAPACITY)
{
if (((current_size + n) > CAPACITY))
{
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(true);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
#endif
#endif
}
current_size = CAPACITY;
position_ = copy_characters(first, static_cast<size_t>(etl::distance(position_, end())), position_);
}
else
{
// Lets do some shifting.
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;
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(true);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
#endif
#endif
}
else
{
current_size += shift_amount;
}
etl::mem_move(position_, position_ + characters_to_shift, begin() + to_position);
// etl::copy_backward(position_, position_ + characters_to_shift,
// begin() + to_position + characters_to_shift);
position_ = copy_characters(first, static_cast<size_t>(etl::distance(first, last)), position_);
}
p_buffer[current_size] = 0;
return position_;
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
iterator insert(const_iterator position, const etl::basic_string_view<T, TOtherTraits>& view)
{
return insert(position, view.begin(), view.end());
}
//*********************************************************************
//*********************************************************************
etl::ibasic_string<T>& insert(size_type position, const etl::ibasic_string<T>& str)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
insert(begin() + position, str.cbegin(), str.cend());
#if ETL_HAS_STRING_TRUNCATION_CHECKS
if (str.is_truncated())
{
set_truncated(true);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
#endif
}
#endif
return *this;
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
etl::ibasic_string<T>& insert(size_type position, const etl::basic_string_view<T, TOtherTraits>& view)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
insert(begin() + position, view.cbegin(), view.cend());
return *this;
}
//*********************************************************************
//*********************************************************************
etl::ibasic_string<T>& insert(size_type position, const etl::ibasic_string<T>& 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));
if ((sublength == npos) || (subposition + sublength > str.size()))
{
sublength = str.size() - subposition;
}
insert(begin() + position, str.cbegin() + subposition, str.cbegin() + subposition + sublength);
#if ETL_HAS_STRING_TRUNCATION_CHECKS
if (str.is_truncated())
{
set_truncated(true);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT_FAIL(ETL_ERROR(string_truncation));
#endif
}
#endif
return *this;
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
etl::ibasic_string<T>& insert(size_type position, const etl::basic_string_view<T, TOtherTraits>& view, size_type subposition, size_type sublength)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds));
if ((sublength == npos) || (subposition + sublength > view.size()))
{
sublength = view.size() - subposition;
}
insert(begin() + position, view.cbegin() + subposition, view.cbegin() + subposition + sublength);
return *this;
}
//*********************************************************************
//*********************************************************************
etl::ibasic_string<T>& insert(size_type position, const_pointer s)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
insert(begin() + position, s, s + etl::strlen(s));
return *this;
}
//*********************************************************************
//*********************************************************************
etl::ibasic_string<T>& insert(size_type position, const_pointer s, size_type n)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
insert(begin() + position, s, s + n);
return *this;
}
//*********************************************************************
//*********************************************************************
etl::ibasic_string<T>& insert(size_type position, size_type n, value_type c)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
insert(begin() + position, n, c);
return *this;
}
//*********************************************************************
//*********************************************************************
etl::ibasic_string<T>& erase(size_type position, size_type length_ = npos)
{
ETL_ASSERT_CHECK_EXTRA(position <= size(), ETL_ERROR(string_out_of_bounds));
// Limit the length.
length_ = etl::min(length_, size() - position);
erase(begin() + position, begin() + position + length_);
return *this;
}
//*********************************************************************
//*********************************************************************
iterator erase(iterator i_element)
{
ETL_ASSERT_CHECK_EXTRA(cbegin() <= i_element && i_element < cend(), ETL_ERROR(string_out_of_bounds));
etl::mem_move(i_element + 1, end(), i_element);
p_buffer[--current_size] = 0;
return i_element;
}
//*********************************************************************
//*********************************************************************
iterator erase(const_iterator i_element)
{
ETL_ASSERT_CHECK_EXTRA(cbegin() <= i_element && i_element < cend(), ETL_ERROR(string_out_of_bounds));
iterator i_element_(to_iterator(i_element));
etl::mem_move(i_element + 1, end(), i_element_);
p_buffer[--current_size] = 0;
return i_element_;
}
//*********************************************************************
//*********************************************************************
iterator erase(const_iterator first, const_iterator last)
{
ETL_ASSERT_CHECK_EXTRA(cbegin() <= first && first <= last && last <= cend(), ETL_ERROR(string_out_of_bounds));
iterator first_ = to_iterator(first);
iterator last_ = to_iterator(last);
if (first_ == last_)
{
return first_;
}
etl::mem_move(last_, end(), first_);
size_type n_delete = static_cast<size_type>(etl::distance(first_, last_));
current_size -= n_delete;
p_buffer[current_size] = 0;
cleanup();
return first_;
}
//*********************************************************************
//*********************************************************************
const_pointer c_str() const
{
return p_buffer;
}
//*********************************************************************
//*********************************************************************
size_type copy(pointer dest, size_type count, size_type pos = 0) const
{
if (pos < size())
{
if (count != npos)
{
count = etl::min(count, size() - pos);
}
else
{
count = size() - pos;
}
etl::mem_move(p_buffer + pos, count, dest);
return count;
}
else
{
return 0U;
}
}
//*********************************************************************
//*********************************************************************
size_type find(const ibasic_string<T>& str, size_type pos = 0) const
{
return find_impl(str.begin(), str.end(), str.size(), pos);
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
size_type find(const etl::basic_string_view<T, TOtherTraits>& view, size_type pos = 0) const
{
return find_impl(view.begin(), view.end(), view.size(), pos);
}
//*********************************************************************
//*********************************************************************
size_type find(const_pointer s, size_type pos = 0) const
{
size_t sz = etl::strlen(s);
return find_impl(s, s + sz, sz, pos);
}
//*********************************************************************
//*********************************************************************
size_type find(const_pointer s, size_type pos, size_type n) const
{
return find_impl(s, s + n, n, pos);
}
//*********************************************************************
//*********************************************************************
size_type find(T c, size_type position = 0) const
{
const_iterator i = etl::find(begin() + position, end(), c);
if (i != end())
{
return static_cast<size_type>(etl::distance(begin(), i));
}
else
{
return npos;
}
}
//*********************************************************************
//*********************************************************************
size_type rfind(const ibasic_string<T>& str, size_type position = npos) const
{
return rfind_impl(str.rbegin(), str.rend(), str.size(), position);
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
size_type rfind(const etl::basic_string_view<T, TOtherTraits>& view, size_type pos = 0) const
{
return rfind_impl(view.rbegin(), view.rend(), view.size(), pos);
}
//*********************************************************************
//*********************************************************************
size_type rfind(const_pointer s, size_type position = npos) const
{
size_type len = etl::strlen(s);
const_reverse_iterator srbegin(s + len);
const_reverse_iterator srend(s);
return rfind_impl(srbegin, srend, len, position);
}
//*********************************************************************
//*********************************************************************
size_type rfind(const_pointer s, size_type position, size_type length_) const
{
const_reverse_iterator srbegin(s + length_);
const_reverse_iterator srend(s);
return rfind_impl(srbegin, srend, length_, position);
}
//*********************************************************************
//*********************************************************************
size_type rfind(T c, size_type position = npos) const
{
if (position >= size())
{
position = size();
}
position = size() - position;
const_reverse_iterator i = etl::find(rbegin() + static_cast<difference_type>(position), rend(), c);
if (i != rend())
{
return size() - static_cast<size_type>(etl::distance(rbegin(), i)) - 1;
}
else
{
return npos;
}
}
//*********************************************************************
//*********************************************************************
bool contains(const etl::ibasic_string<T>& str) const
{
return find(str) != npos;
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
bool contains(const etl::basic_string_view<T, TOtherTraits>& view) const
{
return find(view) != npos;
}
//*********************************************************************
//*********************************************************************
bool contains(const_pointer s) const
{
return find(s) != npos;
}
//*********************************************************************
//*********************************************************************
bool contains(value_type c) const
{
return find(c) != npos;
}
//*********************************************************************
//*********************************************************************
bool starts_with(const etl::ibasic_string<T>& str) const
{
return compare(0, str.size(), str) == 0;
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
bool starts_with(const etl::basic_string_view<T, TOtherTraits>& view) const
{
return compare(0, view.size(), view) == 0;
}
//*********************************************************************
//*********************************************************************
bool starts_with(const_pointer s) const
{
size_t len = etl::strlen(s);
return compare(0, len, s, len) == 0;
}
//*********************************************************************
//*********************************************************************
bool starts_with(value_type c) const
{
return !empty() && (front() == c);
}
//*********************************************************************
//*********************************************************************
bool ends_with(const etl::ibasic_string<T>& str) const
{
if (str.size() > size())
{
return false;
}
return compare(size() - str.size(), str.size(), str) == 0;
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
bool ends_with(const etl::basic_string_view<T, TOtherTraits>& view) const
{
if (view.size() > size())
{
return false;
}
return compare(size() - view.size(), view.size(), view) == 0;
}
//*********************************************************************
//*********************************************************************
bool ends_with(const_pointer s) const
{
size_t len = etl::strlen(s);
if (len > size())
{
return false;
}
return compare(size() - len, len, s, len) == 0;
}
//*********************************************************************
//*********************************************************************
bool ends_with(value_type c) const
{
return !empty() && (back() == c);
}
//*********************************************************************
//*********************************************************************
ibasic_string& replace(size_type position, size_type length_, const ibasic_string& str)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
// Limit the length.
length_ = etl::min(length_, size() - position);
return replace_impl(begin() + position, begin() + position + length_, str.begin(), str.size(), str.is_truncated());
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view<T, TOtherTraits>& view)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
// Limit the length.
length_ = etl::min(length_, size() - position);
return replace_impl(begin() + position, begin() + position + length_, view.begin(), view.size(), false);
}
//*********************************************************************
//*********************************************************************
ibasic_string& replace(const_iterator first, const_iterator last, const ibasic_string& str)
{
return replace_impl(first, last, str.begin(), str.size(), str.is_truncated());
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
ibasic_string& replace(const_iterator first, const_iterator last, const etl::basic_string_view<T, TOtherTraits>& view)
{
return replace_impl(first, last, view.begin(), view.size(), false);
}
//*********************************************************************
//*********************************************************************
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));
// Limit the lengths.
length_ = etl::min(length_, size() - position);
sublength = etl::min(sublength, str.size() - subposition);
return replace_impl(begin() + position, begin() + position + length_, str.begin() + subposition, sublength, str.is_truncated());
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
ibasic_string& replace(size_type position, size_type length_, const etl::basic_string_view<T, TOtherTraits>& view, size_type subposition,
size_type sublength)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds));
// Limit the lengths.
length_ = etl::min(length_, size() - position);
sublength = etl::min(sublength, view.size() - subposition);
return replace_impl(begin() + position, begin() + position + length_, view.begin() + subposition, sublength, false);
}
//*********************************************************************
//*********************************************************************
ibasic_string& replace(size_type position, size_type length_, const_pointer s)
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
// Limit the length.
length_ = etl::min(length_, size() - position);
return replace_impl(begin() + position, begin() + position + length_, s, etl::strlen(s), false);
}
//*********************************************************************
//*********************************************************************
ibasic_string& replace(const_iterator first, const_iterator last, const_pointer s, size_type n)
{
return replace_impl(first, last, s, n, false);
}
//*********************************************************************
//*********************************************************************
template <typename TIterator>
typename etl::enable_if<etl::is_same<TIterator, const_pointer>::value, ibasic_string>::type& replace(const_iterator first, const_iterator last,
TIterator s)
{
return replace_impl(first, last, s, etl::strlen(s), false);
}
//*********************************************************************
//*********************************************************************
template <size_t Size>
ibasic_string& replace(const_iterator first, const_iterator last, const value_type (&literal)[Size])
{
return replace_impl(first, last, literal, Size, false);
}
//*********************************************************************
//*********************************************************************
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));
// Limit the length.
length_ = etl::min(length_, size() - position);
return replace_impl(begin() + position, begin() + position + length_, s, n, false);
}
//*********************************************************************
//*********************************************************************
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));
// Limit the length.
length_ = etl::min(length_, size() - position);
// Erase the bit we want to replace.
erase(position, length_);
// Insert the new stuff.
insert(position, n, c);
return *this;
}
//*********************************************************************
//*********************************************************************
ibasic_string& replace(const_iterator first, const_iterator last, size_type n, value_type c)
{
// Quick hack, as iterators are pointers.
iterator first_ = to_iterator(first);
iterator last_ = to_iterator(last);
// Erase the bit we want to replace.
erase(first_, last_);
// Insert the new stuff.
insert(first_, n, c);
return *this;
}
//*********************************************************************
//*********************************************************************
template <typename TIterator>
ibasic_string& replace(const_iterator first, const_iterator last, TIterator first_replace, TIterator last_replace)
{
// Quick hack, as iterators are pointers.
iterator first_ = to_iterator(first);
iterator last_ = to_iterator(last);
// Erase the bit we want to replace.
erase(first_, last_);
// Insert the new stuff.
insert(first_, first_replace, last_replace);
return *this;
}
//*************************************************************************
//*************************************************************************
int compare(const ibasic_string& str) const
{
return compare(p_buffer, p_buffer + size(), str.p_buffer, str.p_buffer + str.size());
}
//*************************************************************************
//*************************************************************************
template <typename TOtherTraits>
int compare(const etl::basic_string_view<T, TOtherTraits>& view) const
{
return compare(p_buffer, p_buffer + size(), view.data(), view.data() + view.size());
}
//*************************************************************************
//*************************************************************************
int compare(size_type position, size_type length_, const ibasic_string& str) const
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
// Limit the length.
length_ = etl::min(length_, size() - position);
return compare(p_buffer + position, p_buffer + position + length_, str.p_buffer, str.p_buffer + str.size());
}
//*************************************************************************
//*************************************************************************
template <typename TOtherTraits>
int compare(size_type position, size_type length_, const etl::basic_string_view<T, TOtherTraits>& view) const
{
return compare(p_buffer + position, p_buffer + position + length_, view.data(), view.data() + view.size());
}
//*************************************************************************
//*************************************************************************
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));
// Limit the lengths.
length_ = etl::min(length_, size() - position);
sublength = etl::min(sublength, str.size() - subposition);
return compare(p_buffer + position, p_buffer + position + length_, str.p_buffer + subposition, str.p_buffer + subposition + sublength);
}
//*************************************************************************
//*************************************************************************
template <typename TOtherTraits>
int compare(size_type position, size_type length_, const etl::basic_string_view<T, TOtherTraits>& view, size_type subposition,
size_type sublength) const
{
ETL_ASSERT(position <= size(), ETL_ERROR(string_out_of_bounds));
ETL_ASSERT(subposition <= view.size(), ETL_ERROR(string_out_of_bounds));
// Limit the lengths.
length_ = etl::min(length_, size() - position);
sublength = etl::min(sublength, view.size() - subposition);
return compare(p_buffer + position, p_buffer + position + length_, view.data() + subposition, view.data() + subposition + sublength);
}
//*************************************************************************
//*************************************************************************
int compare(const value_type* s) const
{
return compare(p_buffer, p_buffer + size(), s, s + etl::strlen(s));
}
//*************************************************************************
//*************************************************************************
int compare(size_type position, size_type length_, const_pointer s) const
{
return compare(p_buffer + position, p_buffer + position + length_, s, s + etl::strlen(s));
}
//*************************************************************************
//*************************************************************************
int compare(size_type position, size_type length_, const_pointer s, size_type n) const
{
return compare(p_buffer + position, p_buffer + position + length_, s, s + n);
}
//*********************************************************************
//*********************************************************************
size_type find_first_of(const ibasic_string<T>& str, size_type position = 0) const
{
return find_first_of(str.c_str(), position, str.size());
}
//*********************************************************************
//*********************************************************************
size_type find_first_of(const_pointer s, size_type position = 0) const
{
return find_first_of(s, position, etl::strlen(s));
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
size_type find_first_of(const etl::basic_string_view<T, TOtherTraits>& view, size_type position = 0) const
{
return find_first_of(view.data(), position, view.size());
}
//*********************************************************************
//*********************************************************************
size_type find_first_of(const_pointer s, size_type position, size_type n) const
{
if (position < size())
{
for (size_type i = position; i < size(); ++i)
{
for (size_type j = 0; j < n; ++j)
{
if (p_buffer[i] == s[j])
{
return i;
}
}
}
}
return npos;
}
//*********************************************************************
//*********************************************************************
size_type find_first_of(value_type c, size_type position = 0) const
{
if (position < size())
{
for (size_type i = position; i < size(); ++i)
{
if (p_buffer[i] == c)
{
return i;
}
}
}
return npos;
}
//*********************************************************************
//*********************************************************************
size_type find_last_of(const ibasic_string<T>& str, size_type position = npos) const
{
return find_last_of(str.c_str(), position, str.size());
}
//*********************************************************************
//*********************************************************************
size_type find_last_of(const_pointer s, size_type position = npos) const
{
return find_last_of(s, position, etl::strlen(s));
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
size_type find_last_of(const etl::basic_string_view<T, TOtherTraits>& view, size_type position = npos) const
{
return find_last_of(view.data(), position, view.size());
}
//*********************************************************************
//*********************************************************************
size_type find_last_of(const_pointer s, size_type position, size_type n) const
{
if (empty())
{
return npos;
}
position = etl::min(position, size() - 1);
const_reverse_iterator it = rbegin() + static_cast<difference_type>(size() - position - 1);
while (it != rend())
{
for (size_type j = 0; j < n; ++j)
{
if (p_buffer[position] == s[j])
{
return position;
}
}
++it;
--position;
}
return npos;
}
//*********************************************************************
//*********************************************************************
size_type find_last_of(value_type c, size_type position = npos) const
{
if (empty())
{
return npos;
}
position = etl::min(position, size() - 1);
const_reverse_iterator it = rbegin() + static_cast<difference_type>(size() - position - 1);
while (it != rend())
{
if (p_buffer[position] == c)
{
return position;
}
++it;
--position;
}
return npos;
}
//*********************************************************************
//*********************************************************************
size_type find_first_not_of(const ibasic_string<T>& str, size_type position = 0) const
{
return find_first_not_of(str.c_str(), position, str.size());
}
//*********************************************************************
//*********************************************************************
size_type find_first_not_of(const_pointer s, size_type position = 0) const
{
return find_first_not_of(s, position, etl::strlen(s));
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
size_type find_first_not_of(const etl::basic_string_view<T, TOtherTraits>& view, size_type position = 0) const
{
return find_first_not_of(view.data(), position, view.size());
}
//*********************************************************************
//*********************************************************************
size_type find_first_not_of(const_pointer s, size_type position, size_type n) const
{
if (position < size())
{
for (size_type i = position; i < size(); ++i)
{
bool found = false;
for (size_type j = 0; j < n; ++j)
{
if (p_buffer[i] == s[j])
{
found = true;
}
}
if (!found)
{
return i;
}
}
}
return npos;
}
//*********************************************************************
//*********************************************************************
size_type find_first_not_of(value_type c, size_type position = 0) const
{
if (position < size())
{
for (size_type i = position; i < size(); ++i)
{
if (*(p_buffer + i) != c)
{
return i;
}
}
}
return npos;
}
//*********************************************************************
//*********************************************************************
size_type find_last_not_of(const ibasic_string<T>& str, size_type position = npos) const
{
return find_last_not_of(str.c_str(), position, str.size());
}
//*********************************************************************
//*********************************************************************
size_type find_last_not_of(const_pointer s, size_type position = npos) const
{
return find_last_not_of(s, position, etl::strlen(s));
}
//*********************************************************************
//*********************************************************************
template <typename TOtherTraits>
size_type find_last_not_of(const etl::basic_string_view<T, TOtherTraits>& view, size_type position = npos) const
{
return find_last_not_of(view.data(), position, view.size());
}
//*********************************************************************
//*********************************************************************
size_type find_last_not_of(const_pointer s, size_type position, size_type n) const
{
if (empty())
{
return npos;
}
position = etl::min(position, size() - 1);
const_reverse_iterator it = rbegin() + static_cast<difference_type>(size() - position - 1);
while (it != rend())
{
bool found = false;
for (size_type j = 0; j < n; ++j)
{
if (p_buffer[position] == s[j])
{
found = true;
}
}
if (!found)
{
return position;
}
++it;
--position;
}
return npos;
}
//*********************************************************************
//
//*********************************************************************
size_type find_last_not_of(value_type c, size_type position = npos) const
{
if (empty())
{
return npos;
}
position = etl::min(position, size() - 1);
const_reverse_iterator it = rbegin() + static_cast<difference_type>(size() - position - 1);
while (it != rend())
{
if (p_buffer[position] != c)
{
return position;
}
++it;
--position;
}
return npos;
}
//*************************************************************************
//*************************************************************************
ibasic_string& operator=(const ibasic_string& rhs)
{
if (&rhs != this)
{
assign(rhs);
}
return *this;
}
//*************************************************************************
//*************************************************************************
ibasic_string& operator=(const_pointer rhs)
{
assign(rhs);
return *this;
}
//*************************************************************************
//*************************************************************************
template <typename TOtherTraits>
ibasic_string& operator=(const etl::basic_string_view<T, TOtherTraits>& view)
{
assign(view);
return *this;
}
//*************************************************************************
//*************************************************************************
ibasic_string& operator+=(const ibasic_string& rhs)
{
append(rhs);
return *this;
}
//*************************************************************************
//*************************************************************************
template <typename TOtherTraits>
ibasic_string& operator+=(const etl::basic_string_view<T, TOtherTraits>& rhs)
{
append(rhs);
return *this;
}
//*************************************************************************
//*************************************************************************
ibasic_string& operator+=(const_pointer rhs)
{
append(rhs);
return *this;
}
//*************************************************************************
//*************************************************************************
ibasic_string& operator+=(T rhs)
{
append(size_type(1), rhs);
return *this;
}
#if ETL_HAS_ISTRING_REPAIR
//*************************************************************************
//*************************************************************************
virtual void repair() = 0;
#endif
//*********************************************************************
//*********************************************************************
void initialize_free_space()
{
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(false);
#endif
etl::mem_set(&p_buffer[current_size], &p_buffer[CAPACITY + 1U], char(0));
}
//*********************************************************************
//*********************************************************************
void trim_to_terminator()
{
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(p_buffer[CAPACITY] != T(0));
#endif
p_buffer[CAPACITY] = T(0); // Ensure a terminating null.
current_size = etl::strlen(p_buffer);
}
protected:
//*********************************************************************
//*********************************************************************
ibasic_string(T* p_buffer_, size_type MAX_SIZE_)
: string_base(MAX_SIZE_)
, p_buffer(p_buffer_)
{
}
//*********************************************************************
//*********************************************************************
void initialise()
{
current_size = 0U;
p_buffer[0] = 0;
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated(false);
#endif
}
//*************************************************************************
//*************************************************************************
void repair_buffer(T* p_buffer_)
{
p_buffer = p_buffer_;
}
private:
//*********************************************************************
//*********************************************************************
ibasic_string& replace_impl(const_iterator first, const_iterator last, const_pointer s, size_type length, bool other_truncated)
{
// Trivial no-op cases
if ((first == last) && (s == ETL_NULLPTR || length == 0U))
{
return *this;
}
// Invalid range?
if (first > last)
{
return *this;
}
// Quick hack, as iterators are pointers.
iterator first_ = to_iterator(first);
iterator last_ = to_iterator(last);
// If source pointer is inside our current buffer we take the safe
// (legacy) path to preserve correct semantics for overlapping self use.
const bool source_overlaps = (s != ETL_NULLPTR) && (s >= p_buffer) && (s < p_buffer + current_size);
if (source_overlaps)
{
// Legacy behaviour (may be slightly less efficient, but correct).
// Erase range then insert up to 'length' characters from 's'.
erase(first_, last_);
if (s != ETL_NULLPTR && length != 0U)
{
// 'insert' can truncate & set flags.
insert(p_buffer + (first_ - p_buffer), s, s + length);
}
return *this;
}
// Calculate the remove parameters.
const size_type remove_index = size_type(first_ - p_buffer);
const size_type remove_length = size_type(last_ - first_);
const size_type free_space = CAPACITY - remove_index; // Free space is the space from the remove
// index to the end of the buffer.
size_type insert_length = (s == ETL_NULLPTR) ? 0U : length;
// Limit the insert length to the available free space.
if (insert_length > free_space)
{
insert_length = free_space;
}
// Calculate the tail parameters.
size_type tail_index = remove_index + remove_length;
size_type tail_length = current_size - tail_index;
size_type tail_space = free_space - insert_length;
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated((insert_length != length) || (tail_space < tail_length) || is_truncated() || other_truncated);
#endif
// The some or all of tail may be erased if the space remaining for it is
// smaller than the tail length.
if (tail_space < tail_length)
{
tail_length = tail_space;
}
// Three cases: same size, grow, shrink.
if (insert_length == remove_length)
{
// Size unchanged: simple overwrite.
etl::mem_copy(s, insert_length, &p_buffer[remove_index]);
}
else if (insert_length > remove_length)
{
// Grow: shift tail right then copy.
// Shift tail (backwards to handle overlap safely).
etl::mem_move(&p_buffer[tail_index], tail_length, &p_buffer[remove_index + insert_length]);
// Copy new data.
etl::mem_copy(s, insert_length, &p_buffer[remove_index]);
}
else // insert_length < remove_length
{
// Shrink: overwrite then shift tail left.
// Copy new data.
etl::mem_copy(s, insert_length, &p_buffer[remove_index]);
// Move tail left.
etl::mem_move(&p_buffer[tail_index], tail_length, &p_buffer[remove_index + insert_length]);
}
current_size = remove_index + insert_length + tail_length;
p_buffer[current_size] = value_type(0);
cleanup();
return *this;
}
//*************************************************************************
//*************************************************************************
static int compare(const_pointer first1, const_pointer last1, const_pointer first2, const_pointer last2)
{
typedef typename etl::make_unsigned<value_type>::type type;
difference_type length1 = etl::distance(first1, last1);
difference_type length2 = etl::distance(first2, last2);
difference_type compare_length = etl::min(length1, length2);
// First compare the string characters.
while (compare_length != 0)
{
if (static_cast<type>(*first1) < static_cast<type>(*first2))
{
// Compared character is lower.
return -1;
}
else if (static_cast<type>(*first1) > static_cast<type>(*first2))
{
// Compared character is higher.
return 1;
}
++first1;
++first2;
--compare_length;
}
// Then compare the string lengths.
if (length1 < length2)
{
// First string is shorter.
return -1;
}
if (length1 > length2)
{
// First string is longer.
return 1;
}
// Strings are the same length.
return 0;
}
//*************************************************************************
//*************************************************************************
void cleanup()
{
#if ETL_HAS_STRING_CLEAR_AFTER_USE
if (is_secure())
{
etl::memory_clear_range(&p_buffer[current_size], &p_buffer[CAPACITY]);
}
#endif
}
//*************************************************************************
//*************************************************************************
ibasic_string(const ibasic_string&);
//*************************************************************************
//*************************************************************************
T* p_buffer;
//*************************************************************************
//*************************************************************************
#if defined(ETL_POLYMORPHIC_STRINGS) || defined(ETL_POLYMORPHIC_CONTAINERS) || defined(ETL_ISTRING_REPAIR_ENABLE)
public:
virtual
#else
protected:
#endif
~ibasic_string()
{
#if ETL_HAS_STRING_CLEAR_AFTER_USE
if (is_secure())
{
clear();
}
#endif
}
protected:
//*************************************************************************
//*************************************************************************
iterator to_iterator(const_iterator itr) const
{
return const_cast<iterator>(itr);
}
//*************************************************************************
//*************************************************************************
bool is_within_buffer(const_pointer ptr) const
{
return (ptr >= p_buffer) && (ptr <= (p_buffer + CAPACITY));
}
private:
//*********************************************************************
//*********************************************************************
template <typename TIterator1>
static
typename etl::enable_if< etl::is_pointer<typename etl::remove_reference<TIterator1>::type>::value
&& sizeof(typename etl::remove_pointer< typename etl::remove_cvref<TIterator1>::type>::type) == sizeof(value_type),
iterator>::type
copy_characters(TIterator1 from, size_t n, iterator to)
{
etl::mem_move(from, n, to);
return to + n;
}
//*********************************************************************
//*********************************************************************
template <typename TIterator1>
static
typename etl::enable_if< !(etl::is_pointer<typename etl::remove_reference<TIterator1>::type>::value
&& sizeof(typename etl::remove_pointer< typename etl::remove_cvref<TIterator1>::type>::type) == sizeof(value_type)),
iterator>::type
copy_characters(TIterator1 from, size_t n, iterator to)
{
#include "etl/private/diagnostic_stringop_overflow_push.h"
size_t count = 0;
while (count != n)
{
*to++ = static_cast<value_type>(*from++);
++count;
}
#include "etl/private/diagnostic_pop.h"
return to;
}
//*********************************************************************
//*********************************************************************
template <typename TIterator>
typename etl::enable_if< !etl::is_pointer< typename etl::remove_reference<TIterator>::type>::value>::type
append_impl(iterator position, TIterator first, TIterator last, bool truncated, bool secure)
{
difference_type start = etl::distance(p_buffer, position);
difference_type count = etl::distance(first, last);
difference_type free_space = etl::distance(position, p_buffer + CAPACITY);
#if ETL_IS_DEBUG_BUILD
ETL_ASSERT(count >= 0, ETL_ERROR(string_iterator));
#endif
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated((count > free_space) || this->is_truncated() || truncated);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT(is_truncated() == false, ETL_ERROR(string_truncation));
#endif
#else
(void)truncated;
#endif
#if ETL_HAS_STRING_CLEAR_AFTER_USE
if (secure)
{
set_secure();
}
#else
(void)secure;
#endif
// Limit the actual distance to the capacity.
count = etl::min(count, free_space);
copy_characters(first, size_t(count), position);
current_size = size_t(start + count);
p_buffer[current_size] = 0;
cleanup();
}
//*********************************************************************
//*********************************************************************
void append_impl(iterator position, const_pointer src, bool truncated, bool secure)
{
if (src == ETL_NULLPTR)
{
clear();
return;
}
append_impl(position, src, get_string_length(src), truncated, secure);
}
//*********************************************************************
//*********************************************************************
void append_impl(iterator position, const_pointer src, size_t length, bool truncated, bool secure)
{
size_t start = static_cast<size_t>(etl::distance(p_buffer, position));
size_t free_space = static_cast<size_t>(etl::distance(position, p_buffer + CAPACITY));
size_t count = etl::min(length, free_space);
#if ETL_IS_DEBUG_BUILD
ETL_ASSERT(start <= CAPACITY, ETL_ERROR(string_iterator));
#endif
etl::mem_move(src, count, position);
current_size = start + count;
p_buffer[current_size] = 0;
#if ETL_HAS_STRING_TRUNCATION_CHECKS
set_truncated((length > free_space) || truncated);
#if ETL_HAS_ERROR_ON_STRING_TRUNCATION
ETL_ASSERT(is_truncated() == false, ETL_ERROR(string_truncation));
#endif
#else
(void)truncated;
#endif
#if ETL_HAS_STRING_CLEAR_AFTER_USE
if (secure)
{
set_secure();
}
#else
(void)secure;
#endif
cleanup();
}
//*********************************************************************
//*********************************************************************
template <typename TIterator>
typename etl::enable_if< etl::is_pointer< typename etl::remove_reference<TIterator>::type>::value>::type
append_impl(iterator position, TIterator first, TIterator last, bool truncated, bool secure)
{
append_impl(position, first, size_t(etl::distance(first, last)), truncated || is_truncated(), secure);
}
//*************************************************************************
//*************************************************************************
template <typename TIterator>
size_type find_impl(TIterator first, TIterator last, size_type sz, size_type pos = 0) const
{
if ((pos + sz) > size())
{
return npos;
}
const_iterator iposition = etl::search(begin() + pos, end(), first, last);
if (iposition == end())
{
return npos;
}
else
{
return static_cast<size_type>(etl::distance(begin(), iposition));
}
}
//*************************************************************************
//*************************************************************************
template <typename TIterator>
size_type rfind_impl(TIterator rfirst, TIterator rlast, size_type sz, size_type pos = 0) const
{
if (sz > size())
{
return npos;
}
if (pos >= size())
{
pos = size();
}
pos = size() - pos;
const_reverse_iterator iposition = etl::search(rbegin() + static_cast<difference_type>(pos), rend(), rfirst, rlast);
if (iposition == rend())
{
return npos;
}
else
{
return size() - sz - static_cast<size_type>(etl::distance(rbegin(), iposition));
}
}
//*********************************************************************
//*********************************************************************
template <typename U>
static typename etl::enable_if<sizeof(U) == sizeof(char), size_t>::type get_string_length(const U* str)
{
return ::strlen(reinterpret_cast<const char*>(str));
}
#if ETL_USING_LIBC_WCHAR_H
//*********************************************************************
//*********************************************************************
template <typename U>
static typename etl::enable_if<sizeof(U) == sizeof(wchar_t), size_t>::type get_string_length(const U* str)
{
return ::wcslen(reinterpret_cast<const wchar_t*>(str));
}
#endif
//*********************************************************************
//*********************************************************************
template <typename U>
static
#if ETL_USING_LIBC_WCHAR_H
typename etl::enable_if<(sizeof(U) != sizeof(char)) && (sizeof(U) != sizeof(wchar_t)), size_t>::type
#else
typename etl::enable_if<(sizeof(U) != sizeof(char)), size_t>::type
#endif
get_string_length(const U* str)
{
if (str == ETL_NULLPTR)
{
return 0;
}
const U* end = str;
while (*end++ != 0)
{
// Do nothing.
}
return size_t(end - str) - 1;
}
};
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator==(const etl::ibasic_string<T>& lhs, const etl::ibasic_string<T>& rhs)
{
return (lhs.size() == rhs.size()) && etl::equal(lhs.begin(), lhs.end(), rhs.begin());
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator==(const etl::ibasic_string<T>& lhs, const T* rhs)
{
return (lhs.size() == etl::strlen(rhs)) && etl::equal(lhs.begin(), lhs.end(), rhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator==(const T* lhs, const etl::ibasic_string<T>& rhs)
{
return (rhs.size() == etl::strlen(lhs)) && etl::equal(rhs.begin(), rhs.end(), lhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator!=(const etl::ibasic_string<T>& lhs, const etl::ibasic_string<T>& rhs)
{
return !(lhs == rhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator!=(const etl::ibasic_string<T>& lhs, const T* rhs)
{
return !(lhs == rhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator!=(const T* lhs, const etl::ibasic_string<T>& rhs)
{
return !(lhs == rhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator<(const etl::ibasic_string<T>& lhs, const etl::ibasic_string<T>& rhs)
{
return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs.begin(), rhs.end());
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator<(const etl::ibasic_string<T>& lhs, const T* rhs)
{
return etl::lexicographical_compare(lhs.begin(), lhs.end(), rhs, rhs + etl::strlen(rhs));
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator<(const T* lhs, const etl::ibasic_string<T>& rhs)
{
return etl::lexicographical_compare(lhs, lhs + etl::strlen(lhs), rhs.begin(), rhs.end());
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator>(const etl::ibasic_string<T>& lhs, const etl::ibasic_string<T>& rhs)
{
return (rhs < lhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator>(const etl::ibasic_string<T>& lhs, const T* rhs)
{
return (rhs < lhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator>(const T* lhs, const etl::ibasic_string<T>& rhs)
{
return (rhs < lhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator<=(const etl::ibasic_string<T>& lhs, const etl::ibasic_string<T>& rhs)
{
return !(lhs > rhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator<=(const etl::ibasic_string<T>& lhs, const T* rhs)
{
return !(lhs > rhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator<=(const T* lhs, const etl::ibasic_string<T>& rhs)
{
return !(lhs > rhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator>=(const etl::ibasic_string<T>& lhs, const etl::ibasic_string<T>& rhs)
{
return !(lhs < rhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator>=(const etl::ibasic_string<T>& lhs, const T* rhs)
{
return !(lhs < rhs);
}
//***************************************************************************
//***************************************************************************
template <typename T>
bool operator>=(const T* lhs, const etl::ibasic_string<T>& rhs)
{
return !(lhs < rhs);
}
//***************************************************************************
//***************************************************************************
#if ETL_USING_STD_OSTREAM
template <typename T>
std::basic_ostream<T, std::char_traits<T> >& operator<<(std::basic_ostream<T, std::char_traits<T> >& os, const etl::ibasic_string<T>& str)
{
os.write(str.data(), static_cast<std::streamsize>(str.size()));
return os;
}
#endif
} // namespace etl
#include "private/minmax_pop.h"
#endif
algorithm.h
alignment.h
array.h
binary.h
etl::basic_string_view
String view.
Definition string_view.h:117
etl::basic_string_view::cbegin
ETL_CONSTEXPR const_iterator cbegin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the array.
Definition string_view.h:239
etl::basic_string_view::size
ETL_CONSTEXPR size_t size() const ETL_NOEXCEPT
Returns the size of the array.
Definition string_view.h:307
etl::basic_string_view::rend
ETL_CONSTEXPR const_reverse_iterator rend() const ETL_NOEXCEPT
Returns a const reverse iterator to the end of the array.
Definition string_view.h:279
etl::basic_string_view::data
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::basic_string_view::end
ETL_CONSTEXPR const_iterator end() const ETL_NOEXCEPT
Returns a const iterator to the end of the array.
Definition string_view.h:247
etl::basic_string_view::begin
ETL_CONSTEXPR const_iterator begin() const ETL_NOEXCEPT
Returns a const iterator to the beginning of the array.
Definition string_view.h:231
etl::basic_string_view::rbegin
ETL_CONSTEXPR const_reverse_iterator rbegin() const ETL_NOEXCEPT
Returns a const reverse iterator to the reverse beginning of the array.
Definition string_view.h:263
etl::flags
Definition flags.h:51
etl::ibasic_string
Definition basic_string.h:335
etl::ibasic_string::compare
int compare(size_type position, size_type length_, const ibasic_string &str) const
Compare position / length with string.
Definition basic_string.h:1911
etl::ibasic_string::append
ibasic_string & append(TIterator first, TIterator last)
Definition basic_string.h:854
etl::ibasic_string::find_last_of
size_type find_last_of(const_pointer s, size_type position=npos) const
Definition basic_string.h:2079
etl::ibasic_string::rfind
size_type rfind(const_pointer s, size_type position=npos) const
Definition basic_string.h:1517
etl::ibasic_string::replace
ibasic_string & replace(const_iterator first, const_iterator last, const etl::basic_string_view< T, TOtherTraits > &view)
Definition basic_string.h:1735
etl::ibasic_string::replace
etl::enable_if< etl::is_same< TIterator, const_pointer >::value, ibasic_string >::type & replace(const_iterator first, const_iterator last, TIterator s)
Replace characters from 'first' to 'last' with pointed to string.
Definition basic_string.h:1805
etl::ibasic_string::insert
etl::ibasic_string< T > & insert(size_type position, const etl::ibasic_string< T > &str)
Definition basic_string.h:1174
etl::ibasic_string::replace
ibasic_string & replace(const_iterator first, const_iterator last, const value_type(&literal)[Size])
Replace characters from 'first' 'last' with pointed to literal string.
Definition basic_string.h:1815
etl::ibasic_string::find_last_not_of
size_type find_last_not_of(const_pointer s, size_type position=npos) const
Definition basic_string.h:2258
etl::ibasic_string::find
size_type find(const_pointer s, size_type pos=0) const
Definition basic_string.h:1454
etl::ibasic_string::operator=
ibasic_string & operator=(const ibasic_string &rhs)
Assignment operator.
Definition basic_string.h:2346
etl::ibasic_string::append
ibasic_string & append(const ibasic_string &str, size_type subposition, size_type sublength=npos)
Definition basic_string.h:834
etl::ibasic_string::rbegin
const_reverse_iterator rbegin() const
Definition basic_string.h:419
etl::ibasic_string::contains
bool contains(const etl::ibasic_string< T > &str) const
Checks that the string is within this string.
Definition basic_string.h:1569
etl::ibasic_string::operator[]
reference operator[](size_type i)
Definition basic_string.h:546
etl::ibasic_string::assign
void assign(const etl::ibasic_string< T > &other, size_type subposition, size_type sublength)
Definition basic_string.h:686
etl::ibasic_string::insert
etl::ibasic_string< T > & insert(size_type position, const etl::basic_string_view< T, TOtherTraits > &view, size_type subposition, size_type sublength)
Definition basic_string.h:1251
etl::ibasic_string::data_end
pointer data_end()
Definition basic_string.h:651
etl::ibasic_string::erase
iterator erase(const_iterator first, const_iterator last)
Definition basic_string.h:1369
etl::ibasic_string::insert
iterator insert(const_iterator position, TIterator first, TIterator last)
Definition basic_string.h:1071
etl::ibasic_string::is_within_buffer
bool is_within_buffer(const_pointer ptr) const
Checks if a pointer is within the buffer.
Definition basic_string.h:2694
etl::ibasic_string::contains
bool contains(value_type c) const
Checks that character is within this string.
Definition basic_string.h:1594
etl::ibasic_string::find_last_of
size_type find_last_of(const ibasic_string< T > &str, size_type position=npos) const
Definition basic_string.h:2069
etl::ibasic_string::find_first_of
size_type find_first_of(value_type c, size_type position=0) const
Definition basic_string.h:2048
etl::ibasic_string::starts_with
bool starts_with(const etl::ibasic_string< T > &str) const
Checks that the string is the start of this string.
Definition basic_string.h:1602
etl::ibasic_string::find
size_type find(T c, size_type position=0) const
Definition basic_string.h:1477
etl::ibasic_string::replace
ibasic_string & replace(size_type position, size_type length_, const etl::basic_string_view< T, TOtherTraits > &view, size_type subposition, size_type sublength)
Definition basic_string.h:1761
etl::ibasic_string::ends_with
bool ends_with(value_type c) const
Checks that the character is the end of this string.
Definition basic_string.h:1679
etl::ibasic_string::pop_back
void pop_back()
Definition basic_string.h:809
etl::ibasic_string::rfind
size_type rfind(const ibasic_string< T > &str, size_type position=npos) const
Definition basic_string.h:1496
etl::ibasic_string::contains
bool contains(const_pointer s) const
Checks that text is within this string.
Definition basic_string.h:1586
etl::ibasic_string::insert
etl::ibasic_string< T > & insert(size_type position, const etl::basic_string_view< T, TOtherTraits > &view)
Definition basic_string.h:1200
etl::ibasic_string::resize_and_overwrite
void resize_and_overwrite(size_type new_size, TOperation operation)
Resizes the string and overwrites to data using the operation.
Definition basic_string.h:506
etl::ibasic_string::initialize_free_space
void initialize_free_space()
Clears the free space to string terminator value.
Definition basic_string.h:2428
etl::ibasic_string::replace
ibasic_string & replace(size_type position, size_type length_, const_pointer s, size_type n)
Definition basic_string.h:1824
etl::ibasic_string::to_iterator
iterator to_iterator(const_iterator itr) const
Convert from const_iterator to iterator.
Definition basic_string.h:2686
etl::ibasic_string::replace
ibasic_string & replace(size_type position, size_type length_, size_type n, value_type c)
Replace characters from 'position' of 'length' with 'n' copies of 'c'.
Definition basic_string.h:1837
etl::ibasic_string::operator[]
const_reference operator[](size_type i) const
Definition basic_string.h:557
etl::ibasic_string::replace
ibasic_string & replace(const_iterator first, const_iterator last, const ibasic_string &str)
Definition basic_string.h:1723
etl::ibasic_string::find_first_of
size_type find_first_of(const ibasic_string< T > &str, size_type position=0) const
Definition basic_string.h:1992
etl::ibasic_string::find_first_of
size_type find_first_of(const etl::basic_string_view< T, TOtherTraits > &view, size_type position=0) const
Definition basic_string.h:2013
etl::ibasic_string::back
const_reference back() const
Definition basic_string.h:623
etl::ibasic_string::assign
void assign(const_pointer str, size_type n)
Definition basic_string.h:733
etl::ibasic_string::begin
const_iterator begin() const
Definition basic_string.h:365
etl::ibasic_string::find_last_of
size_type find_last_of(const_pointer s, size_type position, size_type n) const
Definition basic_string.h:2101
etl::ibasic_string::ends_with
bool ends_with(const etl::basic_string_view< T, TOtherTraits > &view) const
Checks that the view is the end of this string.
Definition basic_string.h:1651
etl::ibasic_string::rbegin
reverse_iterator rbegin()
Definition basic_string.h:410
etl::ibasic_string::replace
ibasic_string & replace(const_iterator first, const_iterator last, TIterator first_replace, TIterator last_replace)
Definition basic_string.h:1876
etl::ibasic_string::resize
void resize(size_type new_size)
Definition basic_string.h:465
etl::ibasic_string::find_last_not_of
size_type find_last_not_of(const_pointer s, size_type position, size_type n) const
Definition basic_string.h:2280
etl::ibasic_string::replace
ibasic_string & replace(size_type position, size_type length_, const etl::basic_string_view< T, TOtherTraits > &view)
Definition basic_string.h:1707
etl::ibasic_string::find_first_not_of
size_type find_first_not_of(const_pointer s, size_type position=0) const
Definition basic_string.h:2174
etl::ibasic_string::rfind
size_type rfind(T c, size_type position=npos) const
Definition basic_string.h:1545
etl::ibasic_string::erase
etl::ibasic_string< T > & erase(size_type position, size_type length_=npos)
Definition basic_string.h:1314
etl::ibasic_string::compare
int compare(const value_type *s) const
Compare with C string.
Definition basic_string.h:1966
etl::ibasic_string::compare
int compare(size_type position, size_type length_, const_pointer s) const
Compare position / length with C string.
Definition basic_string.h:1974
etl::ibasic_string::insert
iterator insert(const_iterator position, size_type n, T value)
Definition basic_string.h:981
etl::ibasic_string::append
ibasic_string & append(const etl::basic_string_view< T, TOtherTraits > &view)
Definition basic_string.h:889
etl::ibasic_string::at
const_reference at(size_type i) const
Definition basic_string.h:583
etl::ibasic_string::assign
void assign(const etl::basic_string_view< T, TOtherTraits > &view)
Assigns values to the string from a view.
Definition basic_string.h:742
etl::ibasic_string::operator+=
ibasic_string & operator+=(const_pointer rhs)
+= operator.
Definition basic_string.h:2401
etl::ibasic_string::clear
void clear()
Clears the string.
Definition basic_string.h:775
etl::ibasic_string::compare
int compare(size_type position, size_type length_, const ibasic_string &str, size_type subposition, size_type sublength) const
Compare position / length with string / subposition / sublength.
Definition basic_string.h:1933
etl::ibasic_string::rend
reverse_iterator rend()
Definition basic_string.h:428
etl::ibasic_string::operator=
ibasic_string & operator=(const etl::basic_string_view< T, TOtherTraits > &view)
Assignment operator.
Definition basic_string.h:2370
etl::ibasic_string::find_last_of
size_type find_last_of(const etl::basic_string_view< T, TOtherTraits > &view, size_type position=npos) const
Definition basic_string.h:2090
etl::ibasic_string::erase
iterator erase(iterator i_element)
Definition basic_string.h:1332
etl::ibasic_string::append
ibasic_string & append(const_pointer str, size_type n)
Definition basic_string.h:877
etl::ibasic_string::crend
const_reverse_iterator crend() const
Definition basic_string.h:455
etl::ibasic_string::contains
bool contains(const etl::basic_string_view< T, TOtherTraits > &view) const
Checks that the view is within this string.
Definition basic_string.h:1578
etl::ibasic_string::at
reference at(size_type i)
Definition basic_string.h:570
etl::ibasic_string::rfind
size_type rfind(const etl::basic_string_view< T, TOtherTraits > &view, size_type pos=0) const
Definition basic_string.h:1507
etl::ibasic_string::starts_with
bool starts_with(value_type c) const
Checks that the character is the start of this string.
Definition basic_string.h:1629
etl::ibasic_string::compare
int compare(const etl::basic_string_view< T, TOtherTraits > &view) const
Compare with etl::basic_string_view.
Definition basic_string.h:1903
etl::ibasic_string::~ibasic_string
~ibasic_string()
Destructor.
Definition basic_string.h:2671
etl::ibasic_string::find
size_type find(const_pointer s, size_type pos, size_type n) const
Definition basic_string.h:1467
etl::ibasic_string::find_first_of
size_type find_first_of(const_pointer s, size_type position=0) const
Definition basic_string.h:2002
etl::ibasic_string::replace
ibasic_string & replace(size_type position, size_type length_, const ibasic_string &str, size_type subposition, size_type sublength)
Definition basic_string.h:1744
etl::ibasic_string::begin
iterator begin()
Definition basic_string.h:356
etl::ibasic_string::end
iterator end()
Definition basic_string.h:374
etl::ibasic_string::replace
ibasic_string & replace(const_iterator first, const_iterator last, size_type n, value_type c)
Replace characters from 'first' of 'last' with 'n' copies of 'c'.
Definition basic_string.h:1856
etl::ibasic_string::replace
ibasic_string & replace(const_iterator first, const_iterator last, const_pointer s, size_type n)
Definition basic_string.h:1796
etl::ibasic_string::assign
void assign(TIterator first, TIterator last)
Definition basic_string.h:712
etl::ibasic_string::insert
etl::ibasic_string< T > & insert(size_type position, const etl::ibasic_string< T > &str, size_type subposition, size_type sublength)
Definition basic_string.h:1217
etl::ibasic_string::find
size_type find(const ibasic_string< T > &str, size_type pos=0) const
Definition basic_string.h:1433
etl::ibasic_string::push_back
void push_back(T value)
Definition basic_string.h:786
etl::ibasic_string::find_first_not_of
size_type find_first_not_of(const_pointer s, size_type position, size_type n) const
Definition basic_string.h:2196
etl::ibasic_string::crbegin
const_reverse_iterator crbegin() const
Definition basic_string.h:446
etl::ibasic_string::insert
iterator insert(const_iterator position, T value)
Definition basic_string.h:927
etl::ibasic_string::operator=
ibasic_string & operator=(const_pointer rhs)
Assignment operator.
Definition basic_string.h:2359
etl::ibasic_string::insert
etl::ibasic_string< T > & insert(size_type position, const_pointer s, size_type n)
Definition basic_string.h:1286
etl::ibasic_string::replace
ibasic_string & replace(size_type position, size_type length_, const ibasic_string &str)
Definition basic_string.h:1690
etl::ibasic_string::ibasic_string
ibasic_string(T *p_buffer_, size_type MAX_SIZE_)
Constructor.
Definition basic_string.h:2456
etl::ibasic_string::ends_with
bool ends_with(const_pointer s) const
Checks that the string is the end of this string.
Definition basic_string.h:1664
etl::ibasic_string::insert
etl::ibasic_string< T > & insert(size_type position, size_type n, value_type c)
Definition basic_string.h:1300
etl::ibasic_string::rend
const_reverse_iterator rend() const
Definition basic_string.h:437
etl::ibasic_string::find_last_not_of
size_type find_last_not_of(const ibasic_string< T > &str, size_type position=npos) const
Definition basic_string.h:2248
etl::ibasic_string::find
size_type find(const etl::basic_string_view< T, TOtherTraits > &view, size_type pos=0) const
Definition basic_string.h:1444
etl::ibasic_string::data_end
const_pointer data_end() const
Definition basic_string.h:660
etl::ibasic_string::assign
void assign(const etl::ibasic_string< T > &other)
Definition basic_string.h:670
etl::ibasic_string::cend
const_iterator cend() const
Definition basic_string.h:401
etl::ibasic_string::c_str
const_pointer c_str() const
Return a pointer to a C string.
Definition basic_string.h:1394
etl::ibasic_string::resize
void resize(size_type new_size, T value)
Definition basic_string.h:476
etl::ibasic_string::data
ETL_CONSTEXPR const_pointer data() const
Definition basic_string.h:642
etl::ibasic_string::front
const_reference front() const
Definition basic_string.h:603
etl::ibasic_string::operator+=
ibasic_string & operator+=(const etl::basic_string_view< T, TOtherTraits > &rhs)
+= operator.
Definition basic_string.h:2391
etl::ibasic_string::data
pointer data()
Definition basic_string.h:633
etl::ibasic_string::find_first_not_of
size_type find_first_not_of(value_type c, size_type position=0) const
Definition basic_string.h:2227
etl::ibasic_string::append
ibasic_string & append(const_pointer str)
Definition basic_string.h:865
etl::ibasic_string::append
ibasic_string & append(size_type n, T c)
Definition basic_string.h:901
etl::ibasic_string::find_first_not_of
size_type find_first_not_of(const ibasic_string< T > &str, size_type position=0) const
Definition basic_string.h:2164
etl::ibasic_string::find_last_of
size_type find_last_of(value_type c, size_type position=npos) const
Definition basic_string.h:2134
etl::ibasic_string::copy
size_type copy(pointer dest, size_type count, size_type pos=0) const
Definition basic_string.h:1405
etl::ibasic_string::append
ibasic_string & append(const ibasic_string &str)
Definition basic_string.h:821
etl::ibasic_string::find_last_not_of
size_type find_last_not_of(const etl::basic_string_view< T, TOtherTraits > &view, size_type position=npos) const
Definition basic_string.h:2269
etl::ibasic_string::operator+=
ibasic_string & operator+=(T rhs)
+= operator.
Definition basic_string.h:2411
etl::ibasic_string::replace
ibasic_string & replace(size_type position, size_type length_, const_pointer s)
Replace characters from 'position' of 'length' with pointed to string.
Definition basic_string.h:1777
etl::ibasic_string::front
reference front()
Definition basic_string.h:593
etl::ibasic_string::back
reference back()
Definition basic_string.h:613
etl::ibasic_string::starts_with
bool starts_with(const_pointer s) const
Checks that the string is the start of this string.
Definition basic_string.h:1619
etl::ibasic_string::cbegin
const_iterator cbegin() const
Definition basic_string.h:392
etl::ibasic_string::find_first_not_of
size_type find_first_not_of(const etl::basic_string_view< T, TOtherTraits > &view, size_type position=0) const
Definition basic_string.h:2185
etl::ibasic_string::compare
int compare(size_type position, size_type length_, const etl::basic_string_view< T, TOtherTraits > &view, size_type subposition, size_type sublength) const
Definition basic_string.h:1950
etl::ibasic_string::assign
void assign(size_type n, T c)
Definition basic_string.h:753
etl::ibasic_string::initialise
void initialise()
Initialise the string.
Definition basic_string.h:2465
etl::ibasic_string::starts_with
bool starts_with(const etl::basic_string_view< T, TOtherTraits > &view) const
Checks that the view is the start of this string.
Definition basic_string.h:1611
etl::ibasic_string::operator+=
ibasic_string & operator+=(const ibasic_string &rhs)
+= operator.
Definition basic_string.h:2380
etl::ibasic_string::trim_to_terminator
void trim_to_terminator()
Definition basic_string.h:2441
etl::ibasic_string::uninitialized_resize
void uninitialized_resize(size_type new_size)
Definition basic_string.h:523
etl::ibasic_string::compare
int compare(size_type position, size_type length_, const_pointer s, size_type n) const
Compare position / length with C string / n.
Definition basic_string.h:1982
etl::ibasic_string::rfind
size_type rfind(const_pointer s, size_type position, size_type length_) const
Definition basic_string.h:1532
etl::ibasic_string::ends_with
bool ends_with(const etl::ibasic_string< T > &str) const
Checks that the string is the end of this string.
Definition basic_string.h:1637
etl::ibasic_string::find_first_of
size_type find_first_of(const_pointer s, size_type position, size_type n) const
Definition basic_string.h:2024
etl::ibasic_string::compare
int compare(const ibasic_string &str) const
Compare with string.
Definition basic_string.h:1894
etl::ibasic_string::end
const_iterator end() const
Definition basic_string.h:383
etl::ibasic_string::erase
iterator erase(const_iterator i_element)
Definition basic_string.h:1348
etl::ibasic_string::compare
int compare(size_type position, size_type length_, const etl::basic_string_view< T, TOtherTraits > &view) const
Compare position / length with etl::basic_string_view.
Definition basic_string.h:1925
etl::ibasic_string::insert
etl::ibasic_string< T > & insert(size_type position, const_pointer s)
Definition basic_string.h:1271
etl::ibasic_string::assign
void assign(const_pointer str)
Definition basic_string.h:722
etl::ibasic_string::fill
void fill(T value)
Definition basic_string.h:536
etl::ibasic_string::repair_buffer
void repair_buffer(T *p_buffer_)
Fix the internal pointers after a low level memory copy.
Definition basic_string.h:2477
etl::ibasic_string::insert
iterator insert(const_iterator position, const etl::basic_string_view< T, TOtherTraits > &view)
Definition basic_string.h:1164
etl::size_type
etl::private_basic_string::string_base_statics
Definition basic_string.h:146
etl::string_base
Definition basic_string.h:169
etl::string_base::set_secure
void set_secure()
Sets the 'secure' flag to the requested state.
Definition basic_string.h:275
etl::string_base::is_secure
bool is_secure() const
Gets the 'secure' state flag.
Definition basic_string.h:284
etl::string_base::CAPACITY
const size_type CAPACITY
The maximum number of elements in the string.
Definition basic_string.h:320
etl::string_base::full
bool full() const
Definition basic_string.h:205
etl::string_base::~string_base
~string_base()
Destructor.
Definition basic_string.h:317
etl::string_base::truncated
ETL_DEPRECATED bool truncated() const
Definition basic_string.h:256
etl::string_base::set_truncated
void set_truncated(bool status)
Sets the 'truncated' flag.
Definition basic_string.h:308
etl::string_base::max_size
size_type max_size() const
Definition basic_string.h:223
etl::string_base::string_base
string_base(size_type max_size_)
Constructor.
Definition basic_string.h:298
etl::string_base::clear_truncated
void clear_truncated()
Clears the 'truncated' flag.
Definition basic_string.h:265
etl::string_base::length
size_type length() const
Definition basic_string.h:187
etl::string_base::current_size
size_type current_size
The current number of elements in the string.
Definition basic_string.h:319
etl::string_base::available
size_type available() const
Definition basic_string.h:232
etl::string_base::empty
bool empty() const
Definition basic_string.h:196
etl::string_base::capacity
size_type capacity() const
Definition basic_string.h:214
etl::string_base::is_truncated
bool is_truncated() const
Definition basic_string.h:241
etl::string_base::size
size_type size() const
Definition basic_string.h:178
etl::string_exception
Definition basic_string.h:86
etl::string_iterator
Definition basic_string.h:114
etl::string_out_of_bounds
Definition basic_string.h:100
etl::string_truncation
Definition basic_string.h:128
diagnostic_pop.h
diagnostic_stringop_overflow_push.h
error_handler.h
exception.h
flags.h
etl::const_iterator
ETL_ASSERT
#define ETL_ASSERT(b, e)
Definition error_handler.h:511
etl::exception::exception
ETL_EXCEPTION_CONSTEXPR exception(string_type reason_, string_type, numeric_type)
Constructor.
Definition exception.h:81
etl::exception
Definition exception.h:59
etl::integral_limits
Definition integral_limits.h:517
type
etl::memory_clear_range
void memory_clear_range(volatile T *begin, size_t n)
Definition memory.h:2986
integral_limits.h
iterator.h
memory.h
minmax_pop.h
minmax_push.h
etl::private_basic_string
Definition basic_string.h:142
etl
Definition absolute.h:40
etl::operator==
ETL_CONSTEXPR14 bool operator==(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1078
etl::mem_move
T * mem_move(const T *sb, const T *se, T *db) ETL_NOEXCEPT
Definition memory.h:3302
etl::operator<<
std::basic_ostream< T, std::char_traits< T > > & operator<<(std::basic_ostream< T, std::char_traits< T > > &os, const etl::ibasic_string< T > &str)
Definition basic_string.h:3198
etl::mem_set
etl::enable_if< etl::is_pointer< TPointer >::value &&!etl::is_const< TPointer >::value &&etl::is_integral< T >::value &&sizeof(T)==1, TPointer >::type mem_set(TPointer db, const TPointer de, T value) ETL_NOEXCEPT
Definition memory.h:3399
etl::operator>
bool operator>(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1130
etl::operator>=
bool operator>=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1144
etl::operator!=
ETL_CONSTEXPR14 bool operator!=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1090
etl::mem_copy
T * mem_copy(const T *sb, const T *se, T *db) ETL_NOEXCEPT
Definition memory.h:3260
etl::strlen
ETL_CONSTEXPR14 size_t strlen(const T *t) ETL_NOEXCEPT
Alternative strlen for all character types.
Definition char_traits.h:293
etl::operator<
bool operator<(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1103
etl::operator<=
bool operator<=(const etl::array< T, SIZE > &lhs, const etl::array< T, SIZE > &rhs)
Definition array.h:1117
platform.h
string.h
string_utilities.h
etl::value_type
etl::iterator
iterator
Definition iterator.h:482
etl::type
etl::remove_pointer
remove_pointer
Definition type_traits.h:147
type_traits.h