5#ifndef DCPP_STRING_HPP_INCLUDED
6#define DCPP_STRING_HPP_INCLUDED
8#include <duckcpp/core/engine/dcpp_types.hpp>
9#include <duckcpp/core/engine/irrAllocator.hpp>
10#include <duckcpp/core/engine/irrMath.hpp>
34template <
typename T,
typename TAlloc = irrAllocator<T> >
49 DCPP_LOCALE_GERMAN = 1
52static eLocaleID locale_current = DCPP_LOCALE_ANSI;
53static inline void locale_set ( eLocaleID
id )
61 switch ( locale_current )
63 case DCPP_LOCALE_GERMAN:
64 case DCPP_LOCALE_ANSI:
68 return x >=
'A' && x <=
'Z' ? x + 0x20 : x;
74 switch ( locale_current )
76 case DCPP_LOCALE_GERMAN:
77 case DCPP_LOCALE_ANSI:
82 return x >=
'a' && x <=
'z' ? x + (
'A' -
'a' ) : x;
98template <
typename T,
typename TAlloc>
111 :
array(0), allocated(1), used(1)
113 array = allocator.allocate(1);
120 :
array(0), allocated(0), used(0)
126 template <
class B,
class A>
128 :
array(0), allocated(0), used(0)
136 :
array(0), allocated(0), used(0)
138 std::ostringstream
tmpbuf;
140 *
this =
tmpbuf.str().data();
146 :
array(0), allocated(0), used(0)
194 :
array(0), allocated(0), used(0)
225 :
array(0), allocated(0), used(0)
273 :
array(0), allocated(0), used(0)
305 :
array(0), allocated(0), used(0)
314 allocated = used =
length+1;
315 array = allocator.allocate(used);
327 :
array(0), allocated(0), used(0)
338 allocator.deallocate(
array);
348 used =
other.size()+1;
351 allocator.deallocate(
array);
353 array = allocator.allocate(used);
364 template <
class B,
class A>
367 *
this =
other.data();
380 array = allocator.allocate(1);
388 if ((
void*)c == (
void*)
array)
406 array = allocator.allocate(used);
443 DCPP_DEBUG_BREAK_IF(index>=used)
451 DCPP_DEBUG_BREAK_IF(index>=used)
478 return used ==
other.used;
492 return (used <
other.used);
499 return !(*
this ==
str);
506 return !(*
this ==
other);
522 return (
size() == 0);
545 std::basic_string<T>
str()
const
552 explicit operator std::basic_string<T> ()
const
581 if (locale_lower(
array[i]) != locale_lower(
other[i]))
584 return used ==
other.used;
617 return used <
other.used;
634 return (i ==
n) || (used ==
other.used);
647 for(i=0; i <
n &&
array[i] &&
str[i]; ++i)
653 return (i ==
n) || (
array[i] == 0 &&
str[i] == 0);
661 if (used + 1 > allocated)
662 reallocate(used + 1);
691 if (used +
len > allocated)
692 reallocate(used +
len);
710 if (
other.size() == 0)
716 if (used +
len > allocated)
717 reallocate(used +
len);
733 if (
other.size() == 0)
742 if (used +
length > allocated)
743 reallocate(used +
length);
789 if (count < allocated)
846 for (
j=0;
j<count; ++
j)
873 for (
j=0;
j<count; ++
j)
989 o.array[i] =
array[i+begin];
994 o.array[i] = locale_lower (
array[i+begin] );
1175 if (used +
len > allocated)
1176 reallocate(used +
len);
1187 while (
ptr != start)
1308 return (*
this =
subString(begin, (end +1) - begin));
1353 DCPP_DEBUG_BREAK_IF(index>=used)
1376 if ( allocated > 0 )
1392 return used > 1 ?
array[used-2] : 0;
1414 template<
class container>
1467 if (allocated < used)
1498static inline size_t multibyteToWString(
dcpp::nub::wstring & destination,
const char* source)
1501 return multibyteToWString(destination, source, s);
1510#if defined(_MSC_VER)
1511#pragma warning(push)
1512#pragma warning(disable: 4996)
1515#if defined(_MSC_VER)
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.hpp:22
Self reallocating template array (like stl vector) with additional features.
Definition irrArray.hpp:23
bool equals_substring_ignore_case(const self_type &other, const dcpp::int32_kt sourcePos=0) const
Compares the strings ignoring case.
Definition irrString.hpp:591
self_type & replace(T toReplace, T replaceWith)
Replaces all characters of a special type with another one.
Definition irrString.hpp:1088
basic_string(const dcpp::nub::basic_string< B, A > &other)
Constructor from other string types.
Definition irrString.hpp:127
self_type & insert(dcpp::uint32_kt pos, const char *s, dcpp::uint32_kt n)
Insert a certain amount of characters into the string before the given index.
Definition irrString.hpp:762
dcpp::uint32_kt size() const
Returns length of the string's content.
Definition irrString.hpp:513
self_type & operator=(const self_type &other)
Assignment operator.
Definition irrString.hpp:343
basic_string(const B *const c)
Constructor for Unicode and ASCII strings.
Definition irrString.hpp:326
self_type & append(T character)
Appends a character to this string.
Definition irrString.hpp:659
bool operator!=(const T *const str) const
Inequality operator.
Definition irrString.hpp:497
self_type operator+(const B *const c) const
Append operator for strings, ASCII and Unicode.
Definition irrString.hpp:431
self_type & operator+=(T c)
Appends a character to this string.
Definition irrString.hpp:1006
bool empty() const
Definition irrString.hpp:520
bool operator==(const self_type &other) const
Equality operator.
Definition irrString.hpp:472
self_type & operator=(const B *const c)
Assignment operator for strings, ASCII and Unicode.
Definition irrString.hpp:374
self_type & make_lower()
Makes the string lower case.
Definition irrString.hpp:558
bool operator==(const T *const str) const
Equality operator.
Definition irrString.hpp:457
std::basic_string< T > str() const
Returns std::string or std::wstring. The traits_type and allocator_type of the returned std::basic_st...
Definition irrString.hpp:545
dcpp::int32_kt find(const B *const str, const dcpp::uint32_kt start=0) const
finds another string in this string
Definition irrString.hpp:941
virtual ~basic_string()
Destructor.
Definition irrString.hpp:336
dcpp::int32_kt findNext(T c, dcpp::uint32_kt startPos) const
finds next occurrence of character in string
Definition irrString.hpp:889
bool operator!=(const self_type &other) const
Inequality operator.
Definition irrString.hpp:504
self_type & erase(dcpp::uint32_kt index)
Erases a character from the string.
Definition irrString.hpp:1351
bool lower_ignore_case(const self_type &other) const
Compares the strings ignoring case.
Definition irrString.hpp:608
basic_string(unsigned long number)
Constructs a string from an unsigned long.
Definition irrString.hpp:272
bool operator<(const self_type &other) const
Is smaller comparator.
Definition irrString.hpp:483
dcpp::uint32_kt split(container &ret, const T *const delimiter, dcpp::uint32_kt countDelimiters=1, bool ignoreEmptyTokens=true, bool keepSeparators=false) const
Split string into parts (tokens).
Definition irrString.hpp:1415
T & operator[](const dcpp::uint32_kt index)
Direct access operator.
Definition irrString.hpp:441
self_type & append(const self_type &other)
Appends a string to this string.
Definition irrString.hpp:708
basic_string(int number)
Constructs a string from an int.
Definition irrString.hpp:145
self_type & replace(const self_type &toReplace, const self_type &replaceWith)
Replaces all instances of a string with another one.
Definition irrString.hpp:1100
basic_string()
Default constructor.
Definition irrString.hpp:110
dcpp::int32_kt findFirst(T c) const
finds first occurrence of character in string
Definition irrString.hpp:800
dcpp::int32_kt findLastCharNotInList(const B *const c, dcpp::uint32_kt count=1) const
Finds last position of a character not in a given list.
Definition irrString.hpp:865
self_type & remove(const self_type &toRemove)
Removes a string from the string.
Definition irrString.hpp:1230
T lastChar() const
gets the last char of a string or null
Definition irrString.hpp:1390
void reserve(dcpp::uint32_kt count)
Reserves some memory.
Definition irrString.hpp:787
friend size_t multibyteToWString(dcpp::nub::wstring &destination, const char *source, dcpp::uint32_kt sourceSize)
Internally used by the other multibyteToWString functions.
Definition irrString.hpp:1505
basic_string(long number)
Constructs a string from a long.
Definition irrString.hpp:224
dcpp::int32_kt findLast(T c, dcpp::int32_kt start=-1) const
finds last occurrence of character in string
Definition irrString.hpp:904
basic_string(const B *const c, dcpp::uint32_kt length)
Constructor for copying a string from a pointer with a given length.
Definition irrString.hpp:304
self_type & eraseTrailingFloatZeros(char decimalPoint='.')
Erase 0's at the end when a string ends with a floating point number.
Definition irrString.hpp:1320
bool equals_ignore_case(const self_type &other) const
Compares the strings ignoring case.
Definition irrString.hpp:578
self_type & trim(const self_type &whitespace=" \t\n\r")
Trims the string.
Definition irrString.hpp:1299
self_type & append(const self_type &other, dcpp::uint32_kt length)
Appends a string of the length l to this string.
Definition irrString.hpp:731
self_type & removeChars(const self_type &characters)
Removes characters from a string.
Definition irrString.hpp:1263
self_type & append(const T *const other, dcpp::uint32_kt length=0xffffffff)
Appends a char string to this string.
Definition irrString.hpp:676
dcpp::int32_kt findFirstCharNotInList(const B *const c, dcpp::uint32_kt count=1) const
Finds first position of a character not in a given list.
Definition irrString.hpp:838
dcpp::int32_kt findLastChar(const T *const c, dcpp::uint32_kt count=1) const
finds last occurrence of a character of a list in string
Definition irrString.hpp:921
self_type & remove(T c)
Removes characters from a string.
Definition irrString.hpp:1208
bool equalsn(const self_type &other, dcpp::uint32_kt n) const
compares the first n characters of the strings
Definition irrString.hpp:625
bool equalsn(const T *const str, dcpp::uint32_kt n) const
compares the first n characters of the strings
Definition irrString.hpp:642
const T * data() const
Returns character string.
Definition irrString.hpp:537
self_type operator+(const self_type &other) const
Append operator for other strings.
Definition irrString.hpp:420
self_type subString(dcpp::uint32_kt begin, dcpp::int32_kt length, bool make_lower=false) const
Returns a substring.
Definition irrString.hpp:973
const T & operator[](const dcpp::uint32_kt index) const
Direct access operator.
Definition irrString.hpp:449
basic_string(const double number)
Constructs a string from a float.
Definition irrString.hpp:135
self_type & operator=(const dcpp::nub::basic_string< B, A > &other)
Assignment operator for other string types.
Definition irrString.hpp:365
self_type & make_upper()
Makes the string upper case.
Definition irrString.hpp:567
dcpp::int32_kt findFirstChar(const T *const c, dcpp::uint32_kt count=1) const
finds first occurrence of a character of a list in string
Definition irrString.hpp:816
basic_string(unsigned int number)
Constructs a string from an unsigned int.
Definition irrString.hpp:193
self_type & validate()
verify the existing string.
Definition irrString.hpp:1363
basic_string(const self_type &other)
Constructor.
Definition irrString.hpp:119
Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.
Definition vector3d.hpp:13
DUCKCPP_API void wcharToUtf8(const wchar_t *in, char *out, const dcpp::uint64_kt len)
Convert this wchar string to utf-8.
DUCKCPP_API void utf8ToWchar(const char *in, wchar_t *out, const dcpp::uint64_kt len)
Convert this utf-8-encoded string to the platform's wchar.
dcpp::int32_kt isdigit(dcpp::int32_kt c)
some standard function ( to remove dependencies )
Definition coreutil.hpp:197
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.hpp:164
char char_kt
8 bit character variable.
Definition irrTypes.hpp:37
unsigned int uint32_kt
32 bit unsigned variable.
Definition irrTypes.hpp:64
signed int int32_kt
32 bit signed variable.
Definition irrTypes.hpp:72