arsa  2.7
Public Types | Public Member Functions | Friends | List of all members
irr::core::string< T, TAlloc > Class Template Reference

Very simple string class with some useful features. More...

#include <irrString.h>

Public Types

typedef T char_type
 

Public Member Functions

 string ()
 Default constructor. More...
 
 string (const string< T, TAlloc > &other)
 Constructor. More...
 
template<class B , class A >
 string (const string< B, A > &other)
 Constructor from other string types. More...
 
 string (const double number)
 Constructs a string from a float. More...
 
 string (int number)
 Constructs a string from an int. More...
 
 string (unsigned int number)
 Constructs a string from an unsigned int. More...
 
 string (long number)
 Constructs a string from a long. More...
 
 string (unsigned long number)
 Constructs a string from an unsigned long. More...
 
template<class B >
 string (const B *const c, u32 length)
 Constructor for copying a string from a pointer with a given length. More...
 
template<class B >
 string (const B *const c)
 Constructor for Unicode and ASCII strings. More...
 
 ~string ()
 Destructor. More...
 
string< T, TAlloc > & operator= (const string< T, TAlloc > &other)
 Assignment operator. More...
 
template<class B , class A >
string< T, TAlloc > & operator= (const string< B, A > &other)
 Assignment operator for other string types. More...
 
template<class B >
string< T, TAlloc > & operator= (const B *const c)
 Assignment operator for strings, ASCII and Unicode. More...
 
string< T, TAlloc > operator+ (const string< T, TAlloc > &other) const
 Append operator for other strings. More...
 
template<class B >
string< T, TAlloc > operator+ (const B *const c) const
 Append operator for strings, ASCII and Unicode. More...
 
T & operator [] (const u32 index)
 Direct access operator. More...
 
const T & operator [] (const u32 index) const
 Direct access operator. More...
 
bool operator== (const T *const str) const
 Equality operator. More...
 
bool operator== (const string< T, TAlloc > &other) const
 Equality operator. More...
 
bool operator< (const string< T, TAlloc > &other) const
 Is smaller comparator. More...
 
bool operator!= (const T *const str) const
 Inequality operator. More...
 
bool operator!= (const string< T, TAlloc > &other) const
 Inequality operator. More...
 
u32 size () const
 Returns length of the string's content. More...
 
bool empty () const
 
void clear (bool releaseMemory=true)
 
const T * c_str () const
 Returns character string. More...
 
string< T, TAlloc > & make_lower ()
 Makes the string lower case. More...
 
string< T, TAlloc > & make_upper ()
 Makes the string upper case. More...
 
bool equals_ignore_case (const string< T, TAlloc > &other) const
 Compares the strings ignoring case. More...
 
bool equals_substring_ignore_case (const string< T, TAlloc > &other, const s32 sourcePos=0) const
 Compares the strings ignoring case. More...
 
bool lower_ignore_case (const string< T, TAlloc > &other) const
 Compares the strings ignoring case. More...
 
bool equalsn (const string< T, TAlloc > &other, u32 n) const
 compares the first n characters of the strings More...
 
bool equalsn (const T *const str, u32 n) const
 compares the first n characters of the strings More...
 
string< T, TAlloc > & append (T character)
 Appends a character to this string. More...
 
string< T, TAlloc > & append (const T *const other, u32 length=0xffffffff)
 Appends a char string to this string. More...
 
string< T, TAlloc > & append (const string< T, TAlloc > &other)
 Appends a string to this string. More...
 
string< T, TAlloc > & append (const string< T, TAlloc > &other, u32 length)
 Appends a string of the length l to this string. More...
 
string< T, TAlloc > & insert (u32 pos, const char *s, u32 n)
 Insert a certain amount of characters into the string before the given index. More...
 
void reserve (u32 count)
 Reserves some memory. More...
 
s32 findFirst (T c) const
 finds first occurrence of character in string More...
 
s32 findFirstChar (const T *const c, u32 count=1) const
 finds first occurrence of a character of a list in string More...
 
template<class B >
s32 findFirstCharNotInList (const B *const c, u32 count=1) const
 Finds first position of a character not in a given list. More...
 
template<class B >
s32 findLastCharNotInList (const B *const c, u32 count=1) const
 Finds last position of a character not in a given list. More...
 
s32 findNext (T c, u32 startPos) const
 finds next occurrence of character in string More...
 
s32 findLast (T c, s32 start=-1) const
 finds last occurrence of character in string More...
 
s32 findLastChar (const T *const c, u32 count=1) const
 finds last occurrence of a character of a list in string More...
 
template<class B >
s32 find (const B *const str, const u32 start=0) const
 finds another string in this string More...
 
string< T > subString (u32 begin, s32 length, bool make_lower=false) const
 Returns a substring. More...
 
string< T, TAlloc > & operator+= (T c)
 Appends a character to this string. More...
 
string< T, TAlloc > & operator+= (const T *const c)
 Appends a char string to this string. More...
 
string< T, TAlloc > & operator+= (const string< T, TAlloc > &other)
 Appends a string to this string. More...
 
string< T, TAlloc > & operator+= (const int i)
 Appends a string representation of a number to this string. More...
 
string< T, TAlloc > & operator+= (const unsigned int i)
 Appends a string representation of a number to this string. More...
 
string< T, TAlloc > & operator+= (const long i)
 Appends a string representation of a number to this string. More...
 
string< T, TAlloc > & operator+= (const unsigned long i)
 Appends a string representation of a number to this string. More...
 
string< T, TAlloc > & operator+= (const double i)
 Appends a string representation of a number to this string. More...
 
string< T, TAlloc > & operator+= (const float i)
 Appends a string representation of a number to this string. More...
 
string< T, TAlloc > & replace (T toReplace, T replaceWith)
 Replaces all characters of a special type with another one. More...
 
string< T, TAlloc > & replace (const string< T, TAlloc > &toReplace, const string< T, TAlloc > &replaceWith)
 Replaces all instances of a string with another one. More...
 
string< T, TAlloc > & remove (T c)
 Removes characters from a string. More...
 
string< T, TAlloc > & remove (const string< T, TAlloc > &toRemove)
 Removes a string from the string. More...
 
string< T, TAlloc > & removeChars (const string< T, TAlloc > &characters)
 Removes characters from a string. More...
 
string< T, TAlloc > & trim (const string< T, TAlloc > &whitespace=" \t\n\r")
 Trims the string. More...
 
string< T, TAlloc > & eraseTrailingFloatZeros (char decimalPoint='.')
 Erase 0's at the end when a string ends with a floating point number. More...
 
string< T, TAlloc > & erase (u32 index)
 Erases a character from the string. More...
 
string< T, TAlloc > & validate ()
 verify the existing string. More...
 
lastChar () const
 gets the last char of a string or null More...
 
template<class container >
u32 split (container &ret, const T *const delimiter, u32 countDelimiters=1, bool ignoreEmptyTokens=true, bool keepSeparators=false) const
 Split string into parts (tokens). More...
 

Friends

size_t multibyteToWString (string< wchar_t > &destination, const char *source, u32 sourceSize)
 Internally used by the other multibyteToWString functions. More...
 

Detailed Description

template<typename T, typename TAlloc>
class irr::core::string< T, TAlloc >

Very simple string class with some useful features.

string<c8> and string<wchar_t> both accept Unicode AND ASCII/Latin-1, so you can assign Unicode to string<c8> and ASCII/Latin-1 to string<wchar_t> (and the other way round) if you want to.

However, note that the conversation between both is not done using any encoding. This means that c8 strings are treated as ASCII/Latin-1, not UTF-8, and are simply expanded to the equivalent wchar_t, while Unicode/wchar_t characters are truncated to 8-bit ASCII/Latin-1 characters, discarding all other information in the wchar_t.

Helper functions for converting between UTF-8 and wchar_t are provided outside the string class for explicit use.

Definition at line 37 of file irrString.h.

Member Typedef Documentation

◆ char_type

template<typename T, typename TAlloc>
typedef T irr::core::string< T, TAlloc >::char_type

Definition at line 98 of file irrString.h.

Constructor & Destructor Documentation

◆ string() [1/10]

template<typename T, typename TAlloc>
irr::core::string< T, TAlloc >::string ( )
inline

Default constructor.

Definition at line 101 of file irrString.h.

102  : array(0), allocated(1), used(1)
103  {
104  array = allocator.allocate(1); // new T[1];
105  array[0] = 0;
106  }
GLenum array

◆ string() [2/10]

template<typename T, typename TAlloc>
irr::core::string< T, TAlloc >::string ( const string< T, TAlloc > &  other)
inline

Constructor.

Definition at line 110 of file irrString.h.

111  : array(0), allocated(0), used(0)
112  {
113  *this = other;
114  }
GLenum array

◆ string() [3/10]

template<typename T, typename TAlloc>
template<class B , class A >
irr::core::string< T, TAlloc >::string ( const string< B, A > &  other)
inline

Constructor from other string types.

Definition at line 118 of file irrString.h.

119  : array(0), allocated(0), used(0)
120  {
121  *this = other;
122  }
GLenum array

◆ string() [4/10]

template<typename T, typename TAlloc>
irr::core::string< T, TAlloc >::string ( const double  number)
inlineexplicit

Constructs a string from a float.

Definition at line 126 of file irrString.h.

127  : array(0), allocated(0), used(0)
128  {
129  c8 tmpbuf[255];
130  snprintf_irr(tmpbuf, 255, "%0.6f", number);
131  *this = tmpbuf;
132  }
char c8
8 bit character variable.
Definition: irrTypes.h:35
#define snprintf_irr
Definition: irrTypes.h:149
GLenum array

◆ string() [5/10]

template<typename T, typename TAlloc>
irr::core::string< T, TAlloc >::string ( int  number)
inlineexplicit

Constructs a string from an int.

Definition at line 136 of file irrString.h.

137  : array(0), allocated(0), used(0)
138  {
139  // store if negative and make positive
140 
141  bool negative = false;
142  if (number < 0)
143  {
144  number *= -1;
145  negative = true;
146  }
147 
148  // temporary buffer for 16 numbers
149 
150  c8 tmpbuf[16]={0};
151  u32 idx = 15;
152 
153  // special case '0'
154 
155  if (!number)
156  {
157  tmpbuf[14] = '0';
158  *this = &tmpbuf[14];
159  return;
160  }
161 
162  // add numbers
163 
164  while(number && idx)
165  {
166  --idx;
167  tmpbuf[idx] = (c8)('0' + (number % 10));
168  number /= 10;
169  }
170 
171  // add sign
172 
173  if (negative)
174  {
175  --idx;
176  tmpbuf[idx] = '-';
177  }
178 
179  *this = &tmpbuf[idx];
180  }
char c8
8 bit character variable.
Definition: irrTypes.h:35
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ string() [6/10]

template<typename T, typename TAlloc>
irr::core::string< T, TAlloc >::string ( unsigned int  number)
inlineexplicit

Constructs a string from an unsigned int.

Definition at line 184 of file irrString.h.

185  : array(0), allocated(0), used(0)
186  {
187  // temporary buffer for 16 numbers
188 
189  c8 tmpbuf[16]={0};
190  u32 idx = 15;
191 
192  // special case '0'
193 
194  if (!number)
195  {
196  tmpbuf[14] = '0';
197  *this = &tmpbuf[14];
198  return;
199  }
200 
201  // add numbers
202 
203  while(number && idx)
204  {
205  --idx;
206  tmpbuf[idx] = (c8)('0' + (number % 10));
207  number /= 10;
208  }
209 
210  *this = &tmpbuf[idx];
211  }
char c8
8 bit character variable.
Definition: irrTypes.h:35
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ string() [7/10]

template<typename T, typename TAlloc>
irr::core::string< T, TAlloc >::string ( long  number)
inlineexplicit

Constructs a string from a long.

Definition at line 215 of file irrString.h.

216  : array(0), allocated(0), used(0)
217  {
218  // store if negative and make positive
219 
220  bool negative = false;
221  if (number < 0)
222  {
223  number *= -1;
224  negative = true;
225  }
226 
227  // temporary buffer for 16 numbers
228 
229  c8 tmpbuf[16]={0};
230  u32 idx = 15;
231 
232  // special case '0'
233 
234  if (!number)
235  {
236  tmpbuf[14] = '0';
237  *this = &tmpbuf[14];
238  return;
239  }
240 
241  // add numbers
242 
243  while(number && idx)
244  {
245  --idx;
246  tmpbuf[idx] = (c8)('0' + (number % 10));
247  number /= 10;
248  }
249 
250  // add sign
251 
252  if (negative)
253  {
254  --idx;
255  tmpbuf[idx] = '-';
256  }
257 
258  *this = &tmpbuf[idx];
259  }
char c8
8 bit character variable.
Definition: irrTypes.h:35
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ string() [8/10]

template<typename T, typename TAlloc>
irr::core::string< T, TAlloc >::string ( unsigned long  number)
inlineexplicit

Constructs a string from an unsigned long.

Definition at line 263 of file irrString.h.

264  : array(0), allocated(0), used(0)
265  {
266  // temporary buffer for 16 numbers
267 
268  c8 tmpbuf[16]={0};
269  u32 idx = 15;
270 
271  // special case '0'
272 
273  if (!number)
274  {
275  tmpbuf[14] = '0';
276  *this = &tmpbuf[14];
277  return;
278  }
279 
280  // add numbers
281 
282  while(number && idx)
283  {
284  --idx;
285  tmpbuf[idx] = (c8)('0' + (number % 10));
286  number /= 10;
287  }
288 
289  *this = &tmpbuf[idx];
290  }
char c8
8 bit character variable.
Definition: irrTypes.h:35
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ string() [9/10]

template<typename T, typename TAlloc>
template<class B >
irr::core::string< T, TAlloc >::string ( const B *const  c,
u32  length 
)
inline

Constructor for copying a string from a pointer with a given length.

Definition at line 295 of file irrString.h.

296  : array(0), allocated(0), used(0)
297  {
298  if (!c)
299  {
300  // correctly init the string to an empty one
301  *this="";
302  return;
303  }
304 
305  allocated = used = length+1;
306  array = allocator.allocate(used); // new T[used];
307 
308  for (u32 l = 0; l<length; ++l)
309  array[l] = (T)c[l];
310 
311  array[length] = 0;
312  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array
GLuint GLsizei GLsizei * length
const GLubyte * c

◆ string() [10/10]

template<typename T, typename TAlloc>
template<class B >
irr::core::string< T, TAlloc >::string ( const B *const  c)
inline

Constructor for Unicode and ASCII strings.

Definition at line 317 of file irrString.h.

318  : array(0), allocated(0), used(0)
319  {
320  *this = c;
321  }
GLenum array
const GLubyte * c

◆ ~string()

template<typename T, typename TAlloc>
irr::core::string< T, TAlloc >::~string ( )
inline

Destructor.

Definition at line 325 of file irrString.h.

326  {
327  allocator.deallocate(array); // delete [] array;
328  }
GLenum array

Member Function Documentation

◆ append() [1/4]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::append ( character)
inline

Appends a character to this string.

Parameters
characterCharacter to append.

Definition at line 634 of file irrString.h.

635  {
636  if (used + 1 > allocated)
637  reallocate(used + 1);
638 
639  ++used;
640 
641  array[used-2] = character;
642  array[used-1] = 0;
643 
644  return *this;
645  }
GLenum array

◆ append() [2/4]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::append ( const T *const  other,
u32  length = 0xffffffff 
)
inline

Appends a char string to this string.

Parameters
otherChar string to append.
lengthThe length of the string to append.

Definition at line 651 of file irrString.h.

652  {
653  if (!other)
654  return *this;
655 
656  u32 len = 0;
657  const T* p = other;
658  while(*p)
659  {
660  ++len;
661  ++p;
662  }
663  if (len > length)
664  len = length;
665 
666  if (used + len > allocated)
667  reallocate(used + len);
668 
669  --used;
670  ++len;
671 
672  for (u32 l=0; l<len; ++l)
673  array[l+used] = *(other+l);
674 
675  used += len;
676 
677  return *this;
678  }
GLfloat GLfloat p
GLenum GLsizei len
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array
GLuint GLsizei GLsizei * length

◆ append() [3/4]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::append ( const string< T, TAlloc > &  other)
inline

Appends a string to this string.

Parameters
otherString to append.

Definition at line 683 of file irrString.h.

684  {
685  if (other.size() == 0)
686  return *this;
687 
688  --used;
689  const u32 len = other.size()+1;
690 
691  if (used + len > allocated)
692  reallocate(used + len);
693 
694  for (u32 l=0; l<len; ++l)
695  array[used+l] = other[l];
696 
697  used += len;
698 
699  return *this;
700  }
GLenum GLsizei len
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ append() [4/4]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::append ( const string< T, TAlloc > &  other,
u32  length 
)
inline

Appends a string of the length l to this string.

Parameters
otherother String to append to this string.
lengthHow much characters of the other string to add to this one.

Definition at line 706 of file irrString.h.

707  {
708  if (other.size() == 0)
709  return *this;
710 
711  if (other.size() < length)
712  {
713  append(other);
714  return *this;
715  }
716 
717  if (used + length > allocated)
718  reallocate(used + length);
719 
720  --used;
721 
722  for (u32 l=0; l<length; ++l)
723  array[l+used] = other[l];
724  used += length;
725 
726  // ensure proper termination
727  array[used]=0;
728  ++used;
729 
730  return *this;
731  }
string< T, TAlloc > & append(T character)
Appends a character to this string.
Definition: irrString.h:634
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array
GLuint GLsizei GLsizei * length

◆ c_str()

template<typename T, typename TAlloc>
const T* irr::core::string< T, TAlloc >::c_str ( ) const
inline

Returns character string.

Returns
pointer to C-style NUL terminated string.

Definition at line 526 of file irrString.h.

527  {
528  return array;
529  }
GLenum array

◆ clear()

template<typename T, typename TAlloc>
void irr::core::string< T, TAlloc >::clear ( bool  releaseMemory = true)
inline

Definition at line 514 of file irrString.h.

515  {
516  if ( releaseMemory )
517  {
518  reallocate(1);
519  }
520  array[0] = 0;
521  used = 1;
522  }
GLenum array

◆ empty()

template<typename T, typename TAlloc>
bool irr::core::string< T, TAlloc >::empty ( ) const
inline

Informs if the string is empty or not.

Returns
True if the string is empty, false if not.

Definition at line 509 of file irrString.h.

510  {
511  return (size() == 0);
512  }
u32 size() const
Returns length of the string's content.
Definition: irrString.h:502

◆ equals_ignore_case()

template<typename T, typename TAlloc>
bool irr::core::string< T, TAlloc >::equals_ignore_case ( const string< T, TAlloc > &  other) const
inline

Compares the strings ignoring case.

Parameters
otherOther string to compare.
Returns
True if the strings are equal ignoring case.

Definition at line 553 of file irrString.h.

554  {
555  for(u32 i=0; array[i] && other[i]; ++i)
556  if (locale_lower( array[i]) != locale_lower(other[i]))
557  return false;
558 
559  return used == other.used;
560  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ equals_substring_ignore_case()

template<typename T, typename TAlloc>
bool irr::core::string< T, TAlloc >::equals_substring_ignore_case ( const string< T, TAlloc > &  other,
const s32  sourcePos = 0 
) const
inline

Compares the strings ignoring case.

Parameters
otherOther string to compare.
sourcePoswhere to start to compare in the string
Returns
True if the strings are equal ignoring case.

Definition at line 566 of file irrString.h.

567  {
568  if ( (u32) sourcePos >= used )
569  return false;
570 
571  u32 i;
572  for( i=0; array[sourcePos + i] && other[i]; ++i)
573  if (locale_lower( array[sourcePos + i]) != locale_lower(other[i]))
574  return false;
575 
576  return array[sourcePos + i] == 0 && other[i] == 0;
577  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ equalsn() [1/2]

template<typename T, typename TAlloc>
bool irr::core::string< T, TAlloc >::equalsn ( const string< T, TAlloc > &  other,
u32  n 
) const
inline

compares the first n characters of the strings

Parameters
otherOther string to compare.
nNumber of characters to compare
Returns
True if the n first characters of both strings are equal.

Definition at line 600 of file irrString.h.

601  {
602  u32 i;
603  for(i=0; i < n && array[i] && other[i]; ++i)
604  if (array[i] != other[i])
605  return false;
606 
607  // if one (or both) of the strings was smaller then they
608  // are only equal if they have the same length
609  return (i == n) || (used == other.used);
610  }
GLdouble n
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ equalsn() [2/2]

template<typename T, typename TAlloc>
bool irr::core::string< T, TAlloc >::equalsn ( const T *const  str,
u32  n 
) const
inline

compares the first n characters of the strings

Parameters
strOther string to compare.
nNumber of characters to compare
Returns
True if the n first characters of both strings are equal.

Definition at line 617 of file irrString.h.

618  {
619  if (!str)
620  return false;
621  u32 i;
622  for(i=0; i < n && array[i] && str[i]; ++i)
623  if (array[i] != str[i])
624  return false;
625 
626  // if one (or both) of the strings was smaller then they
627  // are only equal if they have the same length
628  return (i == n) || (array[i] == 0 && str[i] == 0);
629  }
GLdouble n
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ erase()

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::erase ( u32  index)
inline

Erases a character from the string.

May be slow, because all elements following after the erased element have to be copied.

Parameters
indexIndex of element to be erased.

Definition at line 1326 of file irrString.h.

1327  {
1328  _IRR_DEBUG_BREAK_IF(index>=used) // access violation
1329 
1330  for (u32 i=index+1; i<used; ++i)
1331  array[i-1] = array[i];
1332 
1333  --used;
1334  return *this;
1335  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
Definition: irrTypes.h:185
GLuint index
GLenum array

◆ eraseTrailingFloatZeros()

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::eraseTrailingFloatZeros ( char  decimalPoint = '.')
inline

Erase 0's at the end when a string ends with a floating point number.

After generating strings from floats we often end up with strings ending up with lots of zeros which don't add any value. Erase 'em all. Examples: "0.100000" becomes "0.1" "10.000000" becomes "10" "foo 3.140000" becomes "foo 3.14" "no_num.000" stays "no_num.000" "1." stays "1."

Definition at line 1295 of file irrString.h.

1296  {
1297  s32 i=findLastCharNotInList("0", 1);
1298  if ( i > 0 && (u32)i < used-2 ) // non 0 must be found and not last char (also used is at least 2 when i > 0)
1299  {
1300  u32 eraseStart=i+1;
1301  u32 dot=0;
1302  if( core::isdigit(array[i]) )
1303  {
1304  while( --i>0 && core::isdigit(array[i]) );
1305  if ( array[i] == decimalPoint )
1306  dot = i;
1307  }
1308  else if ( array[i] == decimalPoint )
1309  {
1310  dot = i;
1311  eraseStart = i;
1312  }
1313  if ( dot > 0 && core::isdigit(array[dot-1]) )
1314  {
1315  array[eraseStart] = 0;
1316  used = eraseStart+1;
1317  }
1318  }
1319  return *this;
1320  }
s32 isdigit(s32 c)
some standard function ( to remove dependencies )
Definition: coreutil.h:197
s32 findLastCharNotInList(const B *const c, u32 count=1) const
Finds last position of a character not in a given list.
Definition: irrString.h:840
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ find()

template<typename T, typename TAlloc>
template<class B >
s32 irr::core::string< T, TAlloc >::find ( const B *const  str,
const u32  start = 0 
) const
inline

finds another string in this string

Parameters
strAnother string
startStart position of the search
Returns
Positions where the string has been found, or -1 if not found.

Definition at line 916 of file irrString.h.

917  {
918  if (str && *str)
919  {
920  u32 len = 0;
921 
922  while (str[len])
923  ++len;
924 
925  if (len > used-1)
926  return -1;
927 
928  for (u32 i=start; i<used-len; ++i)
929  {
930  u32 j=0;
931 
932  while(str[j] && array[i+j] == str[j])
933  ++j;
934 
935  if (!str[j])
936  return i;
937  }
938  }
939 
940  return -1;
941  }
GLuint start
Definition: SDL_opengl.h:1571
GLenum GLsizei len
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ findFirst()

template<typename T, typename TAlloc>
s32 irr::core::string< T, TAlloc >::findFirst ( c) const
inline

finds first occurrence of character in string

Parameters
cCharacter to search for.
Returns
Position where the character has been found, or -1 if not found.

Definition at line 775 of file irrString.h.

776  {
777  for (u32 i=0; i<used-1; ++i)
778  if (array[i] == c)
779  return i;
780 
781  return -1;
782  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array
const GLubyte * c

◆ findFirstChar()

template<typename T, typename TAlloc>
s32 irr::core::string< T, TAlloc >::findFirstChar ( const T *const  c,
u32  count = 1 
) const
inline

finds first occurrence of a character of a list in string

Parameters
cList of characters to find. For example if the method should find the first occurrence of 'a' or 'b', this parameter should be "ab".
countAmount of characters in the list. Usually, this should be strlen(c)
Returns
Position where one of the characters has been found, or -1 if not found.

Definition at line 791 of file irrString.h.

792  {
793  if (!c || !count)
794  return -1;
795 
796  for (u32 i=0; i<used-1; ++i)
797  for (u32 j=0; j<count; ++j)
798  if (array[i] == c[j])
799  return i;
800 
801  return -1;
802  }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array
const GLubyte * c

◆ findFirstCharNotInList()

template<typename T, typename TAlloc>
template<class B >
s32 irr::core::string< T, TAlloc >::findFirstCharNotInList ( const B *const  c,
u32  count = 1 
) const
inline

Finds first position of a character not in a given list.

Parameters
cList of characters not to find. For example if the method should find the first occurrence of a character not 'a' or 'b', this parameter should be "ab".
countAmount of characters in the list. Usually, this should be strlen(c)
Returns
Position where the character has been found, or -1 if not found.

Definition at line 813 of file irrString.h.

814  {
815  if (!c || !count)
816  return -1;
817 
818  for (u32 i=0; i<used-1; ++i)
819  {
820  u32 j;
821  for (j=0; j<count; ++j)
822  if (array[i] == c[j])
823  break;
824 
825  if (j==count)
826  return i;
827  }
828 
829  return -1;
830  }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array
const GLubyte * c

◆ findLast()

template<typename T, typename TAlloc>
s32 irr::core::string< T, TAlloc >::findLast ( c,
s32  start = -1 
) const
inline

finds last occurrence of character in string

Parameters
cCharacter to search for.
startstart to search reverse ( default = -1, on end )
Returns
Position where the character has been found, or -1 if not found.

Definition at line 879 of file irrString.h.

880  {
881  start = core::clamp ( start < 0 ? (s32)(used) - 2 : start, 0, (s32)(used) - 2 );
882  for (s32 i=start; i>=0; --i)
883  if (array[i] == c)
884  return i;
885 
886  return -1;
887  }
GLuint start
Definition: SDL_opengl.h:1571
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
GLenum array
const GLubyte * c
const T clamp(const T &value, const T &low, const T &high)
clamps a value between low and high
Definition: irrMath.h:167

◆ findLastChar()

template<typename T, typename TAlloc>
s32 irr::core::string< T, TAlloc >::findLastChar ( const T *const  c,
u32  count = 1 
) const
inline

finds last occurrence of a character of a list in string

Parameters
cList of strings to find. For example if the method should find the last occurrence of 'a' or 'b', this parameter should be "ab".
countAmount of characters in the list. Usually, this should be strlen(c)
Returns
Position where one of the characters has been found, or -1 if not found.

Definition at line 896 of file irrString.h.

897  {
898  if (!c || !count)
899  return -1;
900 
901  for (s32 i=(s32)used-2; i>=0; --i)
902  for (u32 j=0; j<count; ++j)
903  if (array[i] == c[j])
904  return i;
905 
906  return -1;
907  }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array
const GLubyte * c

◆ findLastCharNotInList()

template<typename T, typename TAlloc>
template<class B >
s32 irr::core::string< T, TAlloc >::findLastCharNotInList ( const B *const  c,
u32  count = 1 
) const
inline

Finds last position of a character not in a given list.

Parameters
cList of characters not to find. For example if the method should find the first occurrence of a character not 'a' or 'b', this parameter should be "ab".
countAmount of characters in the list. Usually, this should be strlen(c)
Returns
Position where the character has been found, or -1 if not found.

Definition at line 840 of file irrString.h.

841  {
842  if (!c || !count)
843  return -1;
844 
845  for (s32 i=(s32)(used-2); i>=0; --i)
846  {
847  u32 j;
848  for (j=0; j<count; ++j)
849  if (array[i] == c[j])
850  break;
851 
852  if (j==count)
853  return i;
854  }
855 
856  return -1;
857  }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array
const GLubyte * c

◆ findNext()

template<typename T, typename TAlloc>
s32 irr::core::string< T, TAlloc >::findNext ( c,
u32  startPos 
) const
inline

finds next occurrence of character in string

Parameters
cCharacter to search for.
startPosPosition in string to start searching.
Returns
Position where the character has been found, or -1 if not found.

Definition at line 864 of file irrString.h.

865  {
866  for (u32 i=startPos; i<used-1; ++i)
867  if (array[i] == c)
868  return i;
869 
870  return -1;
871  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array
const GLubyte * c

◆ insert()

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::insert ( u32  pos,
const char *  s,
u32  n 
)
inline

Insert a certain amount of characters into the string before the given index.

Definition at line 737 of file irrString.h.

738  {
739  if ( pos < used )
740  {
741  reserve(used+n);
742 
743  // move stuff behind insert point
744  const u32 end = used+n-1;
745  for (u32 i=0; i<used-pos; ++i)
746  {
747  array[end-i] = array[end-(i+n)];
748  }
749  used += n;
750 
751  for (u32 i=0; i<n; ++i)
752  {
753  array[pos+i] = s[i];
754  }
755  }
756 
757  return *this;
758  }
GLdouble n
GLuint GLuint end
Definition: SDL_opengl.h:1571
void reserve(u32 count)
Reserves some memory.
Definition: irrString.h:762
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLdouble s
Definition: SDL_opengl.h:2063
GLenum array

◆ lastChar()

template<typename T, typename TAlloc>
T irr::core::string< T, TAlloc >::lastChar ( ) const
inline

gets the last char of a string or null

Definition at line 1365 of file irrString.h.

1366  {
1367  return used > 1 ? array[used-2] : 0;
1368  }
GLenum array

◆ lower_ignore_case()

template<typename T, typename TAlloc>
bool irr::core::string< T, TAlloc >::lower_ignore_case ( const string< T, TAlloc > &  other) const
inline

Compares the strings ignoring case.

Parameters
otherOther string to compare.
Returns
True if this string is smaller ignoring case.

Definition at line 583 of file irrString.h.

584  {
585  for(u32 i=0; array[i] && other.array[i]; ++i)
586  {
587  s32 diff = (s32) locale_lower ( array[i] ) - (s32) locale_lower ( other.array[i] );
588  if ( diff )
589  return diff < 0;
590  }
591 
592  return used < other.used;
593  }
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ make_lower()

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::make_lower ( )
inline

Makes the string lower case.

Definition at line 533 of file irrString.h.

534  {
535  for (u32 i=0; array[i]; ++i)
536  array[i] = locale_lower ( array[i] );
537  return *this;
538  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ make_upper()

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::make_upper ( )
inline

Makes the string upper case.

Definition at line 542 of file irrString.h.

543  {
544  for (u32 i=0; array[i]; ++i)
545  array[i] = locale_upper ( array[i] );
546  return *this;
547  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ operator []() [1/2]

template<typename T, typename TAlloc>
T& irr::core::string< T, TAlloc >::operator [] ( const u32  index)
inline

Direct access operator.

Definition at line 430 of file irrString.h.

431  {
432  _IRR_DEBUG_BREAK_IF(index>=used) // bad index
433  return array[index];
434  }
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
Definition: irrTypes.h:185
GLuint index
GLenum array

◆ operator []() [2/2]

template<typename T, typename TAlloc>
const T& irr::core::string< T, TAlloc >::operator [] ( const u32  index) const
inline

Direct access operator.

Definition at line 438 of file irrString.h.

439  {
440  _IRR_DEBUG_BREAK_IF(index>=used) // bad index
441  return array[index];
442  }
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
Definition: irrTypes.h:185
GLuint index
GLenum array

◆ operator!=() [1/2]

template<typename T, typename TAlloc>
bool irr::core::string< T, TAlloc >::operator!= ( const T *const  str) const
inline

Inequality operator.

Definition at line 486 of file irrString.h.

487  {
488  return !(*this == str);
489  }

◆ operator!=() [2/2]

template<typename T, typename TAlloc>
bool irr::core::string< T, TAlloc >::operator!= ( const string< T, TAlloc > &  other) const
inline

Inequality operator.

Definition at line 493 of file irrString.h.

494  {
495  return !(*this == other);
496  }

◆ operator+() [1/2]

template<typename T, typename TAlloc>
string<T,TAlloc> irr::core::string< T, TAlloc >::operator+ ( const string< T, TAlloc > &  other) const
inline

Append operator for other strings.

Definition at line 409 of file irrString.h.

410  {
411  string<T,TAlloc> str(*this);
412  str.append(other);
413 
414  return str;
415  }
GLsizei const GLchar *const * string

◆ operator+() [2/2]

template<typename T, typename TAlloc>
template<class B >
string<T,TAlloc> irr::core::string< T, TAlloc >::operator+ ( const B *const  c) const
inline

Append operator for strings, ASCII and Unicode.

Definition at line 420 of file irrString.h.

421  {
422  string<T,TAlloc> str(*this);
423  str.append(c);
424 
425  return str;
426  }
GLsizei const GLchar *const * string
const GLubyte * c

◆ operator+=() [1/9]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::operator+= ( c)
inline

Appends a character to this string.

Parameters
cCharacter to append.

Definition at line 981 of file irrString.h.

982  {
983  append(c);
984  return *this;
985  }
string< T, TAlloc > & append(T character)
Appends a character to this string.
Definition: irrString.h:634
const GLubyte * c

◆ operator+=() [2/9]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::operator+= ( const T *const  c)
inline

Appends a char string to this string.

Parameters
cChar string to append.

Definition at line 990 of file irrString.h.

991  {
992  append(c);
993  return *this;
994  }
string< T, TAlloc > & append(T character)
Appends a character to this string.
Definition: irrString.h:634
const GLubyte * c

◆ operator+=() [3/9]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::operator+= ( const string< T, TAlloc > &  other)
inline

Appends a string to this string.

Parameters
otherString to append.

Definition at line 999 of file irrString.h.

1000  {
1001  append(other);
1002  return *this;
1003  }
string< T, TAlloc > & append(T character)
Appends a character to this string.
Definition: irrString.h:634

◆ operator+=() [4/9]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::operator+= ( const int  i)
inline

Appends a string representation of a number to this string.

Parameters
iNumber to append.

Definition at line 1008 of file irrString.h.

1009  {
1011  return *this;
1012  }
GLsizei const GLchar *const * string
string< T, TAlloc > & append(T character)
Appends a character to this string.
Definition: irrString.h:634

◆ operator+=() [5/9]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::operator+= ( const unsigned int  i)
inline

Appends a string representation of a number to this string.

Parameters
iNumber to append.

Definition at line 1017 of file irrString.h.

1018  {
1020  return *this;
1021  }
GLsizei const GLchar *const * string
string< T, TAlloc > & append(T character)
Appends a character to this string.
Definition: irrString.h:634

◆ operator+=() [6/9]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::operator+= ( const long  i)
inline

Appends a string representation of a number to this string.

Parameters
iNumber to append.

Definition at line 1026 of file irrString.h.

1027  {
1029  return *this;
1030  }
GLsizei const GLchar *const * string
string< T, TAlloc > & append(T character)
Appends a character to this string.
Definition: irrString.h:634

◆ operator+=() [7/9]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::operator+= ( const unsigned long  i)
inline

Appends a string representation of a number to this string.

Parameters
iNumber to append.

Definition at line 1035 of file irrString.h.

1036  {
1038  return *this;
1039  }
GLsizei const GLchar *const * string
string< T, TAlloc > & append(T character)
Appends a character to this string.
Definition: irrString.h:634

◆ operator+=() [8/9]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::operator+= ( const double  i)
inline

Appends a string representation of a number to this string.

Parameters
iNumber to append.

Definition at line 1044 of file irrString.h.

1045  {
1047  return *this;
1048  }
GLsizei const GLchar *const * string
string< T, TAlloc > & append(T character)
Appends a character to this string.
Definition: irrString.h:634

◆ operator+=() [9/9]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::operator+= ( const float  i)
inline

Appends a string representation of a number to this string.

Parameters
iNumber to append.

Definition at line 1053 of file irrString.h.

1054  {
1056  return *this;
1057  }
GLsizei const GLchar *const * string
string< T, TAlloc > & append(T character)
Appends a character to this string.
Definition: irrString.h:634

◆ operator<()

template<typename T, typename TAlloc>
bool irr::core::string< T, TAlloc >::operator< ( const string< T, TAlloc > &  other) const
inline

Is smaller comparator.

Definition at line 472 of file irrString.h.

473  {
474  for (u32 i=0; array[i] && other.array[i]; ++i)
475  {
476  const s32 diff = array[i] - other.array[i];
477  if (diff)
478  return (diff < 0);
479  }
480 
481  return (used < other.used);
482  }
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ operator=() [1/3]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::operator= ( const string< T, TAlloc > &  other)
inline

Assignment operator.

Definition at line 332 of file irrString.h.

333  {
334  if (this == &other)
335  return *this;
336 
337  used = other.size()+1;
338  if (used>allocated)
339  {
340  allocator.deallocate(array); // delete [] array;
341  allocated = used;
342  array = allocator.allocate(used); //new T[used];
343  }
344 
345  const T* p = other.c_str();
346  for (u32 i=0; i<used; ++i, ++p)
347  array[i] = *p;
348 
349  return *this;
350  }
GLfloat GLfloat p
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ operator=() [2/3]

template<typename T, typename TAlloc>
template<class B , class A >
string<T,TAlloc>& irr::core::string< T, TAlloc >::operator= ( const string< B, A > &  other)
inline

Assignment operator for other string types.

Definition at line 354 of file irrString.h.

355  {
356  *this = other.c_str();
357  return *this;
358  }

◆ operator=() [3/3]

template<typename T, typename TAlloc>
template<class B >
string<T,TAlloc>& irr::core::string< T, TAlloc >::operator= ( const B *const  c)
inline

Assignment operator for strings, ASCII and Unicode.

Definition at line 363 of file irrString.h.

364  {
365  if (!c)
366  {
367  if (!array)
368  {
369  array = allocator.allocate(1); //new T[1];
370  allocated = 1;
371  }
372  used = 1;
373  array[0] = 0x0;
374  return *this;
375  }
376 
377  if ((void*)c == (void*)array)
378  return *this;
379 
380  u32 len = 0;
381  const B* p = c;
382  do
383  {
384  ++len;
385  } while(*p++);
386 
387  // we'll keep the old string for a while, because the new
388  // string could be a part of the current string.
389  T* oldArray = array;
390 
391  used = len;
392  if (used>allocated)
393  {
394  allocated = used;
395  array = allocator.allocate(used); //new T[used];
396  }
397 
398  for (u32 l = 0; l<len; ++l)
399  array[l] = (T)c[l];
400 
401  if (oldArray != array)
402  allocator.deallocate(oldArray); // delete [] oldArray;
403 
404  return *this;
405  }
GLfloat GLfloat p
GLenum GLsizei len
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array
const GLubyte * c

◆ operator==() [1/2]

template<typename T, typename TAlloc>
bool irr::core::string< T, TAlloc >::operator== ( const T *const  str) const
inline

Equality operator.

Definition at line 446 of file irrString.h.

447  {
448  if (!str)
449  return false;
450 
451  u32 i;
452  for (i=0; array[i] && str[i]; ++i)
453  if (array[i] != str[i])
454  return false;
455 
456  return (!array[i] && !str[i]);
457  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ operator==() [2/2]

template<typename T, typename TAlloc>
bool irr::core::string< T, TAlloc >::operator== ( const string< T, TAlloc > &  other) const
inline

Equality operator.

Definition at line 461 of file irrString.h.

462  {
463  for (u32 i=0; array[i] && other.array[i]; ++i)
464  if (array[i] != other.array[i])
465  return false;
466 
467  return used == other.used;
468  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ remove() [1/2]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::remove ( c)
inline

Removes characters from a string.

Parameters
cCharacter to remove.

Definition at line 1183 of file irrString.h.

1184  {
1185  u32 pos = 0;
1186  u32 found = 0;
1187  for (u32 i=0; i<used-1; ++i)
1188  {
1189  if (array[i] == c)
1190  {
1191  ++found;
1192  continue;
1193  }
1194 
1195  array[pos++] = array[i];
1196  }
1197  used -= found;
1198  array[used-1] = 0;
1199  return *this;
1200  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array
const GLubyte * c

◆ remove() [2/2]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::remove ( const string< T, TAlloc > &  toRemove)
inline

Removes a string from the string.

Parameters
toRemoveString to remove.

Definition at line 1205 of file irrString.h.

1206  {
1207  u32 size = toRemove.size();
1208  if ( size == 0 )
1209  return *this;
1210  u32 pos = 0;
1211  u32 found = 0;
1212  for (u32 i=0; i<used-1; ++i)
1213  {
1214  u32 j = 0;
1215  while (j < size)
1216  {
1217  if (array[i + j] != toRemove[j])
1218  break;
1219  ++j;
1220  }
1221  if (j == size)
1222  {
1223  found += size;
1224  i += size - 1;
1225  continue;
1226  }
1227 
1228  array[pos++] = array[i];
1229  }
1230  used -= found;
1231  array[used-1] = 0;
1232  return *this;
1233  }
u32 size() const
Returns length of the string's content.
Definition: irrString.h:502
GLsizeiptr size
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ removeChars()

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::removeChars ( const string< T, TAlloc > &  characters)
inline

Removes characters from a string.

Parameters
charactersCharacters to remove.

Definition at line 1238 of file irrString.h.

1239  {
1240  if (characters.size() == 0)
1241  return *this;
1242 
1243  u32 pos = 0;
1244  u32 found = 0;
1245  for (u32 i=0; i<used-1; ++i)
1246  {
1247  // Don't use characters.findFirst as it finds the \0,
1248  // causing used to become incorrect.
1249  bool docontinue = false;
1250  for (u32 j=0; j<characters.size(); ++j)
1251  {
1252  if (characters[j] == array[i])
1253  {
1254  ++found;
1255  docontinue = true;
1256  break;
1257  }
1258  }
1259  if (docontinue)
1260  continue;
1261 
1262  array[pos++] = array[i];
1263  }
1264  used -= found;
1265  array[used-1] = 0;
1266 
1267  return *this;
1268  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ replace() [1/2]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::replace ( toReplace,
replaceWith 
)
inline

Replaces all characters of a special type with another one.

Parameters
toReplaceCharacter to replace.
replaceWithCharacter replacing the old one.

Definition at line 1063 of file irrString.h.

1064  {
1065  for (u32 i=0; i<used-1; ++i)
1066  if (array[i] == toReplace)
1067  array[i] = replaceWith;
1068  return *this;
1069  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ replace() [2/2]

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::replace ( const string< T, TAlloc > &  toReplace,
const string< T, TAlloc > &  replaceWith 
)
inline

Replaces all instances of a string with another one.

Parameters
toReplaceThe string to replace.
replaceWithThe string replacing the old one.

Definition at line 1075 of file irrString.h.

1076  {
1077  if (toReplace.size() == 0)
1078  return *this;
1079 
1080  const T* other = toReplace.c_str();
1081  const T* replace = replaceWith.c_str();
1082  const u32 other_size = toReplace.size();
1083  const u32 replace_size = replaceWith.size();
1084 
1085  // Determine the delta. The algorithm will change depending on the delta.
1086  s32 delta = replace_size - other_size;
1087 
1088  // A character for character replace. The string will not shrink or grow.
1089  if (delta == 0)
1090  {
1091  s32 pos = 0;
1092  while ((pos = find(other, pos)) != -1)
1093  {
1094  for (u32 i = 0; i < replace_size; ++i)
1095  array[pos + i] = replace[i];
1096  ++pos;
1097  }
1098  return *this;
1099  }
1100 
1101  // We are going to be removing some characters. The string will shrink.
1102  if (delta < 0)
1103  {
1104  u32 i = 0;
1105  for (u32 pos = 0; pos < used; ++i, ++pos)
1106  {
1107  // Is this potentially a match?
1108  if (array[pos] == *other)
1109  {
1110  // Check to see if we have a match.
1111  u32 j;
1112  for (j = 0; j < other_size; ++j)
1113  {
1114  if (array[pos + j] != other[j])
1115  break;
1116  }
1117 
1118  // If we have a match, replace characters.
1119  if (j == other_size)
1120  {
1121  for (j = 0; j < replace_size; ++j)
1122  array[i + j] = replace[j];
1123  i += replace_size - 1;
1124  pos += other_size - 1;
1125  continue;
1126  }
1127  }
1128 
1129  // No match found, just copy characters.
1130  array[i] = array[pos];
1131  }
1132  array[i-1] = 0;
1133  used = i;
1134 
1135  return *this;
1136  }
1137 
1138  // We are going to be adding characters, so the string size will increase.
1139  // Count the number of times toReplace exists in the string so we can allocate the new size.
1140  u32 find_count = 0;
1141  s32 pos = 0;
1142  while ((pos = find(other, pos)) != -1)
1143  {
1144  ++find_count;
1145  ++pos;
1146  }
1147 
1148  // Re-allocate the string now, if needed.
1149  u32 len = delta * find_count;
1150  if (used + len > allocated)
1151  reallocate(used + len);
1152 
1153  // Start replacing.
1154  pos = 0;
1155  while ((pos = find(other, pos)) != -1)
1156  {
1157  T* start = array + pos + other_size - 1;
1158  T* ptr = array + used - 1;
1159  T* end = array + delta + used -1;
1160 
1161  // Shift characters to make room for the string.
1162  while (ptr != start)
1163  {
1164  *end = *ptr;
1165  --ptr;
1166  --end;
1167  }
1168 
1169  // Add the new string now.
1170  for (u32 i = 0; i < replace_size; ++i)
1171  array[pos + i] = replace[i];
1172 
1173  pos += replace_size;
1174  used += delta;
1175  }
1176 
1177  return *this;
1178  }
GLuint GLuint end
Definition: SDL_opengl.h:1571
s32 find(const B *const str, const u32 start=0) const
finds another string in this string
Definition: irrString.h:916
GLuint start
Definition: SDL_opengl.h:1571
GLenum GLsizei len
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
string< T, TAlloc > & replace(T toReplace, T replaceWith)
Replaces all characters of a special type with another one.
Definition: irrString.h:1063
GLenum array

◆ reserve()

template<typename T, typename TAlloc>
void irr::core::string< T, TAlloc >::reserve ( u32  count)
inline

Reserves some memory.

Parameters
countAmount of characters to reserve.

Definition at line 762 of file irrString.h.

763  {
764  if (count < allocated)
765  return;
766 
767  reallocate(count);
768  }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571

◆ size()

template<typename T, typename TAlloc>
u32 irr::core::string< T, TAlloc >::size ( ) const
inline

Returns length of the string's content.

Returns
Length of the string's content in characters, excluding the trailing NUL.

Definition at line 502 of file irrString.h.

503  {
504  return used-1;
505  }

◆ split()

template<typename T, typename TAlloc>
template<class container >
u32 irr::core::string< T, TAlloc >::split ( container &  ret,
const T *const  delimiter,
u32  countDelimiters = 1,
bool  ignoreEmptyTokens = true,
bool  keepSeparators = false 
) const
inline

Split string into parts (tokens).

This method will split a string at certain delimiter characters into the container passed in as reference. The type of the container has to be given as template parameter. It must provide a push_back and a size method.

Parameters
retThe result container. Tokens are added, the container is not cleared.
delimiterC-style string of delimiter characters
countDelimitersNumber of delimiter characters
ignoreEmptyTokensFlag to avoid empty substrings in the result container. If two delimiters occur without a character in between or an empty substring would be placed in the result. Or if a delimiter is the last character an empty substring would be added at the end. If this flag is set, only non-empty strings are stored.
keepSeparatorsFlag which allows to add the separator to the result string. If this flag is true, the concatenation of the substrings results in the original string. Otherwise, only the characters between the delimiters are returned.
Returns
The number of resulting substrings

Definition at line 1390 of file irrString.h.

1391  {
1392  if (!delimiter)
1393  return 0;
1394 
1395  const u32 oldSize=ret.size();
1396 
1397  u32 tokenStartIdx = 0;
1398  for (u32 i=0; i<used; ++i)
1399  {
1400  for (u32 j=0; j<countDelimiters; ++j)
1401  {
1402  if (array[i] == delimiter[j])
1403  {
1404  if (i - tokenStartIdx > 0)
1405  ret.push_back(string<T,TAlloc>(&array[tokenStartIdx], i - tokenStartIdx));
1406  else if ( !ignoreEmptyTokens )
1407  ret.push_back(string<T,TAlloc>());
1408  if ( keepSeparators )
1409  {
1410  ret.push_back(string<T,TAlloc>(&array[i], 1));
1411  }
1412 
1413  tokenStartIdx = i+1;
1414  break;
1415  }
1416  }
1417  }
1418  if ((used - 1) > tokenStartIdx)
1419  ret.push_back(string<T,TAlloc>(&array[tokenStartIdx], (used - 1) - tokenStartIdx));
1420  else if ( !ignoreEmptyTokens )
1421  ret.push_back(string<T,TAlloc>());
1422 
1423  return ret.size()-oldSize;
1424  }
GLsizei const GLchar *const * string
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

◆ subString()

template<typename T, typename TAlloc>
string<T> irr::core::string< T, TAlloc >::subString ( u32  begin,
s32  length,
bool  make_lower = false 
) const
inline

Returns a substring.

Parameters
beginStart of substring.
lengthLength of substring.
make_lowercopy only lower case

Definition at line 948 of file irrString.h.

949  {
950  // if start after string
951  // or no proper substring length
952  if ((length <= 0) || (begin>=size()))
953  return string<T>("");
954  // clamp length to maximal value
955  if ((length+begin) > size())
956  length = size()-begin;
957 
958  string<T> o;
959  o.reserve(length+1);
960 
961  if ( !make_lower )
962  {
963  for (s32 i=0; i<length; ++i)
964  o.array[i] = array[i+begin];
965  }
966  else
967  {
968  for (s32 i=0; i<length; ++i)
969  o.array[i] = locale_lower ( array[i+begin] );
970  }
971 
972  o.array[length] = 0;
973  o.used = length + 1;
974 
975  return o;
976  }
u32 size() const
Returns length of the string's content.
Definition: irrString.h:502
GLsizei const GLchar *const * string
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
string< T, TAlloc > & make_lower()
Makes the string lower case.
Definition: irrString.h:533
GLenum array
GLuint GLsizei GLsizei * length

◆ trim()

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::trim ( const string< T, TAlloc > &  whitespace = " \t\n\r")
inline

Trims the string.

Removes the specified characters (by default, Latin-1 whitespace) from the beginning and the end of the string.

Definition at line 1274 of file irrString.h.

1275  {
1276  // find start and end of the substring without the specified characters
1277  const s32 begin = findFirstCharNotInList(whitespace.c_str(), whitespace.used);
1278  if (begin == -1)
1279  return (*this="");
1280 
1281  const s32 end = findLastCharNotInList(whitespace.c_str(), whitespace.used);
1282 
1283  return (*this = subString(begin, (end +1) - begin));
1284  }
s32 findFirstCharNotInList(const B *const c, u32 count=1) const
Finds first position of a character not in a given list.
Definition: irrString.h:813
GLuint GLuint end
Definition: SDL_opengl.h:1571
s32 findLastCharNotInList(const B *const c, u32 count=1) const
Finds last position of a character not in a given list.
Definition: irrString.h:840
signed int s32
32 bit signed variable.
Definition: irrTypes.h:70
string< T > subString(u32 begin, s32 length, bool make_lower=false) const
Returns a substring.
Definition: irrString.h:948

◆ validate()

template<typename T, typename TAlloc>
string<T,TAlloc>& irr::core::string< T, TAlloc >::validate ( )
inline

verify the existing string.

Definition at line 1338 of file irrString.h.

1339  {
1340  // terminate on existing null
1341  for (u32 i=0; i<allocated; ++i)
1342  {
1343  if (array[i] == 0)
1344  {
1345  used = i + 1;
1346  return *this;
1347  }
1348  }
1349 
1350  // terminate
1351  if ( allocated > 0 )
1352  {
1353  used = allocated;
1354  array[used-1] = 0;
1355  }
1356  else
1357  {
1358  used = 0;
1359  }
1360 
1361  return *this;
1362  }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLenum array

Friends And Related Function Documentation

◆ multibyteToWString

template<typename T, typename TAlloc>
size_t multibyteToWString ( string< wchar_t > &  destination,
const char *  source,
u32  sourceSize 
)
friend

Internally used by the other multibyteToWString functions.

Definition at line 1487 of file irrString.h.

1488 {
1489  if ( sourceSize )
1490  {
1491  destination.reserve(sourceSize+1);
1492 #if defined(_MSC_VER)
1493 #pragma warning(push)
1494 #pragma warning(disable: 4996) // 'mbstowcs': This function or variable may be unsafe. Consider using mbstowcs_s instead.
1495 #endif
1496  const size_t written = mbstowcs(destination.array, source, (size_t)sourceSize);
1497 #if defined(_MSC_VER)
1498 #pragma warning(pop)
1499 #endif
1500  if ( written != (size_t)-1 )
1501  {
1502  destination.used = (u32)written+1;
1503  destination.array[destination.used-1] = 0;
1504  }
1505  else
1506  {
1507  // Likely character which got converted until the invalid character was encountered are in destination now.
1508  // And it seems even 0-terminated, but I found no documentation anywhere that this (the 0-termination) is guaranteed :-(
1509  destination.clear();
1510  }
1511  return written;
1512  }
1513  else
1514  {
1515  destination.clear();
1516  return 0;
1517  }
1518 }
unsigned int u32
32 bit unsigned variable.
Definition: irrTypes.h:62
GLsizei GLsizei GLchar * source

The documentation for this class was generated from the following file: