5#ifndef __IRR_STRING_H_INCLUDED__
6#define __IRR_STRING_H_INCLUDED__
39static inline void locale_set (
eLocaleID id )
45static inline u32 locale_lower (
u32 x )
47 switch ( locale_current )
54 return x >=
'A' && x <=
'Z' ? x + 0x20 : x;
58static inline u32 locale_upper (
u32 x )
60 switch ( locale_current )
68 return x >=
'a' && x <=
'z' ? x + (
'A' -
'a' ) : x;
72template <
typename T,
typename TAlloc = irrAllocator<T> >
81 :
array(0), allocated(1), used(1)
83 array = allocator.allocate(1);
90 :
array(0), allocated(0), used(0)
96 template <
class B,
class A>
98 :
array(0), allocated(0), used(0)
106 :
array(0), allocated(0), used(0)
116 :
array(0), allocated(0), used(0)
164 :
array(0), allocated(0), used(0)
195 :
array(0), allocated(0), used(0)
243 :
array(0), allocated(0), used(0)
275 :
array(0), allocated(0), used(0)
284 allocated = used =
length+1;
285 array = allocator.allocate(used);
297 :
array(0), allocated(0), used(0)
306 allocator.deallocate(
array);
316 used =
other.size()+1;
319 allocator.deallocate(
array);
321 array = allocator.allocate(used);
325 for (
u32 i=0; i<used; ++i, ++
p)
332 template <
class B,
class A>
335 *
this =
other.c_str();
348 array = allocator.allocate(1);
356 if ((
void*)c == (
void*)
array)
374 array = allocator.allocate(used);
446 return used ==
other.used;
460 return (used <
other.used);
467 return !(*
this ==
str);
474 return !(*
this ==
other);
490 return (
size() == 0);
525 if (locale_lower(
array[i]) != locale_lower(
other[i]))
528 return used ==
other.used;
561 return used <
other.used;
578 return (i ==
n) || (used ==
other.used);
591 for(i=0;
array[i] &&
str[i] && i <
n; ++i)
597 return (i ==
n) || (
array[i] == 0 &&
str[i] == 0);
605 if (used + 1 > allocated)
606 reallocate(used + 1);
635 if (used +
len > allocated)
636 reallocate(used +
len);
654 if (
other.size() == 0)
660 if (used +
len > allocated)
661 reallocate(used +
len);
677 if (
other.size() == 0)
686 if (used +
length > allocated)
687 reallocate(used +
length);
707 if (count < allocated)
720 for (
u32 i=0; i<used-1; ++i)
739 for (
u32 i=0; i<used-1; ++i)
740 for (
u32 j=0;
j<count; ++
j)
761 for (
u32 i=0; i<used-1; ++i)
764 for (
j=0;
j<count; ++
j)
788 for (
s32 i=(
s32)(used-2); i>=0; --i)
791 for (
j=0;
j<count; ++
j)
825 for (
s32 i=start; i>=0; --i)
844 for (
s32 i=(
s32)used-2; i>=0; --i)
845 for (
u32 j=0;
j<count; ++
j)
871 for (
u32 i=start; i<used-
len; ++i)
908 o.array[i] =
array[i+begin];
913 o.array[i] = locale_lower (
array[i+begin] );
1009 for (
u32 i=0; i<used-1; ++i)
1049 for (
u32 pos = 0; pos < used; ++i, ++pos)
1094 if (used +
len > allocated)
1095 reallocate(used +
len);
1106 while (
ptr != start)
1131 for (
u32 i=0; i<used-1; ++i)
1156 for (
u32 i=0; i<used-1; ++i)
1189 for (
u32 i=0; i<used-1; ++i)
1227 return (*
this =
subString(begin, (end +1) - begin));
1239 for (
u32 i=index+1; i<used; ++i)
1250 for (
u32 i=0; i<allocated; ++i)
1260 if ( allocated > 0 )
1276 return used > 1 ?
array[used-2] : 0;
1297 template<
class container>
1306 for (
u32 i=0; i<used; ++i)
1309 for (
u32 j=0;
j<count; ++
j)
1342 if (allocated < used)
Axis aligned bounding box in 3d dimensional space.
Self reallocating template array (like stl vector) with additional features.
string< T, TAlloc > & append(const T *const other, u32 length=0xffffffff)
Appends a char string to this string.
s32 findFirstChar(const T *const c, u32 count=1) const
finds first occurrence of a character of a list in string
u32 size() const
Returns length of the string's content.
bool equals_ignore_case(const string< T, TAlloc > &other) const
Compares the strings ignoring case.
s32 find(const B *const str, const u32 start=0) const
finds another string in this string
bool operator!=(const T *const str) const
Inequality operator.
string< T, TAlloc > & operator+=(T c)
Appends a character to this string.
string(long number)
Constructs a string from a long.
s32 findFirst(T c) const
finds first occurrence of character in string
string(unsigned long number)
Constructs a string from an unsigned long.
s32 findFirstCharNotInList(const B *const c, u32 count=1) const
Finds first position of a character not in a given list.
bool operator==(const string< T, TAlloc > &other) const
Equality operator.
string< T, TAlloc > & validate()
verify the existing string.
string(int number)
Constructs a string from an int.
string< T, TAlloc > & append(T character)
Appends a character to this string.
void reserve(u32 count)
Reserves some memory.
string< T, TAlloc > & trim(const string< T, TAlloc > &whitespace=" \t\n\r")
Trims the string.
string< T, TAlloc > & remove(const string< T, TAlloc > &toRemove)
Removes a string from the string.
string< T > subString(u32 begin, s32 length, bool make_lower=false) const
Returns a substring.
s32 findLast(T c, s32 start=-1) const
finds last occurrence of character in string
string< T, TAlloc > & append(const string< T, TAlloc > &other)
Appends a string to this string.
string< T, TAlloc > & operator=(const B *const c)
Assignment operator for strings, ascii and unicode.
string(const B *const c)
Constructor for unicode and ascii strings.
string()
Default constructor.
T lastChar() const
gets the last char of a string or null
string< T, TAlloc > & operator=(const string< B, A > &other)
Assignment operator for other string types.
bool operator<(const string< T, TAlloc > &other) const
Is smaller comparator.
string(const B *const c, u32 length)
Constructor for copying a string from a pointer with a given length.
string< T, TAlloc > & replace(T toReplace, T replaceWith)
Replaces all characters of a special type with another one.
s32 findLastChar(const T *const c, u32 count=1) const
finds last occurrence of a character of a list in string
string(const string< B, A > &other)
Constructor from other string types.
string(unsigned int number)
Constructs a string from an unsigned int.
s32 findNext(T c, u32 startPos) const
finds next occurrence of character in string
string< T, TAlloc > & replace(const string< T, TAlloc > &toReplace, const string< T, TAlloc > &replaceWith)
Replaces all instances of a string with another one.
string< T, TAlloc > & operator=(const string< T, TAlloc > &other)
Assignment operator.
string< T, TAlloc > & erase(u32 index)
Erases a character from the string.
string< T, TAlloc > & make_upper()
Makes the string upper case.
s32 findLastCharNotInList(const B *const c, u32 count=1) const
Finds last position of a character not in a given list.
bool lower_ignore_case(const string< T, TAlloc > &other) const
Compares the strings ignoring case.
string< T, TAlloc > operator+(const string< T, TAlloc > &other) const
Append operator for other strings.
string(const double number)
Constructs a string from a float.
string(const string< T, TAlloc > &other)
Constructor.
u32 split(container &ret, const T *const c, u32 count=1, bool ignoreEmptyTokens=true, bool keepSeparators=false) const
split string into parts.
bool operator!=(const string< T, TAlloc > &other) const
Inequality operator.
string< T, TAlloc > & append(const string< T, TAlloc > &other, u32 length)
Appends a string of the length l to this string.
const T * c_str() const
Returns character string.
string< T, TAlloc > & removeChars(const string< T, TAlloc > &characters)
Removes characters from a string.
string< T, TAlloc > & make_lower()
Makes the string lower case.
string< T, TAlloc > & remove(T c)
Removes characters from a string.
bool equalsn(const T *const str, u32 n) const
compares the first n characters of the strings
bool equals_substring_ignore_case(const string< T, TAlloc > &other, const s32 sourcePos=0) const
Compares the strings ignoring case.
bool equalsn(const string< T, TAlloc > &other, u32 n) const
compares the first n characters of the strings
bool operator==(const T *const str) const
Equality operator.
string< T, TAlloc > operator+(const B *const c) const
Append operator for strings, ascii and unicode.
T & operator[](const u32 index)
Direct access operator.
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
eLocaleID
Very simple string class with some useful features.
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
string< c8 > stringc
Typedef for character strings.
string< wchar_t > stringw
Typedef for wide character strings.
Everything in the Irrlicht Engine can be found in this namespace.
unsigned int u32
32 bit unsigned variable.
char c8
8 bit character variable.
signed int s32
32 bit signed variable.