5#ifndef NIRT_STRING_HPP_INCLUDED
6#define NIRT_STRING_HPP_INCLUDED
8#include <nirtcpp/core/engine/nirt_types.hpp>
9#include <nirtcpp/core/engine/irrAllocator.hpp>
10#include <nirtcpp/core/engine/irrMath.hpp>
35template <
typename T,
typename TAlloc = irrAllocator<T> >
37static size_t multibyteToWString(string<wchar_t>& destination,
const char* source,
u32 sourceSize);
43 NIRT_LOCALE_GERMAN = 1
46static eLocaleID locale_current = NIRT_LOCALE_ANSI;
47static inline void locale_set ( eLocaleID
id )
53static inline u32 locale_lower (
u32 x )
55 switch ( locale_current )
57 case NIRT_LOCALE_GERMAN:
58 case NIRT_LOCALE_ANSI:
62 return x >=
'A' && x <=
'Z' ? x + 0x20 : x;
66static inline u32 locale_upper (
u32 x )
68 switch ( locale_current )
70 case NIRT_LOCALE_GERMAN:
71 case NIRT_LOCALE_ANSI:
76 return x >=
'a' && x <=
'z' ? x + (
'A' -
'a' ) : x;
92template <
typename T,
typename TAlloc>
101 :
array(0), allocated(1), used(1)
103 array = allocator.allocate(1);
110 :
array(0), allocated(0), used(0)
116 template <
class B,
class A>
118 :
array(0), allocated(0), used(0)
126 :
array(0), allocated(0), used(0)
128 std::ostringstream
tmpbuf;
130 *
this =
tmpbuf.str().data();
136 :
array(0), allocated(0), used(0)
184 :
array(0), allocated(0), used(0)
215 :
array(0), allocated(0), used(0)
263 :
array(0), allocated(0), used(0)
295 :
array(0), allocated(0), used(0)
304 allocated = used =
length+1;
305 array = allocator.allocate(used);
317 :
array(0), allocated(0), used(0)
326 allocator.deallocate(
array);
336 used =
other.size()+1;
339 allocator.deallocate(
array);
341 array = allocator.allocate(used);
345 for (
u32 i=0; i<used; ++i, ++
p)
352 template <
class B,
class A>
355 *
this =
other.data();
368 array = allocator.allocate(1);
376 if ((
void*)c == (
void*)
array)
394 array = allocator.allocate(used);
431 NIRT_DEBUG_BREAK_IF(index>=used)
439 NIRT_DEBUG_BREAK_IF(index>=used)
466 return used ==
other.used;
480 return (used <
other.used);
487 return !(*
this ==
str);
494 return !(*
this ==
other);
510 return (
size() == 0);
555 if (locale_lower(
array[i]) != locale_lower(
other[i]))
558 return used ==
other.used;
591 return used <
other.used;
608 return (i ==
n) || (used ==
other.used);
621 for(i=0; i <
n &&
array[i] &&
str[i]; ++i)
627 return (i ==
n) || (
array[i] == 0 &&
str[i] == 0);
635 if (used + 1 > allocated)
636 reallocate(used + 1);
665 if (used +
len > allocated)
666 reallocate(used +
len);
684 if (
other.size() == 0)
690 if (used +
len > allocated)
691 reallocate(used +
len);
707 if (
other.size() == 0)
716 if (used +
length > allocated)
717 reallocate(used +
length);
743 const u32 end = used+
n-1;
744 for (
u32 i=0; i<used-pos; ++i)
750 for (
u32 i=0; i<
n; ++i)
763 if (count < allocated)
776 for (
u32 i=0; i<used-1; ++i)
795 for (
u32 i=0; i<used-1; ++i)
796 for (
u32 j=0;
j<count; ++
j)
817 for (
u32 i=0; i<used-1; ++i)
820 for (
j=0;
j<count; ++
j)
844 for (
s32 i=(
s32)(used-2); i>=0; --i)
847 for (
j=0;
j<count; ++
j)
881 for (
s32 i=start; i>=0; --i)
900 for (
s32 i=(
s32)used-2; i>=0; --i)
901 for (
u32 j=0;
j<count; ++
j)
927 for (
u32 i=start; i<used-
len; ++i)
963 o.array[i] =
array[i+begin];
968 o.array[i] = locale_lower (
array[i+begin] );
1064 for (
u32 i=0; i<used-1; ++i)
1104 for (
u32 pos = 0; pos < used; ++i, ++pos)
1149 if (used +
len > allocated)
1150 reallocate(used +
len);
1161 while (
ptr != start)
1186 for (
u32 i=0; i<used-1; ++i)
1211 for (
u32 i=0; i<used-1; ++i)
1244 for (
u32 i=0; i<used-1; ++i)
1282 return (*
this =
subString(begin, (end +1) - begin));
1297 if ( i > 0 && (
u32)i < used-2 )
1327 NIRT_DEBUG_BREAK_IF(index>=used)
1329 for (
u32 i=index+1; i<used; ++i)
1340 for (
u32 i=0; i<allocated; ++i)
1350 if ( allocated > 0 )
1366 return used > 1 ?
array[used-2] : 0;
1388 template<
class container>
1397 for (
u32 i=0; i<used; ++i)
1441 if (allocated < used)
1479static inline size_t multibyteToWString(string<wchar_t>& destination,
const char* source)
1481 const u32 s = source ? (
u32)strlen(source) : 0;
1482 return multibyteToWString(destination, source, s);
1491#if defined(_MSC_VER)
1492#pragma warning(push)
1493#pragma warning(disable: 4996)
1496#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
Very simple string class with some useful features.
Definition irrString.hpp:94
bool equals_substring_ignore_case(const string< T, TAlloc > &other, const s32 sourcePos=0) const
Compares the strings ignoring case.
Definition irrString.hpp:565
bool operator!=(const T *const str) const
Inequality operator.
Definition irrString.hpp:485
string(const B *const c, u32 length)
Constructor for copying a string from a pointer with a given length.
Definition irrString.hpp:294
string< T, TAlloc > & erase(u32 index)
Erases a character from the string.
Definition irrString.hpp:1325
bool equalsn(const string< T, TAlloc > &other, u32 n) const
compares the first n characters of the strings
Definition irrString.hpp:599
string< T, TAlloc > & remove(T c)
Removes characters from a string.
Definition irrString.hpp:1182
T & operator[](const u32 index)
Direct access operator.
Definition irrString.hpp:429
string(int number)
Constructs a string from an int.
Definition irrString.hpp:135
string< T > subString(u32 begin, s32 length, bool make_lower=false) const
Returns a substring.
Definition irrString.hpp:947
string< T, TAlloc > & trim(const string< T, TAlloc > &whitespace=" \t\n\r")
Trims the string.
Definition irrString.hpp:1273
bool operator==(const string< T, TAlloc > &other) const
Equality operator.
Definition irrString.hpp:460
bool operator==(const T *const str) const
Equality operator.
Definition irrString.hpp:445
bool equals_ignore_case(const string< T, TAlloc > &other) const
Compares the strings ignoring case.
Definition irrString.hpp:552
bool equalsn(const T *const str, u32 n) const
compares the first n characters of the strings
Definition irrString.hpp:616
s32 findFirstChar(const T *const c, u32 count=1) const
finds first occurrence of a character of a list in string
Definition irrString.hpp:790
s32 findFirst(T c) const
finds first occurrence of character in string
Definition irrString.hpp:774
bool lower_ignore_case(const string< T, TAlloc > &other) const
Compares the strings ignoring case.
Definition irrString.hpp:582
s32 findLastChar(const T *const c, u32 count=1) const
finds last occurrence of a character of a list in string
Definition irrString.hpp:895
string< T, TAlloc > & removeChars(const string< T, TAlloc > &characters)
Removes characters from a string.
Definition irrString.hpp:1237
string(unsigned int number)
Constructs a string from an unsigned int.
Definition irrString.hpp:183
string< T, TAlloc > operator+(const B *const c) const
Append operator for strings, ASCII and Unicode.
Definition irrString.hpp:419
string(const string< B, A > &other)
Constructor from other string types.
Definition irrString.hpp:117
string< T, TAlloc > & operator+=(T c)
Appends a character to this string.
Definition irrString.hpp:980
string< T, TAlloc > & make_lower()
Makes the string lower case.
Definition irrString.hpp:532
bool operator<(const string< T, TAlloc > &other) const
Is smaller comparator.
Definition irrString.hpp:471
string< T, TAlloc > & remove(const string< T, TAlloc > &toRemove)
Removes a string from the string.
Definition irrString.hpp:1204
s32 findNext(T c, u32 startPos) const
finds next occurrence of character in string
Definition irrString.hpp:863
string< T, TAlloc > & replace(T toReplace, T replaceWith)
Replaces all characters of a special type with another one.
Definition irrString.hpp:1062
s32 findFirstCharNotInList(const B *const c, u32 count=1) const
Finds first position of a character not in a given list.
Definition irrString.hpp:812
const T * data() const
Returns character string.
Definition irrString.hpp:525
string(const B *const c)
Constructor for Unicode and ASCII strings.
Definition irrString.hpp:316
string< T, TAlloc > & operator=(const string< B, A > &other)
Assignment operator for other string types.
Definition irrString.hpp:353
string< T, TAlloc > & append(T character)
Appends a character to this string.
Definition irrString.hpp:633
string< T, TAlloc > & operator=(const string< T, TAlloc > &other)
Assignment operator.
Definition irrString.hpp:331
string< T, TAlloc > & append(const string< T, TAlloc > &other, u32 length)
Appends a string of the length l to this string.
Definition irrString.hpp:705
string< T, TAlloc > operator+(const string< T, TAlloc > &other) const
Append operator for other strings.
Definition irrString.hpp:408
string(const double number)
Constructs a string from a float.
Definition irrString.hpp:125
string()
Default constructor.
Definition irrString.hpp:100
bool operator!=(const string< T, TAlloc > &other) const
Inequality operator.
Definition irrString.hpp:492
bool empty() const
Definition irrString.hpp:508
string< T, TAlloc > & append(const string< T, TAlloc > &other)
Appends a string to this string.
Definition irrString.hpp:682
T lastChar() const
gets the last char of a string or null
Definition irrString.hpp:1364
u32 split(container &ret, const T *const delimiter, u32 countDelimiters=1, bool ignoreEmptyTokens=true, bool keepSeparators=false) const
Split string into parts (tokens).
Definition irrString.hpp:1389
string(unsigned long number)
Constructs a string from an unsigned long.
Definition irrString.hpp:262
friend size_t multibyteToWString(string< wchar_t > &destination, const char *source, u32 sourceSize)
Internally used by the other multibyteToWString functions.
Definition irrString.hpp:1486
~string()
Destructor.
Definition irrString.hpp:324
string< T, TAlloc > & eraseTrailingFloatZeros(char decimalPoint='.')
Erase 0's at the end when a string ends with a floating point number.
Definition irrString.hpp:1294
s32 findLast(T c, s32 start=-1) const
finds last occurrence of character in string
Definition irrString.hpp:878
string(long number)
Constructs a string from a long.
Definition irrString.hpp:214
void reserve(u32 count)
Reserves some memory.
Definition irrString.hpp:761
string< T, TAlloc > & append(const T *const other, u32 length=0xffffffff)
Appends a char string to this string.
Definition irrString.hpp:650
u32 size() const
Returns length of the string's content.
Definition irrString.hpp:501
s32 findLastCharNotInList(const B *const c, u32 count=1) const
Finds last position of a character not in a given list.
Definition irrString.hpp:839
s32 find(const B *const str, const u32 start=0) const
finds another string in this string
Definition irrString.hpp:915
string< T, TAlloc > & validate()
verify the existing string.
Definition irrString.hpp:1337
string< T, TAlloc > & operator=(const B *const c)
Assignment operator for strings, ASCII and Unicode.
Definition irrString.hpp:362
string(const string< T, TAlloc > &other)
Constructor.
Definition irrString.hpp:109
string< T, TAlloc > & replace(const string< T, TAlloc > &toReplace, const string< T, TAlloc > &replaceWith)
Replaces all instances of a string with another one.
Definition irrString.hpp:1074
string< T, TAlloc > & make_upper()
Makes the string upper case.
Definition irrString.hpp:541
string< T, TAlloc > & insert(u32 pos, const char *s, u32 n)
Insert a certain amount of characters into the string before the given index.
Definition irrString.hpp:736
NIRTCPP_API void utf8ToWchar(const char *in, wchar_t *out, const u64 len)
Convert this utf-8-encoded string to the platform's wchar.
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition irrMath.hpp:164
NIRTCPP_API void wcharToUtf8(const wchar_t *in, char *out, const u64 len)
Convert this wchar string to utf-8.
s32 isdigit(s32 c)
some standard function ( to remove dependencies )
Definition coreutil.hpp:197
As of Nirtcpp 1.6, position2d is a synonym for vector2d.
Definition vector3d.hpp:11
signed int s32
32 bit signed variable.
Definition irrTypes.hpp:72
unsigned int u32
32 bit unsigned variable.
Definition irrTypes.hpp:64
char c8
8 bit character variable.
Definition irrTypes.hpp:37