mirror of
https://github.com/ETLCPP/etl.git
synced 2026-04-30 19:09:10 +08:00
Full string utilities for char
This commit is contained in:
parent
488f8a0f5f
commit
5c9f648cc5
1
.gitignore
vendored
1
.gitignore
vendored
@ -257,3 +257,4 @@ test/Logs
|
||||
build-test-Desktop_x86_windows_msvc2019_pe_32bit-Debug
|
||||
test/vs2019/.vs
|
||||
Corel Auto-Preserve
|
||||
test/vs2019/Debug No Unit Tests
|
||||
|
||||
@ -939,11 +939,11 @@ namespace etl
|
||||
//***************************************************************************
|
||||
// replace
|
||||
template <typename TIterator, typename T>
|
||||
void replace(TIterator first, TIterator last, const T& old_value, const T& new_value)
|
||||
ETL_CONSTEXPR14 void replace(TIterator first, TIterator last, const T& old_value, const T& new_value)
|
||||
{
|
||||
while (first != last)
|
||||
while (first != last)
|
||||
{
|
||||
if (*first == old_value)
|
||||
if (*first == old_value)
|
||||
{
|
||||
*first = new_value;
|
||||
}
|
||||
@ -955,7 +955,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
// replace_if
|
||||
template <typename TIterator, typename TPredicate, typename T>
|
||||
void replace(TIterator first, TIterator last, TPredicate predicate, const T& new_value)
|
||||
ETL_CONSTEXPR14 void replace_if(TIterator first, TIterator last, TPredicate predicate, const T& new_value)
|
||||
{
|
||||
while (first != last)
|
||||
{
|
||||
@ -964,14 +964,14 @@ namespace etl
|
||||
*first = new_value;
|
||||
}
|
||||
|
||||
++first
|
||||
++first;
|
||||
}
|
||||
}
|
||||
#else
|
||||
//***************************************************************************
|
||||
// replace
|
||||
template <typename TIterator, typename T>
|
||||
void replace(TIterator first, TIterator last, const T& old_value, const T& new_value)
|
||||
ETL_CONSTEXPR14 void replace(TIterator first, TIterator last, const T& old_value, const T& new_value)
|
||||
{
|
||||
std::replace(first, last, old_value, new_value);
|
||||
}
|
||||
@ -979,7 +979,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
// replace_if
|
||||
template <typename TIterator, typename TPredicate, typename T>
|
||||
void replace(TIterator first, TIterator last, TPredicate predicate, const T& new_value)
|
||||
ETL_CONSTEXPR14 void replace_if(TIterator first, TIterator last, TPredicate predicate, const T& new_value)
|
||||
{
|
||||
std::replace_if(first, last, predicate, new_value);
|
||||
}
|
||||
@ -1236,7 +1236,7 @@ namespace etl
|
||||
{
|
||||
#if ETL_CPP11_SUPPORTED
|
||||
return std::is_heap(first, last);
|
||||
#else
|
||||
#else
|
||||
typedef etl::less<typename etl::iterator_traits<TIterator>::value_type> compare;
|
||||
return private_heap::is_heap(first, last - first, compare());
|
||||
#endif
|
||||
|
||||
@ -1148,6 +1148,11 @@ namespace etl
|
||||
//*********************************************************************
|
||||
iterator erase(iterator first, iterator last)
|
||||
{
|
||||
if (first == last)
|
||||
{
|
||||
return first;
|
||||
}
|
||||
|
||||
etl::copy(last, end(), first);
|
||||
size_t n_delete = etl::distance(first, last);
|
||||
|
||||
|
||||
@ -36,11 +36,26 @@ SOFTWARE.
|
||||
#include "../string_view.h"
|
||||
#include "../algorithm.h"
|
||||
#include "../utility.h"
|
||||
#include "../enum_type.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
namespace etl
|
||||
{
|
||||
struct string_pad_direction
|
||||
{
|
||||
enum enum_type
|
||||
{
|
||||
LEFT,
|
||||
RIGHT,
|
||||
};
|
||||
|
||||
ETL_DECLARE_ENUM_TYPE(string_pad_direction, int)
|
||||
ETL_ENUM_TYPE(LEFT, "left")
|
||||
ETL_ENUM_TYPE(RIGHT, "right")
|
||||
ETL_END_ENUM_TYPE
|
||||
};
|
||||
|
||||
namespace private_string_utilities
|
||||
{
|
||||
//***************************************************************************
|
||||
@ -73,36 +88,6 @@ namespace etl
|
||||
return TStringView(pbegin, view.end());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from_left
|
||||
/// Trim left of trim_characters
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void trim_from_left(TIString& s, typename TIString::const_pointer trim_characters, size_t length)
|
||||
{
|
||||
size_t position = s.find_first_not_of(trim_characters, 0, length);
|
||||
s.erase(0U, position);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// view_trim_left_of
|
||||
/// Trim left of whitespace
|
||||
//***************************************************************************
|
||||
template <typename TStringView>
|
||||
TStringView view_trim_from_left(const TStringView& view, typename TStringView::const_pointer trim_characters, size_t length)
|
||||
{
|
||||
size_t first = view.find_first_not_of(trim_characters, 0, length);
|
||||
|
||||
typename TStringView::const_pointer pbegin = view.end();
|
||||
|
||||
if (first != TStringView::npos)
|
||||
{
|
||||
pbegin = view.begin() + first;
|
||||
}
|
||||
|
||||
return TStringView(pbegin, view.end());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_left_delimiters
|
||||
/// Trim left, up to, but not including, delimiters.
|
||||
@ -137,42 +122,6 @@ namespace etl
|
||||
return TStringView(pbegin, view.end());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_left_delimiters
|
||||
/// Trim left, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void trim_left_delimiters(TIString& s, typename TIString::const_pointer delimiters, size_t length)
|
||||
{
|
||||
size_t p = s.find_first_of(delimiters, 0, length);
|
||||
|
||||
if (p != TIString::npos)
|
||||
{
|
||||
s.erase(0, p);
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// view_trim_left_delimiters
|
||||
/// Trim left, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
template <typename TStringView>
|
||||
TStringView view_trim_left_delimiters(const TStringView& view, typename TStringView::const_pointer delimiters, size_t length)
|
||||
{
|
||||
size_t first = view.find_first_of(delimiters, 0, length);
|
||||
|
||||
typename TStringView::const_pointer pbegin = view.end();
|
||||
|
||||
if (first != TStringView::npos)
|
||||
{
|
||||
pbegin = view.begin() + first;
|
||||
}
|
||||
|
||||
return TStringView(pbegin, view.end());
|
||||
}
|
||||
|
||||
//*********************************************************************************************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from_right
|
||||
/// Trim right of trim_characters
|
||||
@ -202,35 +151,6 @@ namespace etl
|
||||
return TStringView(view.begin(), pend);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from_right
|
||||
/// Trim right of trim_characters
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void trim_from_right(TIString& s, typename TIString::const_pointer trim_characters, size_t length)
|
||||
{
|
||||
s.erase(s.find_last_not_of(trim_characters, TIString::npos, length) + 1);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// view_trim_from_right
|
||||
/// Trim right of trim_characters
|
||||
//***************************************************************************
|
||||
template <typename TStringView>
|
||||
TStringView view_trim_from_right(const TStringView& view, typename TStringView::const_pointer trim_characters, size_t length)
|
||||
{
|
||||
size_t last = view.find_last_not_of(trim_characters, TStringView::npos, length) + 1;
|
||||
|
||||
typename TStringView::const_pointer pend = view.begin();
|
||||
|
||||
if (last != TStringView::npos)
|
||||
{
|
||||
pend += last;
|
||||
}
|
||||
|
||||
return TStringView(view.begin(), pend);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_right_delimiters
|
||||
//***************************************************************************
|
||||
@ -268,45 +188,6 @@ namespace etl
|
||||
return TStringView(view.begin(), pend);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_right
|
||||
/// Trim right, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void trim_right_delimiters(TIString& s, typename TIString::const_pointer delimiters, size_t length)
|
||||
{
|
||||
size_t p = s.find_last_of(delimiters, TIString::npos, length);
|
||||
|
||||
if (p != TIString::npos)
|
||||
{
|
||||
++p;
|
||||
|
||||
if (p != s.size())
|
||||
{
|
||||
s.erase(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// view_trim_right_delimiters
|
||||
/// Trim right, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
template <typename TStringView>
|
||||
TStringView view_trim_right_delimiters(const TStringView& view, typename TStringView::const_pointer delimiters, size_t length)
|
||||
{
|
||||
size_t last = view.find_last_of(delimiters, 0, length) + 1;
|
||||
|
||||
typename TStringView::const_pointer pend = view.begin();
|
||||
|
||||
if (last != TStringView::npos)
|
||||
{
|
||||
pend += last;
|
||||
}
|
||||
|
||||
return TStringView(view.begin(), pend);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from
|
||||
/// Trim left and right of trim_characters
|
||||
@ -344,43 +225,6 @@ namespace etl
|
||||
return TStringView(pbegin, pend);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from
|
||||
/// Trim left and right of trim_characters
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void trim_from(TIString& s, typename TIString::const_pointer trim_characters, size_t length)
|
||||
{
|
||||
trim_from_left(s, trim_characters, length);
|
||||
trim_from_right(s, trim_characters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from
|
||||
/// Trim left and right of trim_characters
|
||||
//***************************************************************************
|
||||
template <typename TStringView>
|
||||
TStringView view_trim_from(const TStringView& view, typename TStringView::const_pointer trim_characters, size_t length)
|
||||
{
|
||||
size_t first = view.find_first_not_of(trim_characters, 0, length);
|
||||
size_t last = view.find_last_not_of(trim_characters, 0, length) + 1;
|
||||
|
||||
typename TStringView::const_pointer pbegin = view.begin();
|
||||
typename TStringView::const_pointer pend = view.begin();
|
||||
|
||||
if (first != TStringView::npos)
|
||||
{
|
||||
pbegin += first;
|
||||
}
|
||||
|
||||
if (last != TStringView::npos)
|
||||
{
|
||||
pend += last;
|
||||
}
|
||||
|
||||
return TStringView(pbegin, pend);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_delimiters
|
||||
/// Trim left and right of trim_characters
|
||||
@ -418,27 +262,6 @@ namespace etl
|
||||
return TStringView(pbegin, pend);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_delimiters
|
||||
/// Trim left and right of trim_characters
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void trim_delimiters(TIString& s, typename TIString::const_pointer delimiters, size_t length)
|
||||
{
|
||||
trim_left_delimiters(s, delimiters, length);
|
||||
trim_right_delimiters(s, delimiters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_delimiters
|
||||
/// Trim left and right of trim_characters
|
||||
//***************************************************************************
|
||||
template <typename TStringView>
|
||||
TStringView view_trim_delimiters(const TStringView& view, typename TStringView::const_pointer delimiters, size_t length)
|
||||
{
|
||||
return view;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// reverse
|
||||
/// Reverse a string
|
||||
@ -493,6 +316,146 @@ namespace etl
|
||||
}
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find first of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
template <typename TIterator, typename TPointer>
|
||||
TIterator find_first_of(TIterator first, TIterator last, TPointer delimiters)
|
||||
{
|
||||
TIterator itr(first);
|
||||
|
||||
while (itr != last)
|
||||
{
|
||||
TPointer pd = delimiters;
|
||||
|
||||
while (*pd != 0)
|
||||
{
|
||||
if (*itr == *pd)
|
||||
{
|
||||
return itr;
|
||||
}
|
||||
|
||||
++pd;
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find first not of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
template <typename TIterator, typename TPointer>
|
||||
TIterator find_first_not_of(TIterator first, TIterator last, TPointer delimiters)
|
||||
{
|
||||
TIterator itr(first);
|
||||
|
||||
while (itr != last)
|
||||
{
|
||||
TPointer pd = delimiters;
|
||||
|
||||
bool found = false;
|
||||
|
||||
while (*pd != 0)
|
||||
{
|
||||
if (*itr == *pd)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
++pd;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
return itr;
|
||||
}
|
||||
|
||||
++itr;
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find last of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
template <typename TIterator, typename TPointer>
|
||||
TIterator find_last_of(TIterator first, TIterator last, TPointer delimiters)
|
||||
{
|
||||
if (first == last)
|
||||
{
|
||||
return last;
|
||||
}
|
||||
|
||||
TIterator itr(last - 1);
|
||||
TIterator end(first - 1);
|
||||
|
||||
while (itr != end)
|
||||
{
|
||||
TPointer pd = delimiters;
|
||||
|
||||
while (*pd != 0)
|
||||
{
|
||||
if (*itr == *pd)
|
||||
{
|
||||
return itr;
|
||||
}
|
||||
|
||||
++pd;
|
||||
}
|
||||
|
||||
--itr;
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find last not of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
template <typename TIterator, typename TPointer>
|
||||
TIterator find_last_not_of(TIterator first, TIterator last, TPointer delimiters)
|
||||
{
|
||||
if (first == last)
|
||||
{
|
||||
return last;
|
||||
}
|
||||
|
||||
TIterator itr(last - 1);
|
||||
TIterator end(first - 1);
|
||||
|
||||
while (itr != end)
|
||||
{
|
||||
TPointer pd = delimiters;
|
||||
|
||||
bool found = false;
|
||||
|
||||
while (*pd != 0)
|
||||
{
|
||||
if (*itr == *pd)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
||||
++pd;
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
return itr;
|
||||
}
|
||||
|
||||
--itr;
|
||||
}
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// get_token
|
||||
//***************************************************************************
|
||||
@ -502,252 +465,75 @@ namespace etl
|
||||
typename TIString::const_iterator first = last_view.end();
|
||||
typename TIString::const_iterator last = last_view.end();
|
||||
|
||||
// The last view was default constructed, so we must be looking for the first token.
|
||||
// If the last view was default constructed then we must be looking for the first token.
|
||||
if (last_view.data() == ETL_NULLPTR)
|
||||
{
|
||||
first = s.begin();
|
||||
last = s.begin();
|
||||
}
|
||||
|
||||
// Look for the start of the next token.
|
||||
size_t first_position = s.find_first_not_of(delimiters, std::distance(s.begin(), last));
|
||||
size_t last_position = s.find_first_of(delimiters, first_position);
|
||||
first = find_first_not_of(first, s.end(), delimiters);
|
||||
last = find_first_of(first, s.end(), delimiters);
|
||||
|
||||
if (first_position == TIString::npos)
|
||||
{
|
||||
first_position = s.size();
|
||||
}
|
||||
|
||||
if (last_position == TIString::npos)
|
||||
{
|
||||
last_position = s.size();
|
||||
}
|
||||
|
||||
return TStringView(s.begin() + first_position, s.begin() + last_position);
|
||||
return TStringView(first, last);
|
||||
}
|
||||
|
||||
////***************************************************************************
|
||||
/////
|
||||
////***************************************************************************
|
||||
//template<size_t max_len>
|
||||
//etl::string<max_len> left(etl::string<max_len> const& s, size_t n_chars)
|
||||
//{
|
||||
// return s.substr(0, n_chars);
|
||||
//}
|
||||
//***************************************************************************
|
||||
/// pad_left
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void pad_left(TIString& s, size_t required_size, typename TIString::value_type pad_char)
|
||||
{
|
||||
required_size = etl::min(required_size, s.capacity());
|
||||
|
||||
////***************************************************************************
|
||||
/////
|
||||
////***************************************************************************
|
||||
//template<size_t max_len>
|
||||
//etl::string<max_len> right(etl::string<max_len> const& s, size_t start)
|
||||
//{
|
||||
// return s.substr(start);
|
||||
//}
|
||||
if (required_size > s.size())
|
||||
{
|
||||
required_size -= s.size();
|
||||
s.insert(0U, required_size, pad_char);
|
||||
}
|
||||
}
|
||||
|
||||
//template<size_t max_len, size_t max_num_tokens>
|
||||
//void tokenize(etl::string<max_len> const& s, etl::vector<etl::string<max_len>, max_num_tokens>& tokens, char const* delims, bool ignore_empty_strings)
|
||||
//{
|
||||
// size_t delim;
|
||||
// size_t O = 0;
|
||||
//***************************************************************************
|
||||
/// pad_right
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void pad_right(TIString& s, size_t required_size, typename TIString::value_type pad_char)
|
||||
{
|
||||
required_size = etl::min(required_size, s.capacity());
|
||||
|
||||
// tokens.clear();
|
||||
if (required_size > s.size())
|
||||
{
|
||||
required_size -= s.size();
|
||||
s.insert(s.size(), required_size, pad_char);
|
||||
}
|
||||
}
|
||||
|
||||
// delim = s.find_first_of(delims, O);
|
||||
//***************************************************************************
|
||||
/// pad
|
||||
//***************************************************************************
|
||||
template <typename TIString>
|
||||
void pad(TIString& s, size_t required_size, string_pad_direction pad_direction, typename TIString::value_type pad_char)
|
||||
{
|
||||
switch (int(pad_direction))
|
||||
{
|
||||
case string_pad_direction::LEFT:
|
||||
{
|
||||
pad_left(s, required_size, pad_char);
|
||||
break;
|
||||
}
|
||||
|
||||
// while (delim != etl::string<max_len>::npos)
|
||||
// {
|
||||
// etl::string<max_len> tok(s.substr(O, delim - O));
|
||||
// trim(tok);
|
||||
// if (!tok.empty() || !ignore_empty_strings)
|
||||
// tokens.push_back(tok);
|
||||
// O = delim + 1;
|
||||
case string_pad_direction::RIGHT:
|
||||
{
|
||||
pad_right(s, required_size, pad_char);
|
||||
break;
|
||||
}
|
||||
|
||||
// delim = s.find_first_of(delims, O);
|
||||
// }
|
||||
// etl::string<max_len> tok(s.substr(O));
|
||||
// trim(tok);
|
||||
// if (!tok.empty() || !ignore_empty_strings)
|
||||
// tokens.push_back(tok);
|
||||
//}
|
||||
|
||||
//template<size_t max_len, size_t max_token_len, size_t max_num_tokens>
|
||||
//void tokenize(etl::string<max_len> const& s, etl::vector<etl::string<max_token_len>, max_num_tokens>& tokens, char const* delims, bool ignore_empty_strings)
|
||||
//{
|
||||
// size_t delim;
|
||||
// size_t O = 0;
|
||||
|
||||
// tokens.clear();
|
||||
|
||||
// delim = s.find_first_of(delims, O);
|
||||
|
||||
// while (delim != etl::string<max_len>::npos)
|
||||
// {
|
||||
// etl::string<max_token_len> tok(s.substr(O, delim - O).c_str());
|
||||
// trim(tok);
|
||||
// if (!tok.empty() || !ignore_empty_strings)
|
||||
// tokens.push_back(tok);
|
||||
// O = delim + 1;
|
||||
|
||||
// delim = s.find_first_of(delims, O);
|
||||
// }
|
||||
// etl::string<max_token_len> tok(s.substr(O).c_str());
|
||||
// trim(tok);
|
||||
// if (!tok.empty() || !ignore_empty_strings)
|
||||
// tokens.push_back(tok);
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//float to_float(etl::string<max_len> const& s)
|
||||
//{
|
||||
// return strtof(s.c_str(), 0);
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//unsigned to_unsigned(etl::string<max_len> const& s, int radix)
|
||||
//{
|
||||
// return strtoul(s.c_str(), 0, radix);
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//int to_int(etl::string<max_len> const& s, int radix)
|
||||
//{
|
||||
// return strtol(s.c_str(), 0, radix);
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//bool to_bool(etl::string<max_len> const& s)
|
||||
//{
|
||||
// return s[0] == 't' || s[0] == 'T';
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//etl::string<max_len> substr_between(etl::string<max_len> const& s, const etl::string<max_len> brackets)
|
||||
//{
|
||||
// size_t l = s.find_first_of(brackets[0]);
|
||||
// size_t r = s.find_last_of(brackets[1]);
|
||||
|
||||
// if (l != etl::string<max_len>::npos && r != etl::string<max_len>::npos && r - l > 1)
|
||||
// return s.substr(l + 1, r - l - 1);
|
||||
// return etl::string<max_len>();
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//int array_subscript(etl::string<max_len> const& s)
|
||||
//{
|
||||
// etl::string<max_len> n = substr_between(s);
|
||||
// return n.empty() ? -1 : to_int(n);
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//etl::string<max_len> from_float(float f, int digits)
|
||||
//{
|
||||
// char buf[32];
|
||||
// char format[] = { '%','9','.',char('0' + char(digits)),'f',0 };
|
||||
// sprintf(buf, format, f);
|
||||
// return etl::string<max_len>(buf);
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//etl::string<max_len> from_float(float f, char const* format_string)
|
||||
//{
|
||||
// char buf[32];
|
||||
// sprintf(buf, format_string, f);
|
||||
// return etl::string<max_len>(buf);
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//etl::string<max_len> from_unsigned(unsigned u, bool hex = false)
|
||||
//{
|
||||
// char buf[16];
|
||||
// char format[] = { '%',hex ? 'x' : 'u',0 };
|
||||
// sprintf(buf, format, u);
|
||||
// return etl::string<max_len>(buf);
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//etl::string<max_len> from_int(int i, bool hex = false)
|
||||
//{
|
||||
// char buf[16];
|
||||
// char format[] = { '%',hex ? 'x' : 'i',0 };
|
||||
// sprintf(buf, format, i);
|
||||
// return etl::string<max_len>(buf);
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//etl::string<max_len> from_bool(bool b, bool verbose)
|
||||
//{
|
||||
// if (verbose)
|
||||
// return b ? "true" : "false";
|
||||
// else
|
||||
// return b ? "t" : "f";
|
||||
//}
|
||||
|
||||
|
||||
//template<size_t max_len>
|
||||
//void reverse(etl::string<max_len>& s)
|
||||
//{
|
||||
// std::reverse(s.begin(), s.end());
|
||||
//}
|
||||
|
||||
//enum pad_dir_t
|
||||
//{
|
||||
// pad_dir__right,
|
||||
// pad_dir__left
|
||||
//};
|
||||
|
||||
//template<size_t max_len>
|
||||
//void pad(etl::string<max_len>& s, size_t size, pad_dir_t dir, char pad_char)
|
||||
//{
|
||||
// if (size > s.size())
|
||||
// {
|
||||
// size -= s.size();
|
||||
|
||||
// if (dir == pad_dir__left)
|
||||
// {
|
||||
// reverse(s);
|
||||
// s.reserve(s.size() + size);
|
||||
// while (size--)
|
||||
// s.push_back(pad_char);
|
||||
// reverse(s);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// s.reserve(s.size() + size);
|
||||
// while (size--)
|
||||
// s.push_back(pad_char);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//void to_uppercase(etl::string<max_len>& s)
|
||||
//{
|
||||
// for (typename etl::string<max_len>::iterator iter = s.begin(); iter != s.end(); ++iter)
|
||||
// *iter = char(toupper(*iter));
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//void to_lowercase(etl::string<max_len>& s)
|
||||
//{
|
||||
// for (typename etl::string<max_len>::iterator iter = s.begin(); iter != s.end(); ++iter)
|
||||
// *iter = char(tolower(*iter));
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//void namify(etl::string<max_len>& s)
|
||||
//{
|
||||
// replace(s.begin(), s.end(), ' ', '_');
|
||||
// replace(s.begin(), s.end(), '/', '_');
|
||||
// replace(s.begin(), s.end(), '-', '_');
|
||||
// replace(s.begin(), s.end(), '.', '_');
|
||||
// replace(s.begin(), s.end(), '(', '_');
|
||||
// replace(s.begin(), s.end(), ')', '_');
|
||||
// replace(s.begin(), s.end(), ',', '_');
|
||||
// replace(s.begin(), s.end(), '[', '_');
|
||||
// replace(s.begin(), s.end(), ']', '_');
|
||||
// while (!s.empty() && s.back() == '_')
|
||||
// s.pop_back();
|
||||
//}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -77,42 +77,6 @@ namespace etl
|
||||
return etl::private_string_utilities::view_trim_from_left<etl::string_view>(view, trim_characters);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from_left
|
||||
/// Trim left of specified characters
|
||||
//***************************************************************************
|
||||
inline void trim_from_left(etl::istring& s, etl::istring::const_pointer trim_characters, size_t length)
|
||||
{
|
||||
etl::private_string_utilities::trim_from_left<etl::istring>(s, trim_characters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from_left
|
||||
/// View trim left of specified characters
|
||||
//***************************************************************************
|
||||
inline etl::string_view trim_from_left(const etl::string_view& view, etl::istring::const_pointer trim_characters, size_t length)
|
||||
{
|
||||
return etl::private_string_utilities::view_trim_from_left<etl::string_view>(view, trim_characters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from_left
|
||||
/// Trim left of specified characters
|
||||
//***************************************************************************
|
||||
inline void trim_from_left(etl::istring& s, const etl::istring& trim_characters)
|
||||
{
|
||||
etl::private_string_utilities::trim_from_left<etl::istring>(s, trim_characters.c_str());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from_left
|
||||
/// View trim left of specified characters
|
||||
//***************************************************************************
|
||||
inline etl::string_view trim_from_left(const etl::string_view& view, const etl::istring& trim_characters)
|
||||
{
|
||||
return etl::private_string_utilities::view_trim_from_left<etl::string_view>(view, trim_characters.c_str());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_left
|
||||
/// Trim left, up to, but not including, delimiters.
|
||||
@ -131,44 +95,6 @@ namespace etl
|
||||
return etl::private_string_utilities::view_trim_left_delimiters<etl::string_view>(s, delimiters);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_left
|
||||
/// Trim left, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
inline void trim_left(etl::istring& s, etl::istring::const_pointer delimiters, size_t length)
|
||||
{
|
||||
etl::private_string_utilities::trim_left_delimiters<etl::istring>(s, delimiters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_left
|
||||
/// Trim left, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
inline etl::string_view trim_left(const etl::string_view& view, etl::string_view::const_pointer delimiters, size_t length)
|
||||
{
|
||||
return etl::private_string_utilities::view_trim_left_delimiters<etl::string_view>(view, delimiters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_left
|
||||
/// Trim left, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
inline void trim_left(etl::istring& s, const etl::istring& delimiters)
|
||||
{
|
||||
etl::private_string_utilities::trim_left_delimiters<etl::istring>(s, delimiters.c_str());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_left
|
||||
/// Trim left, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
inline etl::string_view trim_left(const etl::string_view& view, const etl::istring& delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::view_trim_left_delimiters<etl::string_view>(view, delimiters.c_str());
|
||||
}
|
||||
|
||||
//*********************************************************************************************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_whitespace_right
|
||||
/// Trim right of whitespace
|
||||
@ -205,42 +131,6 @@ namespace etl
|
||||
return etl::private_string_utilities::view_trim_from_right<etl::string_view>(view, trim_characters);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from_right
|
||||
/// Trim right of specified characters
|
||||
//***************************************************************************
|
||||
inline void trim_from_right(etl::istring& s, etl::istring::const_pointer trim_characters, size_t length)
|
||||
{
|
||||
etl::private_string_utilities::trim_from_right<etl::istring>(s, trim_characters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from_right
|
||||
/// Trim right of specified characters
|
||||
//***************************************************************************
|
||||
inline etl::string_view trim_from_right(const etl::string_view& view, etl::istring::const_pointer trim_characters, size_t length)
|
||||
{
|
||||
return etl::private_string_utilities::view_trim_from_right<etl::string_view>(view, trim_characters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from_right
|
||||
/// Trim right of specified characters
|
||||
//***************************************************************************
|
||||
inline void trim_from_right(etl::istring& s, const etl::istring& trim_characters)
|
||||
{
|
||||
etl::private_string_utilities::trim_from_right<etl::istring>(s, trim_characters.c_str());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from_right
|
||||
/// Trim right of specified characters
|
||||
//***************************************************************************
|
||||
inline etl::string_view trim_from_right(const etl::string_view& view, const etl::istring& trim_characters)
|
||||
{
|
||||
return etl::private_string_utilities::view_trim_from_right<etl::string_view>(view, trim_characters.c_str());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_right
|
||||
//***************************************************************************
|
||||
@ -257,44 +147,6 @@ namespace etl
|
||||
return etl::private_string_utilities::view_trim_right_delimiters<etl::string_view>(view, delimiters);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_right
|
||||
/// Trim right, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
inline void trim_right(etl::istring& s, etl::istring::const_pointer delimiters, size_t length)
|
||||
{
|
||||
etl::private_string_utilities::trim_right_delimiters<etl::istring>(s, delimiters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_right
|
||||
/// Trim right, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
inline etl::string_view trim_right(const etl::string_view& view, etl::istring::const_pointer delimiters, size_t length)
|
||||
{
|
||||
etl::private_string_utilities::view_trim_right_delimiters<etl::string_view>(view, delimiters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_right
|
||||
/// Trim right, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
inline void trim_right(etl::istring& s, const etl::istring& delimiters)
|
||||
{
|
||||
etl::private_string_utilities::trim_right_delimiters<etl::istring>(s, delimiters.c_str());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_right
|
||||
/// Trim right, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
inline etl::string_view trim_right(const etl::string_view& view, const etl::istring& delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::view_trim_right_delimiters<etl::string_view>(view, delimiters.c_str());
|
||||
}
|
||||
|
||||
//*********************************************************************************************************************************************************
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_whitespace
|
||||
/// Trim both ends of whitespace
|
||||
@ -331,42 +183,6 @@ namespace etl
|
||||
return etl::private_string_utilities::view_trim_from<etl::string_view>(view, trim_characters);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from
|
||||
/// Trim right of specified characters
|
||||
//***************************************************************************
|
||||
inline void trim_from(etl::istring& s, etl::istring::const_pointer trim_characters, size_t length)
|
||||
{
|
||||
etl::private_string_utilities::trim_from<etl::istring>(s, trim_characters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from
|
||||
/// Trim right of specified characters
|
||||
//***************************************************************************
|
||||
inline etl::string_view trim_from(const etl::string_view& view, etl::istring::const_pointer trim_characters, size_t length)
|
||||
{
|
||||
return etl::private_string_utilities::view_trim_from<etl::string_view>(view, trim_characters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from
|
||||
/// Trim right of specified characters
|
||||
//***************************************************************************
|
||||
inline void trim_from(etl::istring& s, const etl::istring& trim_characters)
|
||||
{
|
||||
etl::private_string_utilities::trim_from<etl::istring>(s, trim_characters.c_str());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim_from
|
||||
/// Trim right of specified characters
|
||||
//***************************************************************************
|
||||
inline etl::string_view trim_from(const etl::string_view& view, const etl::istring& trim_characters)
|
||||
{
|
||||
return etl::private_string_utilities::view_trim_from<etl::string_view>(view, trim_characters.c_str());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim
|
||||
//***************************************************************************
|
||||
@ -383,168 +199,83 @@ namespace etl
|
||||
return etl::private_string_utilities::view_trim_delimiters<etl::string_view>(view, delimiters);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim
|
||||
/// Trim right, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
inline void trim(etl::istring& s, etl::istring::const_pointer delimiters, size_t length)
|
||||
{
|
||||
etl::private_string_utilities::trim_delimiters<etl::istring>(s, delimiters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim
|
||||
/// Trim right, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
inline etl::string_view trim(const etl::string_view& view, etl::istring::const_pointer delimiters, size_t length)
|
||||
{
|
||||
etl::private_string_utilities::view_trim_delimiters<etl::string_view>(view, delimiters, length);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim
|
||||
/// Trim right, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
inline void trim(etl::istring& s, const etl::istring& delimiters)
|
||||
{
|
||||
etl::private_string_utilities::trim_delimiters<etl::istring>(s, delimiters.c_str());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// trim
|
||||
/// Trim right, up to, but not including, delimiters.
|
||||
//***************************************************************************
|
||||
inline etl::string_view trim(const etl::string_view& view, const etl::istring& delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::view_trim_delimiters<etl::string_view>(view, delimiters.c_str());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// reverse
|
||||
/// Reverse the string
|
||||
//***************************************************************************
|
||||
void reverse(etl::istring& s)
|
||||
inline void reverse(etl::istring& s)
|
||||
{
|
||||
etl::private_string_utilities::reverse<etl::istring>(s);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Get up to the first n characters.
|
||||
//***************************************************************************
|
||||
inline void left_n(etl::istring& s, size_t n)
|
||||
{
|
||||
n = (n > s.size()) ? s.size() : n;
|
||||
|
||||
s.erase(s.begin() + n, s.end());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Get a view of up to the first n characters.
|
||||
//***************************************************************************
|
||||
etl::string_view left(const etl::istring& s, size_t n)
|
||||
inline etl::string_view left_n(etl::string_view view, size_t n)
|
||||
{
|
||||
n = (n > s.size()) ? s.size() : n;
|
||||
n = (n > view.size()) ? view.size() : n;
|
||||
|
||||
return etl::string_view(s.begin(), s.begin() + n);
|
||||
return etl::string_view(view.begin(), view.begin() + n);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Get a view of up to the last n characters.
|
||||
/// Get up to the last n characters.
|
||||
//***************************************************************************
|
||||
etl::string_view right(const etl::istring& s, size_t n)
|
||||
inline void right_n(etl::istring& s, size_t n)
|
||||
{
|
||||
n = (n > s.size()) ? s.size() : n;
|
||||
|
||||
return etl::string_view(s.end() - n, s.end());
|
||||
s.erase(s.begin(), s.end() - n);
|
||||
}
|
||||
|
||||
//template<size_t max_len, size_t max_num_tokens>
|
||||
//void tokenize(etl::string<max_len> const& s, etl::vector<etl::string<max_len>, max_num_tokens>& tokens, char const* delims, bool ignore_empty_strings)
|
||||
//{
|
||||
// size_t delim;
|
||||
// size_t O = 0;
|
||||
//***************************************************************************
|
||||
/// Get a view of up to the last n characters.
|
||||
//***************************************************************************
|
||||
inline etl::string_view right_n(etl::string_view view, size_t n)
|
||||
{
|
||||
n = (n > view.size()) ? view.size() : n;
|
||||
|
||||
// tokens.clear();
|
||||
return etl::string_view(view.end() - n, view.end());
|
||||
}
|
||||
|
||||
// delim = s.find_first_of(delims, O);
|
||||
//***************************************************************************
|
||||
/// pad_left
|
||||
//***************************************************************************
|
||||
inline void pad_left(etl::istring& s, size_t required_size, etl::istring::value_type pad_char)
|
||||
{
|
||||
etl::private_string_utilities::pad_left(s, required_size, pad_char);
|
||||
}
|
||||
|
||||
// while (delim != etl::string<max_len>::npos)
|
||||
// {
|
||||
// etl::string<max_len> tok(s.substr(O, delim - O));
|
||||
// trim(tok);
|
||||
// if (!tok.empty() || !ignore_empty_strings)
|
||||
// tokens.push_back(tok);
|
||||
// O = delim + 1;
|
||||
//***************************************************************************
|
||||
/// pad_right
|
||||
//***************************************************************************
|
||||
inline void pad_right(etl::istring& s, size_t required_size, etl::istring::value_type pad_char)
|
||||
{
|
||||
etl::private_string_utilities::pad_right(s, required_size, pad_char);
|
||||
}
|
||||
|
||||
// delim = s.find_first_of(delims, O);
|
||||
// }
|
||||
// etl::string<max_len> tok(s.substr(O));
|
||||
// trim(tok);
|
||||
// if (!tok.empty() || !ignore_empty_strings)
|
||||
// tokens.push_back(tok);
|
||||
//}
|
||||
|
||||
//template<size_t max_len, size_t max_token_len, size_t max_num_tokens>
|
||||
//void tokenize(etl::string<max_len> const& s, etl::vector<etl::string<max_token_len>, max_num_tokens>& tokens, char const* delims, bool ignore_empty_strings)
|
||||
//{
|
||||
// size_t delim;
|
||||
// size_t O = 0;
|
||||
|
||||
// tokens.clear();
|
||||
|
||||
// delim = s.find_first_of(delims, O);
|
||||
|
||||
// while (delim != etl::string<max_len>::npos)
|
||||
// {
|
||||
// etl::string<max_token_len> tok(s.substr(O, delim - O).c_str());
|
||||
// trim(tok);
|
||||
// if (!tok.empty() || !ignore_empty_strings)
|
||||
// tokens.push_back(tok);
|
||||
// O = delim + 1;
|
||||
|
||||
// delim = s.find_first_of(delims, O);
|
||||
// }
|
||||
// etl::string<max_token_len> tok(s.substr(O).c_str());
|
||||
// trim(tok);
|
||||
// if (!tok.empty() || !ignore_empty_strings)
|
||||
// tokens.push_back(tok);
|
||||
//}
|
||||
|
||||
//template<size_t max_len>
|
||||
//etl::string<max_len> substr_between(etl::string<max_len> const& s, const etl::string<max_len> brackets)
|
||||
//{
|
||||
// size_t l = s.find_first_of(brackets[0]);
|
||||
// size_t r = s.find_last_of(brackets[1]);
|
||||
|
||||
// if (l != etl::string<max_len>::npos && r != etl::string<max_len>::npos && r - l > 1)
|
||||
// return s.substr(l + 1, r - l - 1);
|
||||
// return etl::string<max_len>();
|
||||
//}
|
||||
|
||||
//enum pad_dir_t
|
||||
//{
|
||||
// pad_dir__right,
|
||||
// pad_dir__left
|
||||
//};
|
||||
|
||||
//template<size_t max_len>
|
||||
//void pad(etl::string<max_len>& s, size_t size, pad_dir_t dir, char pad_char)
|
||||
//{
|
||||
// if (size > s.size())
|
||||
// {
|
||||
// size -= s.size();
|
||||
|
||||
// if (dir == pad_dir__left)
|
||||
// {
|
||||
// reverse(s);
|
||||
// s.reserve(s.size() + size);
|
||||
// while (size--)
|
||||
// s.push_back(pad_char);
|
||||
// reverse(s);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// s.reserve(s.size() + size);
|
||||
// while (size--)
|
||||
// s.push_back(pad_char);
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//***************************************************************************
|
||||
/// pad
|
||||
//***************************************************************************
|
||||
void pad(etl::istring& s, size_t required_size, string_pad_direction pad_direction, etl::istring::value_type pad_char)
|
||||
{
|
||||
etl::private_string_utilities::pad(s, required_size, pad_direction, pad_char);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// to_upper_case
|
||||
//***************************************************************************
|
||||
void to_upper_case(etl::istring& s)
|
||||
inline void to_upper_case(etl::istring& s)
|
||||
{
|
||||
etl::istring::iterator itr = s.begin();
|
||||
|
||||
@ -558,7 +289,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// to_lower_case
|
||||
//***************************************************************************
|
||||
void to_lower_case(etl::istring& s)
|
||||
inline void to_lower_case(etl::istring& s)
|
||||
{
|
||||
etl::istring::iterator itr = s.begin();
|
||||
|
||||
@ -572,7 +303,7 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// to_sentence_case
|
||||
//***************************************************************************
|
||||
void to_sentence_case(etl::istring& s)
|
||||
inline void to_sentence_case(etl::istring& s)
|
||||
{
|
||||
etl::istring::iterator itr = s.begin();
|
||||
|
||||
@ -588,9 +319,9 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// transform
|
||||
//***************************************************************************
|
||||
void transform(etl::istring& s,
|
||||
const etl::pair<etl::istring::value_type, etl::istring::value_type>* pairsbegin,
|
||||
const etl::pair<etl::istring::value_type, etl::istring::value_type>* pairsend)
|
||||
inline void transform(etl::istring& s,
|
||||
const etl::pair<etl::istring::value_type, etl::istring::value_type>* pairsbegin,
|
||||
const etl::pair<etl::istring::value_type, etl::istring::value_type>* pairsend)
|
||||
{
|
||||
etl::private_string_utilities::transform_characters<etl::istring>(s, pairsbegin, pairsend);
|
||||
}
|
||||
@ -598,9 +329,9 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// transform
|
||||
//***************************************************************************
|
||||
void transform(etl::istring& s,
|
||||
const etl::pair<const etl::istring::value_type*, const etl::istring::value_type*>* pairsbegin,
|
||||
const etl::pair<const etl::istring::value_type*, const etl::istring::value_type*>* pairsend)
|
||||
inline void transform(etl::istring& s,
|
||||
const etl::pair<const etl::istring::value_type*, const etl::istring::value_type*>* pairsbegin,
|
||||
const etl::pair<const etl::istring::value_type*, const etl::istring::value_type*>* pairsend)
|
||||
{
|
||||
etl::private_string_utilities::transform_strings<etl::istring>(s, pairsbegin, pairsend);
|
||||
}
|
||||
@ -608,10 +339,170 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// get_token
|
||||
//***************************************************************************
|
||||
etl::string_view get_token(const etl::istring& s, etl::istring::const_pointer delimiters, const string_view& last_view)
|
||||
inline etl::string_view get_token(const etl::istring& s, etl::istring::const_pointer delimiters, const string_view& last_view)
|
||||
{
|
||||
return etl::private_string_utilities::get_token(s, delimiters, last_view);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find first of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::iterator find_first_of(etl::istring::iterator first, etl::istring::iterator last, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_first_of(first, last, delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find first of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::const_iterator find_first_of(etl::istring::const_iterator first, etl::istring::const_iterator last, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_first_of(first, last, delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find first of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::iterator find_first_of(etl::istring& s, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_first_of(s.begin(), s.end(), delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find first of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::const_iterator find_first_of(const etl::istring& s, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_first_of(s.cbegin(), s.cend(), delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find first of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::const_iterator find_first_of(const etl::string_view& s, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_first_of(s.cbegin(), s.cend(), delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find first not of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::iterator find_first_not_of(etl::istring::iterator first, etl::istring::iterator last, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_first_not_of(first, last, delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find first not of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::const_iterator find_first_not_of(etl::istring::const_iterator first, etl::istring::const_iterator last, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_first_not_of(first, last, delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find first not of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::iterator find_first_not_of(etl::istring& s, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_first_not_of(s.begin(), s.end(), delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find first not of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::const_iterator find_first_not_of(const etl::istring& s, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_first_not_of(s.cbegin(), s.cend(), delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find first not of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::const_iterator find_first_not_of(const etl::string_view& view, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_first_not_of(view.cbegin(), view.cend(), delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find last of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::iterator find_last_of(etl::istring::iterator first, etl::istring::iterator last, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_last_of(first, last, delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find last of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::const_iterator find_last_of(etl::istring::const_iterator first, etl::istring::const_iterator last, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_last_of(first, last, delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find last of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::iterator find_last_of(etl::istring& s, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_last_of(s.begin(), s.end(), delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find last of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::const_iterator find_last_of(const etl::istring& s, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_last_of(s.cbegin(), s.cend(), delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find last of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::const_iterator find_last_of(const etl::string_view& view, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_last_of(view.cbegin(), view.cend(), delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find last of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::iterator find_last_not_of(etl::istring::iterator first, etl::istring::iterator last, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_last_not_of(first, last, delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find last of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::const_iterator find_last_not_of(etl::istring::const_iterator first, etl::istring::const_iterator last, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_last_not_of(first, last, delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find last of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::iterator find_last_not_of(etl::istring& s, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_last_not_of(s.begin(), s.end(), delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find last of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::const_iterator find_last_not_of(const etl::istring& s, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_last_not_of(s.cbegin(), s.cend(), delimiters);
|
||||
}
|
||||
|
||||
//*********************************************************************
|
||||
/// Find last of any of delimiters within the string
|
||||
//*********************************************************************
|
||||
inline etl::istring::const_iterator find_last_not_of(const etl::string_view& view, etl::istring::const_pointer delimiters)
|
||||
{
|
||||
return etl::private_string_utilities::find_last_not_of(view.cbegin(), view.cend(), delimiters);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -373,6 +373,7 @@
|
||||
<Unit filename="../../include/etl/private/minmax_push.h" />
|
||||
<Unit filename="../../include/etl/private/move.h" />
|
||||
<Unit filename="../../include/etl/private/pvoidvector.h" />
|
||||
<Unit filename="../../include/etl/private/string_utilities_helper.h" />
|
||||
<Unit filename="../../include/etl/private/swap.h" />
|
||||
<Unit filename="../../include/etl/private/to_string_helper.h" />
|
||||
<Unit filename="../../include/etl/private/vector_base.h" />
|
||||
@ -435,6 +436,7 @@
|
||||
<Unit filename="../../include/etl/state_chart.h" />
|
||||
<Unit filename="../../include/etl/static_assert.h" />
|
||||
<Unit filename="../../include/etl/string_stream.h" />
|
||||
<Unit filename="../../include/etl/string_utilities.h" />
|
||||
<Unit filename="../../include/etl/string_view.h" />
|
||||
<Unit filename="../../include/etl/task.h" />
|
||||
<Unit filename="../../include/etl/temp.h" />
|
||||
@ -578,6 +580,7 @@
|
||||
<Unit filename="../test_string_stream.cpp" />
|
||||
<Unit filename="../test_string_u16.cpp" />
|
||||
<Unit filename="../test_string_u32.cpp" />
|
||||
<Unit filename="../test_string_utilities_char.cpp" />
|
||||
<Unit filename="../test_string_view.cpp" />
|
||||
<Unit filename="../test_string_wchar_t.cpp" />
|
||||
<Unit filename="../test_task_scheduler.cpp" />
|
||||
|
||||
@ -2004,5 +2004,31 @@ namespace
|
||||
CHECK_EQUAL(1, *etl::multimin_iter_compare(std::less<int>(), &i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6], &i[7]));
|
||||
CHECK_EQUAL(8, *etl::multimin_iter_compare(std::greater<int>(), &i[0], &i[1], &i[2], &i[3], &i[4], &i[5], &i[6], &i[7]));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(replace)
|
||||
{
|
||||
int data[] = { 1, 8, 2, 7, 2, 6, 2, 2, 10, 9 };
|
||||
int expected[] = { 1, 8, 0, 7, 0, 6, 0, 0, 10, 9 };
|
||||
|
||||
// Replace 2 with 0
|
||||
etl::replace(std::begin(data), std::end(data), 2, 0);
|
||||
|
||||
bool is_same = std::equal(std::begin(data), std::end(data), std::begin(expected));
|
||||
CHECK(is_same);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(replace_if)
|
||||
{
|
||||
int data[] = { 1, 8, 2, 7, 3, 6, 4, 5, 10, 9 };
|
||||
int expected[] = { 0, 8, 0, 7, 0, 6, 0, 0, 10, 9 };
|
||||
|
||||
// Replace <=5 with 0
|
||||
etl::replace_if(std::begin(data), std::end(data), std::bind(std::less_equal<int>(), std::placeholders::_1, 5), 0);
|
||||
|
||||
bool is_same = std::equal(std::begin(data), std::end(data), std::begin(expected));
|
||||
CHECK(is_same);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -157,7 +157,7 @@
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug Clang|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141_clang_c2</PlatformToolset>
|
||||
<PlatformToolset>ClangCL</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user