1#ifndef NE_STL_INCLUDENE_STL_STRING_
2#define NE_STL_INCLUDENE_STL_STRING_
12#if !defined(NE_STL_OS_WIN)
17template <element_malloc_fun_t<
char> _malloc = memory::safe_malloc_container_element<
char>,
18 element_delete_fun_t<
char> _delete = memory::safe_delete_container_element<
char>>
104 other._str =
nullptr;
108 other.malloc_fun_ =
nullptr;
109 other.delete_fun_ =
nullptr;
114 if (other !=
nullptr) {
121 if (
this != &other) {
129 append(std_string.c_str());
132 operator std::string()
const {
133 std::string ret(
c_str());
171 const char&
at(std::size_t i)
const {
176 char&
at(std::size_t i) {
251 char* buffer =
nullptr;
253 if (buffer ==
nullptr)
264 if (s ==
nullptr || strlen(s) == 0)
268 char* buffer =
nullptr;
270 if (buffer ==
nullptr)
277 char* buffer =
nullptr;
279 if (buffer ==
nullptr)
286 const std::size_t n =
_getLength(first, second);
288 char* buffer =
nullptr;
290 if (buffer ==
nullptr)
309 char* buffer =
nullptr;
320 char* buffer =
nullptr;
327 char* buffer =
nullptr;
334 char* buffer =
nullptr;
347 char* buffer =
nullptr;
376 char* buffer =
nullptr;
378 _replace(pos, len, buffer, strlen(buffer));
390 _string&
replace(std::size_t pos, std::size_t len,
const char* other, std::size_t n) {
399 char* buffer =
nullptr;
406 char* buffer =
nullptr;
413 const std::size_t n =
_getLength(first, second);
414 char* buffer =
nullptr;
422 _string temp = std::move(*
this);
423 *
this = std::move(other);
424 other = std::move(temp);
433 if (other ==
nullptr)
437 void _append(
const char* other, std::size_t n) {
438 if (!other || n == 0)
443 operator[](
_str_len + i) = other[i];
448 if (other !=
nullptr)
451 void _insert_str(std::size_t pos,
const char* other, std::size_t n) {
463 char* buffer =
nullptr;
467 _append(buffer, strlen(buffer));
474 if (other ==
nullptr) {
478 for (std::size_t i = 0; i < len; ++i) {
479 buffer[i] = other[pos + i];
482 void _erase(std::size_t pos, std::size_t len) {
484 for (std::size_t i = pos + len; i <
_str_len; ++i)
488 void _replace(std::size_t pos, std::size_t len,
const char* other, std::size_t n) {
490 char* buffer =
nullptr;
493 char* replace_buffer =
nullptr;
494 _substr(replace_buffer, other, 0, n);
513 std::size_t
copy(
char* s, std::size_t len, std::size_t pos = 0)
const {
517 for (std::size_t i = 0; i < len; ++i)
523 std::size_t
find(
const char* s, std::size_t pos = 0)
const {
return _find(s, strlen(s), pos); }
524 std::size_t
find(
const char* s, std::size_t pos, std::size_t n)
const {
return _find(s, n, pos); }
525 std::size_t
find(
char c, std::size_t pos = 0)
const {
return _find(&c, 1, pos); }
529 std::size_t
rfind(
const char* s, std::size_t pos, std::size_t n)
const {
return _rfind(s, n, pos); }
562 char* buffer =
nullptr;
570 std::size_t
_find(
const char* other, std::size_t len, std::size_t pos)
const {
574 for (; pos <=
_str_len - len; ++pos)
575 if (
operator[](pos) == *other &&
_find_compare(other, len, pos)) {
581 std::size_t
_rfind(
const char* other, std::size_t len, std::size_t pos)
const {
586 for (std::size_t i = pos; 0 <= i; --i)
587 if (
operator[](i) == *other &&
_find_compare(other, len, i)) {
593 bool _find_compare(
const char* other, std::size_t len, std::size_t pos)
const {
594 for (std::size_t i = 1; i < len; ++i)
595 if (
operator[](pos + i) != *(other + i))
599 std::size_t
_find_first_of(
const char* other, std::size_t len, std::size_t pos,
bool isTrue)
const {
611 std::size_t
_find_last_of(
const char* other, std::size_t len, std::size_t pos,
bool isTrue)
const {
616 for (std::size_t i = pos; 0 <= i; --i)
623 bool _find_of_compare(
const char* other, std::size_t len, std::size_t pos,
bool isTrue)
const {
624 for (std::size_t i = 0; i < len; ++i)
625 if (
operator[](pos) == *(other + i))
689 for (std::size_t i = 0; i <
_str_len; ++i)
690 operator[](i) = buffer[i];
723 for (std::size_t i = 0; i < n; ++i)
724 buffer[i] = *
begin++;
726 void _fill_str(
char* other,
const std::size_t len, std::size_t pos,
char c)
const {
727 if (other ==
nullptr)
729 std::size_t
begin = pos;
742 return memory::safe_malloc_container_element<char>(count);
750 memory::safe_delete_container_element<char>(data);
765 static uint32_t abs(uint32_t value) {
return value; };
766 static uint64_t abs(uint64_t value) {
return value; };
767 static int32_t abs(int32_t value) { return ::abs(value); };
768 static int64_t abs(int64_t value) {
770 return ::_abs64(value);
772 return (int64_t)::fabs(value);
777typename std::enable_if<std::numeric_limits<T>::is_signed,
bool>::type is_valuenegative(T value) {
778 static_assert(std::numeric_limits<T>::is_specialized,
"Argument must be numeric.");
782typename std::enable_if<!std::numeric_limits<T>::is_signed,
bool>::type is_valuenegative(T) {
783 static_assert(std::numeric_limits<T>::is_specialized,
"Argument must be numeric.");
786template <
typename TInt>
788 const size_t kOutputBufSize = 3 *
sizeof(TInt) + std::numeric_limits<TInt>::is_signed;
790 chr_t outbuf[kOutputBufSize];
791 auto res = _ABS::abs(value);
792 chr_t* end = outbuf + kOutputBufSize;
796 *i =
static_cast<chr_t
>((res % 10) +
'0');
799 if (is_valuenegative(value)) {
801 *i =
static_cast<chr_t
>(
'-');
809struct std::hash<
nstd::string> {
Definition: ne_stl_iterator.h:22
nstd::iterator_type< TElement > & current()
Definition: ne_stl_iterator.h:32
Definition: ne_stl_iterator.h:159
Definition: ne_stl_iterator.h:108
Definition: ne_stl_iterator.h:242
Definition: ne_stl_string.h:19
iterator begin()
Definition: ne_stl_string.h:187
char value_type
Definition: ne_stl_string.h:21
_string & operator+=(char c)
Definition: ne_stl_string.h:225
_string & replace(const_iterator i1, const_iterator i2, const char *other, std::size_t n)
Definition: ne_stl_string.h:394
std::size_t _str_len
Definition: ne_stl_string.h:756
_string & operator+=(const char *s)
Definition: ne_stl_string.h:221
~_string()
Definition: ne_stl_string.h:138
_string & operator+=(const _string &s)
Definition: ne_stl_string.h:217
std::size_t _getLength(const const_iterator first, const const_iterator second)
Definition: ne_stl_string.h:205
std::size_t find_last_of(const char *other, std::size_t pos=nstd::container_npos::value) const
Definition: ne_stl_string.h:540
friend bool operator<(const _string &lhs, const _string &rhs)
Definition: ne_stl_string.h:148
std::size_t copy(char *s, std::size_t len, std::size_t pos=0) const
Definition: ne_stl_string.h:513
bool _find_compare(const char *other, std::size_t len, std::size_t pos) const
Definition: ne_stl_string.h:593
friend bool operator!=(const _string &lhs, const _string &rhs)
Definition: ne_stl_string.h:147
const char & operator[](std::size_t i) const
Definition: ne_stl_string.h:169
void reserve(std::size_t n=0)
Definition: ne_stl_string.h:655
const_iterator end() const
Definition: ne_stl_string.h:190
char * _str
Definition: ne_stl_string.h:755
friend bool operator>=(const _string &lhs, const _string &rhs)
Definition: ne_stl_string.h:151
const_reverse_iterator rbegin() const
Definition: ne_stl_string.h:195
void insert(iterator p, std::size_t n, char c)
Definition: ne_stl_string.h:333
std::size_t _find_first_of(const char *other, std::size_t len, std::size_t pos, bool isTrue) const
Definition: ne_stl_string.h:599
std::size_t find_first_not_of(const char *other, std::size_t pos=0) const
Definition: ne_stl_string.h:547
_string & operator=(const std::string &std_string)
Definition: ne_stl_string.h:127
const char & back() const
Definition: ne_stl_string.h:183
std::size_t _find(const char *other, std::size_t len, std::size_t pos) const
Definition: ne_stl_string.h:570
_string(const char *copy)
Definition: ne_stl_string.h:59
const_iterator cbegin() const
Definition: ne_stl_string.h:191
char & back()
Definition: ne_stl_string.h:184
std::size_t rfind(const _string &other, std::size_t pos=container_npos::value) const
Definition: ne_stl_string.h:527
std::size_t find_last_not_of(const char *other, std::size_t pos=nstd::container_npos::value) const
Definition: ne_stl_string.h:554
const char & at(std::size_t i) const
Definition: ne_stl_string.h:171
std::size_t _rfind(const char *other, std::size_t len, std::size_t pos) const
Definition: ne_stl_string.h:581
friend bool operator>(const _string &lhs, const _string &rhs)
Definition: ne_stl_string.h:149
string_iterator_type _end() const
Definition: ne_stl_string.h:204
const_reverse_iterator rend() const
Definition: ne_stl_string.h:197
_string(std::size_t n, char c)
Definition: ne_stl_string.h:77
string_iterator_type _ibegin() const
Definition: ne_stl_string.h:202
std::size_t find_first_not_of(const char *other, std::size_t pos, std::size_t n) const
Definition: ne_stl_string.h:548
_string & replace(const_iterator i1, const_iterator i2, const _string &other)
Definition: ne_stl_string.h:370
void _append(const char *other)
Definition: ne_stl_string.h:432
std::size_t _getLength(const _string &str, std::size_t pos, std::size_t len=container_npos::value) const
Definition: ne_stl_string.h:500
std::size_t find_last_of(char c, std::size_t pos=nstd::container_npos::value) const
Definition: ne_stl_string.h:544
_string(const char *s, std::size_t n)
Definition: ne_stl_string.h:68
std::size_t find_first_of(const char *other, std::size_t pos=0) const
Definition: ne_stl_string.h:533
iterator insert(iterator p, char c)
Definition: ne_stl_string.h:339
nstd::iterator_type< char > string_iterator_type
Definition: ne_stl_string.h:24
_string(const const_iterator first, const const_iterator second)
Definition: ne_stl_string.h:86
const_iterator begin() const
Definition: ne_stl_string.h:188
void clear()
Definition: ne_stl_string.h:666
friend bool operator==(const _string &lhs, const _string &rhs)
Definition: ne_stl_string.h:146
bool empty() const
Definition: ne_stl_string.h:667
_string & append(const _string &other, std::size_t subpos, std::size_t sublen=container_npos::value)
Definition: ne_stl_string.h:249
void _substr(char *&buffer, const char *other, std::size_t pos=0, std::size_t len=container_npos::value) const
Definition: ne_stl_string.h:473
_string(const _string &other)
Definition: ne_stl_string.h:41
std::size_t find(const _string &other, std::size_t pos=0) const
Definition: ne_stl_string.h:522
std::size_t rfind(const char *s, std::size_t pos=container_npos::value) const
Definition: ne_stl_string.h:528
std::size_t find_first_of(const _string &other, std::size_t pos=0) const
Definition: ne_stl_string.h:532
void _alloc_cstring(char *&buffer, const std::size_t n, const const_iterator i1, const const_iterator i2) const
Definition: ne_stl_string.h:720
_string operator+(char c) const
Definition: ne_stl_string.h:239
void swap(_string &other)
Definition: ne_stl_string.h:421
std::size_t find_first_not_of(char c, std::size_t pos=0) const
Definition: ne_stl_string.h:549
void _increaseCapacity(const std::size_t cap)
Definition: ne_stl_string.h:695
char & at(std::size_t i)
Definition: ne_stl_string.h:176
void _replace(std::size_t pos, std::size_t len, const char *other, std::size_t n)
Definition: ne_stl_string.h:488
_string()
Definition: ne_stl_string.h:31
_string(const _string &other, std::size_t pos, std::size_t len=container_npos::value)
Definition: ne_stl_string.h:50
void resize(std::size_t n, char c)
Definition: ne_stl_string.h:643
string_iterator_type _rbegin() const
Definition: ne_stl_string.h:203
_string & replace(std::size_t pos, std::size_t len, const char *s)
Definition: ne_stl_string.h:382
void _insert_str(std::size_t pos, const char *other)
Definition: ne_stl_string.h:447
_string & insert(std::size_t pos, std::size_t n, char c)
Definition: ne_stl_string.h:326
void _append(const char *other, std::size_t n)
Definition: ne_stl_string.h:437
std::size_t find_last_of(const char *other, std::size_t pos, std::size_t n) const
Definition: ne_stl_string.h:543
_string & replace(const_iterator i1, const_iterator i2, const char *other)
Definition: ne_stl_string.h:386
std::size_t find(char c, std::size_t pos=0) const
Definition: ne_stl_string.h:525
_string & replace(std::size_t pos, std::size_t len, std::size_t n, char c)
Definition: ne_stl_string.h:398
void resize(std::size_t n)
Definition: ne_stl_string.h:634
void _delete_data(char *&data) const
Definition: ne_stl_string.h:744
std::size_t _increaseBy
Definition: ne_stl_string.h:758
_string & replace(std::size_t pos, std::size_t len, const _string &other, std::size_t subpos, std::size_t sublen=container_npos::value)
Definition: ne_stl_string.h:374
_string & replace(const_iterator i1, const_iterator i2, const_iterator first, const_iterator second)
Definition: ne_stl_string.h:412
void _fill_str(char *other, const std::size_t len, std::size_t pos, char c) const
Definition: ne_stl_string.h:726
void _alloc_cstring(char *&buffer, const std::size_t n, char c) const
Definition: ne_stl_string.h:716
reverse_iterator rbegin()
Definition: ne_stl_string.h:194
std::size_t rfind(char c, std::size_t pos=container_npos::value) const
Definition: ne_stl_string.h:530
bool _find_of_compare(const char *other, std::size_t len, std::size_t pos, bool isTrue) const
Definition: ne_stl_string.h:623
std::size_t find_first_of(char c, std::size_t pos=0) const
Definition: ne_stl_string.h:535
char * _new_data(std::size_t count) const
Definition: ne_stl_string.h:738
_string & insert(std::size_t pos, const char *s, std::size_t n)
Definition: ne_stl_string.h:319
_string & operator=(const _string &other)
Definition: ne_stl_string.h:120
const_iterator cend() const
Definition: ne_stl_string.h:192
iterator erase(const_iterator p)
Definition: ne_stl_string.h:357
std::size_t capacity() const
Definition: ne_stl_string.h:654
std::size_t find(const char *s, std::size_t pos=0) const
Definition: ne_stl_string.h:523
char & operator[](std::size_t i)
Definition: ne_stl_string.h:170
iterator end()
Definition: ne_stl_string.h:189
std::size_t length() const
Definition: ne_stl_string.h:631
_string & operator=(const char *other)
Definition: ne_stl_string.h:113
void shrink_to_fit()
Definition: ne_stl_string.h:668
const_reverse_iterator crend() const
Definition: ne_stl_string.h:199
std::size_t max_size() const
Definition: ne_stl_string.h:633
_string & append(std::size_t n, char c)
Definition: ne_stl_string.h:276
const_reverse_iterator crbegin() const
Definition: ne_stl_string.h:198
_string & replace(std::size_t pos, std::size_t len, const char *other, std::size_t n)
Definition: ne_stl_string.h:390
element_malloc_fun_t< char > malloc_fun_
Definition: ne_stl_string.h:759
void insert(iterator p, const const_iterator begin, const const_iterator last)
Definition: ne_stl_string.h:343
std::size_t find_first_of(const char *other, std::size_t pos, std::size_t n) const
Definition: ne_stl_string.h:534
std::size_t _str_cap
Definition: ne_stl_string.h:757
void _decreaseCapacity(const std::size_t cap)
Definition: ne_stl_string.h:704
_string & insert(std::size_t pos, const _string &other, std::size_t subpos, std::size_t sublen=container_npos::value)
Definition: ne_stl_string.h:307
std::size_t rfind(const char *s, std::size_t pos, std::size_t n) const
Definition: ne_stl_string.h:529
_string & append(const char *other)
Definition: ne_stl_string.h:259
_string(const std::string &other)
Definition: ne_stl_string.h:95
_string & replace(const_iterator i1, const_iterator i2, std::size_t n, char c)
Definition: ne_stl_string.h:405
char & front()
Definition: ne_stl_string.h:182
int32_t _compare(const _string &rhs) const
Definition: ne_stl_string.h:154
void _clear_str(const std::size_t pos)
Definition: ne_stl_string.h:734
element_delete_fun_t< char > delete_fun_
Definition: ne_stl_string.h:760
_string(_string &&other)
Definition: ne_stl_string.h:97
void _setCapacity(const std::size_t cap)
Definition: ne_stl_string.h:678
std::size_t find_last_of(const _string &other, std::size_t pos=nstd::container_npos::value) const
Definition: ne_stl_string.h:537
std::size_t find(const char *s, std::size_t pos, std::size_t n) const
Definition: ne_stl_string.h:524
void _erase(std::size_t pos, std::size_t len)
Definition: ne_stl_string.h:482
_string & insert(std::size_t pos, const _string &other)
Definition: ne_stl_string.h:303
friend bool operator<=(const _string &lhs, const _string &rhs)
Definition: ne_stl_string.h:150
std::size_t find_first_not_of(const _string &other, std::size_t pos=0) const
Definition: ne_stl_string.h:546
const char * c_str() const
Definition: ne_stl_string.h:511
reverse_iterator rend()
Definition: ne_stl_string.h:196
std::size_t find_last_not_of(const _string &other, std::size_t pos=nstd::container_npos::value) const
Definition: ne_stl_string.h:551
_string & append(const const_iterator first, const const_iterator second)
Definition: ne_stl_string.h:285
std::size_t find_last_not_of(char c, std::size_t pos=nstd::container_npos::value) const
Definition: ne_stl_string.h:558
void _insert_str(std::size_t pos, const char *other, std::size_t n)
Definition: ne_stl_string.h:451
_string & pop_back()
Definition: ne_stl_string.h:426
_string & append(const _string &other)
Definition: ne_stl_string.h:245
void _setLength(const std::size_t len)
Definition: ne_stl_string.h:671
_string operator+(const char *s) const
Definition: ne_stl_string.h:234
_string substr(std::size_t pos=0, std::size_t len=container_npos::value) const
Definition: ne_stl_string.h:560
void _alloc_cstring(char *&buffer, const std::size_t n) const
Definition: ne_stl_string.h:711
_string operator+(const _string &s) const
Definition: ne_stl_string.h:229
_string & erase(std::size_t pos=0, std::size_t len=container_npos::value)
Definition: ne_stl_string.h:353
iterator erase(const_iterator first, const_iterator last)
Definition: ne_stl_string.h:361
_string & push_back(char c)
Definition: ne_stl_string.h:298
std::size_t find_last_not_of(const char *other, std::size_t pos, std::size_t n) const
Definition: ne_stl_string.h:557
_string & append(const char *s, std::size_t n)
Definition: ne_stl_string.h:263
_string & insert(std::size_t pos, const char *other)
Definition: ne_stl_string.h:315
std::size_t _find_last_of(const char *other, std::size_t len, std::size_t pos, bool isTrue) const
Definition: ne_stl_string.h:611
_string & replace(std::size_t pos, std::size_t len, const _string &other)
Definition: ne_stl_string.h:366
const char & front() const
Definition: ne_stl_string.h:181
std::size_t size() const
Definition: ne_stl_string.h:632
Definition: ne_stl_any.h:7
void(*)(TElement *&) element_delete_fun_t
Definition: ne_stl_memory.h:13
TElement *(*)(std::size_t) element_malloc_fun_t
Definition: ne_stl_memory.h:10
_string<> string
Definition: ne_stl_string.h:762
#define false
Definition: stdbool.h:33
Definition: ne_stl_value_def.h:12
static const T value
Definition: ne_stl_type_traits.h:10
Definition: ne_stl_iterator.h:9
std::size_t operator()(const nstd::string &ne_str) const noexcept
Definition: ne_stl_string.h:810