arsa  2.7
Classes | Public Types | Public Member Functions | Static Public Attributes | List of all members
irr::core::ustring16< TAlloc > Class Template Reference

UTF-16 string class. More...

#include <irrUString.h>

Classes

class  _ustring16_const_iterator
 Iterator to iterate through a UTF-16 string. More...
 
class  _ustring16_iterator
 Iterator to iterate through a UTF-16 string. More...
 
class  _ustring16_iterator_access
 Access an element in a unicode string, allowing one to change it. More...
 

Public Types

typedef ustring16< TAlloc >::_ustring16_iterator_access access
 
typedef ustring16< TAlloc >::_ustring16_iterator iterator
 
typedef ustring16< TAlloc >::_ustring16_const_iterator const_iterator
 

Public Member Functions

 ustring16 ()
 Default constructor. More...
 
 ustring16 (const ustring16< TAlloc > &other)
 Constructor. More...
 
template<class B , class A >
 ustring16 (const string< B, A > &other)
 Constructor from other string types. More...
 
 ustring16 (const char *const c)
 Constructor for copying a character string from a pointer. More...
 
 ustring16 (const char *const c, size_t length)
 Constructor for copying a character string from a pointer with a given length. More...
 
 ustring16 (const uchar8_t *const c)
 Constructor for copying a UTF-8 string from a pointer. More...
 
 ustring16 (const char c)
 Constructor for copying a UTF-8 string from a single char. More...
 
 ustring16 (const uchar8_t *const c, size_t length)
 Constructor for copying a UTF-8 string from a pointer with a given length. More...
 
 ustring16 (const uchar16_t *const c)
 Constructor for copying a UTF-16 string from a pointer. More...
 
 ustring16 (const uchar16_t *const c, size_t length)
 Constructor for copying a UTF-16 string from a pointer with a given length. More...
 
 ustring16 (const uchar32_t *const c)
 Constructor for copying a UTF-32 string from a pointer. More...
 
 ustring16 (const uchar32_t *const c, size_t length)
 Constructor for copying a UTF-32 from a pointer with a given length. More...
 
 ustring16 (const wchar_t *const c)
 Constructor for copying a wchar_t string from a pointer. More...
 
 ustring16 (const wchar_t *const c, size_t length)
 Constructor for copying a wchar_t string from a pointer with a given length. More...
 
 ~ustring16 ()
 Destructor. More...
 
ustring16operator= (const ustring16< TAlloc > &other)
 Assignment operator. More...
 
template<class B , class A >
ustring16< TAlloc > & operator= (const string< B, A > &other)
 Assignment operator for other string types. More...
 
ustring16< TAlloc > & operator= (const uchar8_t *const c)
 Assignment operator for UTF-8 strings. More...
 
ustring16< TAlloc > & operator= (const uchar16_t *const c)
 Assignment operator for UTF-16 strings. More...
 
ustring16< TAlloc > & operator= (const uchar32_t *const c)
 Assignment operator for UTF-32 strings. More...
 
ustring16< TAlloc > & operator= (const wchar_t *const c)
 Assignment operator for wchar_t strings. More...
 
template<class B >
ustring16< TAlloc > & operator= (const B *const c)
 Assignment operator for other strings. More...
 
access operator [] (const size_t index)
 Direct access operator. More...
 
const access operator [] (const size_t index) const
 Direct access operator. More...
 
bool operator== (const uchar16_t *const str) const
 Equality operator. More...
 
bool operator== (const ustring16< TAlloc > &other) const
 Equality operator. More...
 
bool operator< (const ustring16< TAlloc > &other) const
 Is smaller comparator. More...
 
bool operator != (const uchar16_t *const str) const
 Inequality operator. More...
 
bool operator != (const ustring16< TAlloc > &other) const
 Inequality operator. More...
 
size_t size () const
 
bool empty () const
 
const uchar16_tc_str () const
 
bool equalsn (const ustring16< TAlloc > &other, size_t n) const
 
bool equalsn (const uchar16_t *const str, size_t n) const
 
ustring16< TAlloc > & append (uchar32_t character)
 
ustring16< TAlloc > & append (const uchar8_t *const other, size_t length=0xffffffff)
 
ustring16< TAlloc > & append (const uchar16_t *const other, size_t length=0xffffffff)
 
ustring16< TAlloc > & append (const uchar32_t *const other, size_t length=0xffffffff)
 
ustring16< TAlloc > & append (const ustring16< TAlloc > &other)
 
ustring16< TAlloc > & append (const ustring16< TAlloc > &other, size_t length)
 
void reserve (size_t count)
 
size_t findFirst (uchar32_t c) const
 
size_t findFirstChar (const uchar32_t *const c, size_t count=1) const
 
size_t findFirstCharNotInList (const uchar32_t *const c, size_t count=1) const
 
size_t findLastCharNotInList (const uchar32_t *const c, size_t count=1) const
 
size_t findNext (uchar32_t c, size_t startPos) const
 
size_t findLast (uchar32_t c, size_t start=ustring16< TAlloc >::npos) const
 
size_t findLastChar (const uchar32_t *const c, size_t count=1) const
 
size_t find (const ustring16< TAlloc > &str, const size_t start=0) const
 
size_t find_raw (const ustring16< TAlloc > &str, const size_t start=0) const
 
ustring16< TAlloc > subString (size_t begin, size_t length) const
 
ustring16< TAlloc > & operator+= (char c)
 
ustring16< TAlloc > & operator+= (uchar32_t c)
 
ustring16< TAlloc > & operator+= (short c)
 
ustring16< TAlloc > & operator+= (unsigned short c)
 
ustring16< TAlloc > & operator+= (long c)
 
ustring16< TAlloc > & operator+= (unsigned long c)
 
ustring16< TAlloc > & operator+= (double c)
 
ustring16< TAlloc > & operator+= (const uchar16_t *const c)
 
ustring16< TAlloc > & operator+= (const ustring16< TAlloc > &other)
 
ustring16< TAlloc > & replace (uchar32_t toReplace, uchar32_t replaceWith)
 
ustring16< TAlloc > & replace (const ustring16< TAlloc > &toReplace, const ustring16< TAlloc > &replaceWith)
 
ustring16< TAlloc > & remove (uchar32_t c)
 
ustring16< TAlloc > & remove (const ustring16< TAlloc > &toRemove)
 
ustring16< TAlloc > & removeChars (const ustring16< TAlloc > &characters)
 
ustring16< TAlloc > & trim (const ustring16< TAlloc > &whitespace=" \t\n\r")
 
ustring16< TAlloc > & erase (size_t index)
 
ustring16< TAlloc > & validate ()
 
uchar32_t lastChar () const
 
template<class container >
size_t split (container &ret, const uchar32_t *const c, size_t count=1, bool ignoreEmptyTokens=true, bool keepSeparators=false) const
 Split the ustring16 into parts. More...
 
template<class container >
size_t split (container &ret, const ustring16< TAlloc > &c, bool ignoreEmptyTokens=true, bool keepSeparators=false) const
 Split the ustring16 into parts. More...
 
size_t capacity () const
 
size_t size_raw () const
 
ustring16< TAlloc > & insert (uchar32_t c, size_t pos)
 
ustring16< TAlloc > & insert (const ustring16< TAlloc > &c, size_t pos)
 
ustring16< TAlloc > & insert_raw (uchar16_t c, size_t pos)
 
ustring16< TAlloc > & erase_raw (size_t pos)
 
ustring16< TAlloc > & replace_raw (uchar16_t c, size_t pos)
 
iterator begin ()
 
const_iterator begin () const
 
const_iterator cbegin () const
 
iterator end ()
 
const_iterator end () const
 
const_iterator cend () const
 
core::string< uchar8_ttoUTF8_s (const bool addBOM=false) const
 
core::array< uchar8_ttoUTF8 (const bool addBOM=false) const
 
core::array< uchar16_ttoUTF16 (const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
 
core::array< uchar32_ttoUTF32 (const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
 
core::string< wchar_t > toWCHAR_s (const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
 Converts the string to a wchar_t encoded string. More...
 
core::array< wchar_t > toWCHAR (const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
 Converts the string to a wchar_t encoded string array. More...
 
io::path toPATH_s (const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
 
ustring16< TAlloc > & loadDataStream (const char *data, size_t data_size)
 
const unicode::EUTF_ENCODE getEncoding () const
 
const unicode::EUTF_ENDIAN getEndianness () const
 

Static Public Attributes

static const size_t npos = -1
 

Detailed Description

template<typename TAlloc = irrAllocator<uchar16_t>>
class irr::core::ustring16< TAlloc >

UTF-16 string class.

Definition at line 236 of file irrUString.h.

Member Typedef Documentation

◆ access

template<typename TAlloc = irrAllocator<uchar16_t>>
typedef ustring16<TAlloc>::_ustring16_iterator_access irr::core::ustring16< TAlloc >::access

Definition at line 435 of file irrUString.h.

◆ const_iterator

template<typename TAlloc = irrAllocator<uchar16_t>>
typedef ustring16<TAlloc>::_ustring16_const_iterator irr::core::ustring16< TAlloc >::const_iterator

Definition at line 798 of file irrUString.h.

◆ iterator

template<typename TAlloc = irrAllocator<uchar16_t>>
typedef ustring16<TAlloc>::_ustring16_iterator irr::core::ustring16< TAlloc >::iterator

Definition at line 797 of file irrUString.h.

Constructor & Destructor Documentation

◆ ustring16() [1/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( )
inline

Default constructor.

Definition at line 812 of file irrUString.h.

813  : array(0), allocated(1), used(0)
814  {
815 #if __BIG_ENDIAN__
816  encoding = unicode::EUTFE_UTF16_BE;
817 #else
818  encoding = unicode::EUTFE_UTF16_LE;
819 #endif
820  array = allocator.allocate(1); // new u16[1];
821  array[0] = 0x0;
822  }
GLenum array

◆ ustring16() [2/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( const ustring16< TAlloc > &  other)
inline

Constructor.

Definition at line 826 of file irrUString.h.

827  : array(0), allocated(0), used(0)
828  {
829 #if __BIG_ENDIAN__
830  encoding = unicode::EUTFE_UTF16_BE;
831 #else
832  encoding = unicode::EUTFE_UTF16_LE;
833 #endif
834  *this = other;
835  }
GLenum array

◆ ustring16() [3/14]

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

Constructor from other string types.

Definition at line 840 of file irrUString.h.

841  : array(0), allocated(0), used(0)
842  {
843 #if __BIG_ENDIAN__
844  encoding = unicode::EUTFE_UTF16_BE;
845 #else
846  encoding = unicode::EUTFE_UTF16_LE;
847 #endif
848  *this = other;
849  }
GLenum array

◆ ustring16() [4/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( const char *const  c)
inline

Constructor for copying a character string from a pointer.

Definition at line 888 of file irrUString.h.

889  : array(0), allocated(0), used(0)
890  {
891 #if __BIG_ENDIAN__
892  encoding = unicode::EUTFE_UTF16_BE;
893 #else
894  encoding = unicode::EUTFE_UTF16_LE;
895 #endif
896 
897  loadDataStream(c, strlen(c));
898  //append((uchar8_t*)c);
899  }
ustring16< TAlloc > & loadDataStream(const char *data, size_t data_size)
Definition: irrUString.h:3207
GLenum array
const GLubyte * c

◆ ustring16() [5/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( const char *const  c,
size_t  length 
)
inline

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

Definition at line 903 of file irrUString.h.

904  : array(0), allocated(0), used(0)
905  {
906 #if __BIG_ENDIAN__
907  encoding = unicode::EUTFE_UTF16_BE;
908 #else
909  encoding = unicode::EUTFE_UTF16_LE;
910 #endif
911 
913  }
ustring16< TAlloc > & loadDataStream(const char *data, size_t data_size)
Definition: irrUString.h:3207
GLenum array
GLuint GLsizei GLsizei * length
const GLubyte * c

◆ ustring16() [6/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( const uchar8_t *const  c)
inline

Constructor for copying a UTF-8 string from a pointer.

Definition at line 918 of file irrUString.h.

919  : array(0), allocated(0), used(0)
920  {
921 #if __BIG_ENDIAN__
922  encoding = unicode::EUTFE_UTF16_BE;
923 #else
924  encoding = unicode::EUTFE_UTF16_LE;
925 #endif
926 
927  append(c);
928  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
GLenum array
const GLubyte * c

◆ ustring16() [7/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( const char  c)
inline

Constructor for copying a UTF-8 string from a single char.

Definition at line 932 of file irrUString.h.

933  : array(0), allocated(0), used(0)
934  {
935 #if __BIG_ENDIAN__
936  encoding = unicode::EUTFE_UTF16_BE;
937 #else
938  encoding = unicode::EUTFE_UTF16_LE;
939 #endif
940 
941  append((uchar32_t)c);
942  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
GLenum array
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ ustring16() [8/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( const uchar8_t *const  c,
size_t  length 
)
inline

Constructor for copying a UTF-8 string from a pointer with a given length.

Definition at line 946 of file irrUString.h.

947  : array(0), allocated(0), used(0)
948  {
949 #if __BIG_ENDIAN__
950  encoding = unicode::EUTFE_UTF16_BE;
951 #else
952  encoding = unicode::EUTFE_UTF16_LE;
953 #endif
954 
955  append(c, length);
956  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
GLenum array
GLuint GLsizei GLsizei * length
const GLubyte * c

◆ ustring16() [9/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( const uchar16_t *const  c)
inline

Constructor for copying a UTF-16 string from a pointer.

Definition at line 960 of file irrUString.h.

961  : array(0), allocated(0), used(0)
962  {
963 #if __BIG_ENDIAN__
964  encoding = unicode::EUTFE_UTF16_BE;
965 #else
966  encoding = unicode::EUTFE_UTF16_LE;
967 #endif
968 
969  append(c);
970  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
GLenum array
const GLubyte * c

◆ ustring16() [10/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( const uchar16_t *const  c,
size_t  length 
)
inline

Constructor for copying a UTF-16 string from a pointer with a given length.

Definition at line 974 of file irrUString.h.

975  : array(0), allocated(0), used(0)
976  {
977 #if __BIG_ENDIAN__
978  encoding = unicode::EUTFE_UTF16_BE;
979 #else
980  encoding = unicode::EUTFE_UTF16_LE;
981 #endif
982 
983  append(c, length);
984  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
GLenum array
GLuint GLsizei GLsizei * length
const GLubyte * c

◆ ustring16() [11/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( const uchar32_t *const  c)
inline

Constructor for copying a UTF-32 string from a pointer.

Definition at line 988 of file irrUString.h.

989  : array(0), allocated(0), used(0)
990  {
991 #if __BIG_ENDIAN__
992  encoding = unicode::EUTFE_UTF16_BE;
993 #else
994  encoding = unicode::EUTFE_UTF16_LE;
995 #endif
996 
997  append(c);
998  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
GLenum array
const GLubyte * c

◆ ustring16() [12/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( const uchar32_t *const  c,
size_t  length 
)
inline

Constructor for copying a UTF-32 from a pointer with a given length.

Definition at line 1002 of file irrUString.h.

1003  : array(0), allocated(0), used(0)
1004  {
1005 #if __BIG_ENDIAN__
1006  encoding = unicode::EUTFE_UTF16_BE;
1007 #else
1008  encoding = unicode::EUTFE_UTF16_LE;
1009 #endif
1010 
1011  append(c, length);
1012  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
GLenum array
GLuint GLsizei GLsizei * length
const GLubyte * c

◆ ustring16() [13/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( const wchar_t *const  c)
inline

Constructor for copying a wchar_t string from a pointer.

Definition at line 1016 of file irrUString.h.

1017  : array(0), allocated(0), used(0)
1018  {
1019 #if __BIG_ENDIAN__
1020  encoding = unicode::EUTFE_UTF16_BE;
1021 #else
1022  encoding = unicode::EUTFE_UTF16_LE;
1023 #endif
1024 
1025  if (sizeof(wchar_t) == 4)
1026  append(reinterpret_cast<const uchar32_t* const>(c));
1027  else if (sizeof(wchar_t) == 2)
1028  append(reinterpret_cast<const uchar16_t* const>(c));
1029  else if (sizeof(wchar_t) == 1)
1030  append(reinterpret_cast<const uchar8_t* const>(c));
1031  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
GLenum array
const GLubyte * c

◆ ustring16() [14/14]

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::ustring16 ( const wchar_t *const  c,
size_t  length 
)
inline

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

Definition at line 1035 of file irrUString.h.

1036  : array(0), allocated(0), used(0)
1037  {
1038 #if __BIG_ENDIAN__
1039  encoding = unicode::EUTFE_UTF16_BE;
1040 #else
1041  encoding = unicode::EUTFE_UTF16_LE;
1042 #endif
1043 
1044  if (sizeof(wchar_t) == 4)
1045  append(reinterpret_cast<const uchar32_t* const>(c), length);
1046  else if (sizeof(wchar_t) == 2)
1047  append(reinterpret_cast<const uchar16_t* const>(c), length);
1048  else if (sizeof(wchar_t) == 1)
1049  append(reinterpret_cast<const uchar8_t* const>(c), length);
1050  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
GLenum array
GLuint GLsizei GLsizei * length
const GLubyte * c

◆ ~ustring16()

template<typename TAlloc = irrAllocator<uchar16_t>>
irr::core::ustring16< TAlloc >::~ustring16 ( )
inline

Destructor.

Definition at line 1067 of file irrUString.h.

1068  {
1069  allocator.deallocate(array); // delete [] array;
1070  }
GLenum array

Member Function Documentation

◆ append() [1/6]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::append ( uchar32_t  character)
inline

Appends a character to this ustring16

Parameters
characterThe character to append.
Returns
A reference to our current string.

Definition at line 1360 of file irrUString.h.

1361  {
1362  if (used + 2 >= allocated)
1363  reallocate(used + 2);
1364 
1365  if (character > 0xFFFF)
1366  {
1367  used += 2;
1368 
1369  // character will be multibyte, so split it up into a surrogate pair.
1370  uchar16_t x = static_cast<uchar16_t>(character);
1371  uchar16_t vh = UTF16_HI_SURROGATE | ((((character >> 16) & ((1 << 5) - 1)) - 1) << 6) | (x >> 10);
1372  uchar16_t vl = UTF16_LO_SURROGATE | (x & ((1 << 10) - 1));
1373  array[used-2] = vh;
1374  array[used-1] = vl;
1375  }
1376  else
1377  {
1378  ++used;
1379  array[used-1] = character;
1380  }
1381  array[used] = 0;
1382 
1383  return *this;
1384  }
u16 uchar16_t
Definition: irrUString.h:86
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLenum array

◆ append() [2/6]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::append ( const uchar8_t *const  other,
size_t  length = 0xffffffff 
)
inline

Appends a UTF-8 string to this ustring16

Parameters
otherThe UTF-8 string to append.
lengthThe length of the string to append.
Returns
A reference to our current string.

Definition at line 1391 of file irrUString.h.

1392  {
1393  if (!other)
1394  return *this;
1395 
1396  // Determine if the string is long enough for a BOM.
1397  size_t len = 0;
1398  const uchar8_t* p = other;
1399  do
1400  {
1401  ++len;
1402  } while (*p++ && len < unicode::BOM_ENCODE_UTF8_LEN);
1403 
1404  // Check for BOM.
1407  {
1408  if (memcmp(other, unicode::BOM_ENCODE_UTF8, unicode::BOM_ENCODE_UTF8_LEN) == 0)
1409  c_bom = unicode::EUTFE_UTF8;
1410  }
1411 
1412  // If a BOM was found, don't include it in the string.
1413  const uchar8_t* c2 = other;
1414  if (c_bom != unicode::EUTFE_NONE)
1415  {
1416  c2 = other + unicode::BOM_UTF8_LEN;
1418  }
1419 
1420  // Calculate the size of the string to read in.
1421  len = 0;
1422  p = c2;
1423  do
1424  {
1425  ++len;
1426  } while(*p++ && len < length);
1427  if (len > length)
1428  len = length;
1429 
1430  // If we need to grow the array, do it now.
1431  if (used + len >= allocated)
1432  reallocate(used + (len * 2));
1433  size_t start = used;
1434 
1435  // Convert UTF-8 to UTF-16.
1436  size_t pos = start;
1437  for (size_t l = 0; l<len;)
1438  {
1439  ++used;
1440  if (((c2[l] >> 6) & 0x03) == 0x02)
1441  { // Invalid continuation byte.
1443  ++l;
1444  }
1445  else if (c2[l] == 0xC0 || c2[l] == 0xC1)
1446  { // Invalid byte - overlong encoding.
1448  ++l;
1449  }
1450  else if ((c2[l] & 0xF8) == 0xF0)
1451  { // 4 bytes UTF-8, 2 bytes UTF-16.
1452  // Check for a full string.
1453  if ((l + 3) >= len)
1454  {
1456  l += 3;
1457  break;
1458  }
1459 
1460  // Validate.
1461  bool valid = true;
1462  u8 l2 = 0;
1463  if (valid && (((c2[l+1] >> 6) & 0x03) == 0x02)) ++l2; else valid = false;
1464  if (valid && (((c2[l+2] >> 6) & 0x03) == 0x02)) ++l2; else valid = false;
1465  if (valid && (((c2[l+3] >> 6) & 0x03) == 0x02)) ++l2; else valid = false;
1466  if (!valid)
1467  {
1469  l += l2;
1470  continue;
1471  }
1472 
1473  // Decode.
1474  uchar8_t b1 = ((c2[l] & 0x7) << 2) | ((c2[l+1] >> 4) & 0x3);
1475  uchar8_t b2 = ((c2[l+1] & 0xF) << 4) | ((c2[l+2] >> 2) & 0xF);
1476  uchar8_t b3 = ((c2[l+2] & 0x3) << 6) | (c2[l+3] & 0x3F);
1477  uchar32_t v = b3 | ((uchar32_t)b2 << 8) | ((uchar32_t)b1 << 16);
1478 
1479  // Split v up into a surrogate pair.
1480  uchar16_t x = static_cast<uchar16_t>(v);
1481  uchar16_t vh = UTF16_HI_SURROGATE | ((((v >> 16) & ((1 << 5) - 1)) - 1) << 6) | (x >> 10);
1482  uchar16_t vl = UTF16_LO_SURROGATE | (x & ((1 << 10) - 1));
1483 
1484  array[pos++] = vh;
1485  array[pos++] = vl;
1486  l += 4;
1487  ++used; // Using two shorts this time, so increase used by 1.
1488  }
1489  else if ((c2[l] & 0xF0) == 0xE0)
1490  { // 3 bytes UTF-8, 1 byte UTF-16.
1491  // Check for a full string.
1492  if ((l + 2) >= len)
1493  {
1495  l += 2;
1496  break;
1497  }
1498 
1499  // Validate.
1500  bool valid = true;
1501  u8 l2 = 0;
1502  if (valid && (((c2[l+1] >> 6) & 0x03) == 0x02)) ++l2; else valid = false;
1503  if (valid && (((c2[l+2] >> 6) & 0x03) == 0x02)) ++l2; else valid = false;
1504  if (!valid)
1505  {
1507  l += l2;
1508  continue;
1509  }
1510 
1511  // Decode.
1512  uchar8_t b1 = ((c2[l] & 0xF) << 4) | ((c2[l+1] >> 2) & 0xF);
1513  uchar8_t b2 = ((c2[l+1] & 0x3) << 6) | (c2[l+2] & 0x3F);
1514  uchar16_t ch = b2 | ((uchar16_t)b1 << 8);
1515  array[pos++] = ch;
1516  l += 3;
1517  }
1518  else if ((c2[l] & 0xE0) == 0xC0)
1519  { // 2 bytes UTF-8, 1 byte UTF-16.
1520  // Check for a full string.
1521  if ((l + 1) >= len)
1522  {
1524  l += 1;
1525  break;
1526  }
1527 
1528  // Validate.
1529  if (((c2[l+1] >> 6) & 0x03) != 0x02)
1530  {
1532  ++l;
1533  continue;
1534  }
1535 
1536  // Decode.
1537  uchar8_t b1 = (c2[l] >> 2) & 0x7;
1538  uchar8_t b2 = ((c2[l] & 0x3) << 6) | (c2[l+1] & 0x3F);
1539  uchar16_t ch = b2 | ((uchar16_t)b1 << 8);
1540  array[pos++] = ch;
1541  l += 2;
1542  }
1543  else
1544  { // 1 byte UTF-8, 1 byte UTF-16.
1545  // Validate.
1546  if (c2[l] > 0x7F)
1547  { // Values above 0xF4 are restricted and aren't used. By now, anything above 0x7F is invalid.
1549  }
1550  else array[pos++] = static_cast<uchar16_t>(c2[l]);
1551  ++l;
1552  }
1553  }
1554  array[used] = 0;
1555 
1556  // Validate our new UTF-16 string.
1557  validate();
1558 
1559  return *this;
1560  }
u16 uchar16_t
Definition: irrUString.h:86
const u8 BOM_ENCODE_UTF8[3]
Unicode byte order marks for file operations.
Definition: irrUString.h:137
GLfloat GLfloat p
GLuint start
Definition: SDL_opengl.h:1571
GLenum GLsizei len
unsigned char u8
8 bit unsigned variable.
Definition: irrTypes.h:22
EUTF_ENCODE
Unicode encoding type.
Definition: irrUString.h:149
const GLdouble * v
Definition: SDL_opengl.h:2064
ustring16< TAlloc > & validate()
Definition: irrUString.h:2468
u8 uchar8_t
Definition: irrUString.h:87
const u8 BOM_UTF8_LEN
The size of the Unicode byte order mark in terms of the Unicode character size.
Definition: irrUString.h:132
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
const irr::u16 UTF_REPLACEMENT_CHARACTER
The unicode replacement character. Used to replace invalid characters.
Definition: irrUString.h:97
GLenum array
GLuint GLsizei GLsizei * length
u32 uchar32_t
Definition: irrUString.h:85
const u8 BOM_ENCODE_UTF8_LEN
The size in bytes of the Unicode byte marks for file operations.
Definition: irrUString.h:144

◆ append() [3/6]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::append ( const uchar16_t *const  other,
size_t  length = 0xffffffff 
)
inline

Appends a UTF-16 string to this ustring16

Parameters
otherThe UTF-16 string to append.
lengthThe length of the string to append.
Returns
A reference to our current string.

Definition at line 1567 of file irrUString.h.

1568  {
1569  if (!other)
1570  return *this;
1571 
1572  // Determine if the string is long enough for a BOM.
1573  size_t len = 0;
1574  const uchar16_t* p = other;
1575  do
1576  {
1577  ++len;
1578  } while (*p++ && len < unicode::BOM_ENCODE_UTF16_LEN);
1579 
1580  // Check for the BOM to determine the string's endianness.
1583  c_end = unicode::EUTFEE_LITTLE;
1584  else if (memcmp(other, unicode::BOM_ENCODE_UTF16_BE, unicode::BOM_ENCODE_UTF16_LEN) == 0)
1585  c_end = unicode::EUTFEE_BIG;
1586 
1587  // If a BOM was found, don't include it in the string.
1588  const uchar16_t* c2 = other;
1589  if (c_end != unicode::EUTFEE_NATIVE)
1590  {
1591  c2 = other + unicode::BOM_UTF16_LEN;
1593  }
1594 
1595  // Calculate the size of the string to read in.
1596  len = 0;
1597  p = c2;
1598  do
1599  {
1600  ++len;
1601  } while(*p++ && len < length);
1602  if (len > length)
1603  len = length;
1604 
1605  // If we need to grow the size of the array, do it now.
1606  if (used + len >= allocated)
1607  reallocate(used + (len * 2));
1608  size_t start = used;
1609  used += len;
1610 
1611  // Copy the string now.
1613  for (size_t l = start; l < start + len; ++l)
1614  {
1615  array[l] = (uchar16_t)c2[l];
1616  if (c_end != unicode::EUTFEE_NATIVE && c_end != m_end)
1618  }
1619 
1620  array[used] = 0;
1621 
1622  // Validate our new UTF-16 string.
1623  validate();
1624  return *this;
1625  }
u16 uchar16_t
Definition: irrUString.h:86
const u8 BOM_UTF16_LEN
Definition: irrUString.h:133
const unicode::EUTF_ENDIAN getEndianness() const
Definition: irrUString.h:3247
const u8 BOM_ENCODE_UTF16_LEN
Definition: irrUString.h:145
GLfloat GLfloat p
GLuint start
Definition: SDL_opengl.h:1571
GLenum GLsizei len
ustring16< TAlloc > & validate()
Definition: irrUString.h:2468
const u8 BOM_ENCODE_UTF16_BE[2]
Definition: irrUString.h:138
uchar16_t swapEndian16(const uchar16_t &c)
Definition: irrUString.h:113
EUTF_ENDIAN
Unicode endianness.
Definition: irrUString.h:162
GLenum array
GLuint GLsizei GLsizei * length
const u8 BOM_ENCODE_UTF16_LE[2]
Definition: irrUString.h:139

◆ append() [4/6]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::append ( const uchar32_t *const  other,
size_t  length = 0xffffffff 
)
inline

Appends a UTF-32 string to this ustring16

Parameters
otherThe UTF-32 string to append.
lengthThe length of the string to append.
Returns
A reference to our current string.

Definition at line 1632 of file irrUString.h.

1633  {
1634  if (!other)
1635  return *this;
1636 
1637  // Check for the BOM to determine the string's endianness.
1640  c_end = unicode::EUTFEE_LITTLE;
1641  else if (memcmp(other, unicode::BOM_ENCODE_UTF32_BE, unicode::BOM_ENCODE_UTF32_LEN) == 0)
1642  c_end = unicode::EUTFEE_BIG;
1643 
1644  // If a BOM was found, don't include it in the string.
1645  const uchar32_t* c2 = other;
1646  if (c_end != unicode::EUTFEE_NATIVE)
1647  {
1648  c2 = other + unicode::BOM_UTF32_LEN;
1650  }
1651 
1652  // Calculate the size of the string to read in.
1653  size_t len = 0;
1654  const uchar32_t* p = c2;
1655  do
1656  {
1657  ++len;
1658  } while(*p++ && len < length);
1659  if (len > length)
1660  len = length;
1661 
1662  // If we need to grow the size of the array, do it now.
1663  // In case all of the UTF-32 string is split into surrogate pairs, do len * 2.
1664  if (used + (len * 2) >= allocated)
1665  reallocate(used + ((len * 2) * 2));
1666  size_t start = used;
1667 
1668  // Convert UTF-32 to UTF-16.
1670  size_t pos = start;
1671  for (size_t l = 0; l<len; ++l)
1672  {
1673  ++used;
1674 
1675  uchar32_t ch = c2[l];
1676  if (c_end != unicode::EUTFEE_NATIVE && c_end != m_end)
1677  ch = unicode::swapEndian32(ch);
1678 
1679  if (ch > 0xFFFF)
1680  {
1681  // Split ch up into a surrogate pair as it is over 16 bits long.
1682  uchar16_t x = static_cast<uchar16_t>(ch);
1683  uchar16_t vh = UTF16_HI_SURROGATE | ((((ch >> 16) & ((1 << 5) - 1)) - 1) << 6) | (x >> 10);
1684  uchar16_t vl = UTF16_LO_SURROGATE | (x & ((1 << 10) - 1));
1685  array[pos++] = vh;
1686  array[pos++] = vl;
1687  ++used; // Using two shorts, so increased used again.
1688  }
1689  else if (ch >= 0xD800 && ch <= 0xDFFF)
1690  {
1691  // Between possible UTF-16 surrogates (invalid!)
1693  }
1694  else array[pos++] = static_cast<uchar16_t>(ch);
1695  }
1696  array[used] = 0;
1697 
1698  // Validate our new UTF-16 string.
1699  validate();
1700 
1701  return *this;
1702  }
u16 uchar16_t
Definition: irrUString.h:86
const u8 BOM_ENCODE_UTF32_LEN
Definition: irrUString.h:146
const unicode::EUTF_ENDIAN getEndianness() const
Definition: irrUString.h:3247
GLfloat GLfloat p
GLuint start
Definition: SDL_opengl.h:1571
uchar32_t swapEndian32(const uchar32_t &c)
Definition: irrUString.h:120
GLenum GLsizei len
ustring16< TAlloc > & validate()
Definition: irrUString.h:2468
const u8 BOM_ENCODE_UTF32_LE[4]
Definition: irrUString.h:141
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
EUTF_ENDIAN
Unicode endianness.
Definition: irrUString.h:162
const irr::u16 UTF_REPLACEMENT_CHARACTER
The unicode replacement character. Used to replace invalid characters.
Definition: irrUString.h:97
const u8 BOM_ENCODE_UTF32_BE[4]
Definition: irrUString.h:140
GLenum array
GLuint GLsizei GLsizei * length
u32 uchar32_t
Definition: irrUString.h:85
const u8 BOM_UTF32_LEN
Definition: irrUString.h:134

◆ append() [5/6]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::append ( const ustring16< TAlloc > &  other)
inline

Appends a ustring16 to this ustring16

Parameters
otherThe string to append to this one.
Returns
A reference to our current string.

Definition at line 1708 of file irrUString.h.

1709  {
1710  const uchar16_t* oa = other.c_str();
1711 
1712  size_t len = other.size_raw();
1713 
1714  if (used + len >= allocated)
1715  reallocate(used + len);
1716 
1717  for (size_t l=0; l<len; ++l)
1718  array[used+l] = oa[l];
1719 
1720  used += len;
1721  array[used] = 0;
1722 
1723  return *this;
1724  }
u16 uchar16_t
Definition: irrUString.h:86
GLenum GLsizei len
GLenum array

◆ append() [6/6]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::append ( const ustring16< TAlloc > &  other,
size_t  length 
)
inline

Appends a certain amount of characters of a ustring16 to this ustring16.

Parameters
otherThe string to append to this one.
lengthHow many characters of the other string to add to this one.
Returns
A reference to our current string.

Definition at line 1731 of file irrUString.h.

1732  {
1733  if (other.size() == 0)
1734  return *this;
1735 
1736  if (other.size() < length)
1737  {
1738  append(other);
1739  return *this;
1740  }
1741 
1742  if (used + length * 2 >= allocated)
1743  reallocate(used + length * 2);
1744 
1745  const_iterator iter(other, 0);
1746  size_t l = length;
1747  while (!iter.atEnd() && l)
1748  {
1749  uchar32_t c = *iter;
1750  append(c);
1751  ++iter;
1752  --l;
1753  }
1754 
1755  return *this;
1756  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
GLuint GLsizei GLsizei * length
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ begin() [1/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
iterator irr::core::ustring16< TAlloc >::begin ( )
inline

Returns an iterator to the beginning of the string.

Returns
An iterator to the beginning of the string.

Definition at line 2741 of file irrUString.h.

2742  {
2743  iterator i(*this, 0);
2744  return i;
2745  }
ustring16< TAlloc >::_ustring16_iterator iterator
Definition: irrUString.h:797

◆ begin() [2/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
const_iterator irr::core::ustring16< TAlloc >::begin ( ) const
inline

Returns an iterator to the beginning of the string.

Returns
An iterator to the beginning of the string.

Definition at line 2750 of file irrUString.h.

2751  {
2752  const_iterator i(*this, 0);
2753  return i;
2754  }
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798

◆ c_str()

template<typename TAlloc = irrAllocator<uchar16_t>>
const uchar16_t* irr::core::ustring16< TAlloc >::c_str ( ) const
inline

Returns a pointer to the raw UTF-16 string data.

Returns
pointer to C-style NUL terminated array of UTF-16 code points.

Definition at line 1314 of file irrUString.h.

1315  {
1316  return array;
1317  }
GLenum array

◆ capacity()

template<typename TAlloc = irrAllocator<uchar16_t>>
size_t irr::core::ustring16< TAlloc >::capacity ( ) const
inline

Gets the size of the allocated memory buffer for the string.

Returns
The size of the allocated memory buffer.

Definition at line 2614 of file irrUString.h.

2615  {
2616  return allocated;
2617  }

◆ cbegin()

template<typename TAlloc = irrAllocator<uchar16_t>>
const_iterator irr::core::ustring16< TAlloc >::cbegin ( ) const
inline

Returns an iterator to the beginning of the string.

Returns
An iterator to the beginning of the string.

Definition at line 2759 of file irrUString.h.

2760  {
2761  const_iterator i(*this, 0);
2762  return i;
2763  }
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798

◆ cend()

template<typename TAlloc = irrAllocator<uchar16_t>>
const_iterator irr::core::ustring16< TAlloc >::cend ( ) const
inline

Returns an iterator to the end of the string.

Returns
An iterator to the end of the string.

Definition at line 2788 of file irrUString.h.

2789  {
2790  const_iterator i(*this, 0);
2791  i.toEnd();
2792  return i;
2793  }
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798

◆ empty()

template<typename TAlloc = irrAllocator<uchar16_t>>
bool irr::core::ustring16< TAlloc >::empty ( ) const
inline

Informs if the ustring is empty or not.

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

Definition at line 1306 of file irrUString.h.

1307  {
1308  return (size_raw() == 0);
1309  }
size_t size_raw() const
Definition: irrUString.h:2622

◆ end() [1/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
iterator irr::core::ustring16< TAlloc >::end ( )
inline

Returns an iterator to the end of the string.

Returns
An iterator to the end of the string.

Definition at line 2768 of file irrUString.h.

2769  {
2770  iterator i(*this, 0);
2771  i.toEnd();
2772  return i;
2773  }
ustring16< TAlloc >::_ustring16_iterator iterator
Definition: irrUString.h:797

◆ end() [2/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
const_iterator irr::core::ustring16< TAlloc >::end ( ) const
inline

Returns an iterator to the end of the string.

Returns
An iterator to the end of the string.

Definition at line 2778 of file irrUString.h.

2779  {
2780  const_iterator i(*this, 0);
2781  i.toEnd();
2782  return i;
2783  }
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798

◆ equalsn() [1/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
bool irr::core::ustring16< TAlloc >::equalsn ( const ustring16< TAlloc > &  other,
size_t  n 
) const
inline

Compares the first n characters of this string with another.

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

Definition at line 1324 of file irrUString.h.

1325  {
1326  size_t i;
1327  const uchar16_t* oa = other.c_str();
1328  for(i=0; array[i] && oa[i] && i < n; ++i)
1329  if (array[i] != oa[i])
1330  return false;
1331 
1332  // if one (or both) of the strings was smaller then they
1333  // are only equal if they have the same length
1334  return (i == n) || (used == other.used);
1335  }
u16 uchar16_t
Definition: irrUString.h:86
GLdouble n
GLenum array

◆ equalsn() [2/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
bool irr::core::ustring16< TAlloc >::equalsn ( const uchar16_t *const  str,
size_t  n 
) const
inline

Compares the first n characters of this string with another.

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

Definition at line 1342 of file irrUString.h.

1343  {
1344  if (!str)
1345  return false;
1346  size_t i;
1347  for(i=0; array[i] && str[i] && i < n; ++i)
1348  if (array[i] != str[i])
1349  return false;
1350 
1351  // if one (or both) of the strings was smaller then they
1352  // are only equal if they have the same length
1353  return (i == n) || (array[i] == 0 && str[i] == 0);
1354  }
GLdouble n
GLenum array

◆ erase()

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::erase ( size_t  index)
inline

Erases a character from the ustring16. May be slow, because all elements following after the erased element have to be copied.

Parameters
indexIndex of element to be erased.
Returns
A reference to our current string.

Definition at line 2447 of file irrUString.h.

2448  {
2449  _IRR_DEBUG_BREAK_IF(index>used) // access violation
2450 
2451  iterator i(*this, index);
2452 
2453  uchar32_t t = *i;
2454  size_t len = (t > 0xFFFF ? 2 : 1);
2455 
2456  for (size_t j = i.getPos() + len; j <= used; ++j)
2457  array[j - len] = array[j];
2458 
2459  used -= len;
2460  array[used] = 0;
2461 
2462  return *this;
2463  }
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
ustring16< TAlloc >::_ustring16_iterator iterator
Definition: irrUString.h:797
GLenum GLsizei len
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
Definition: irrTypes.h:185
GLuint index
GLenum array
u32 uchar32_t
Definition: irrUString.h:85

◆ erase_raw()

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::erase_raw ( size_t  pos)
inline

Removes a character from string.

Parameters
posPosition of the character to remove.
Returns
A reference to our current string.

Definition at line 2716 of file irrUString.h.

2717  {
2718  for (size_t i=pos; i<=used; ++i)
2719  {
2720  array[i] = array[i + 1];
2721  }
2722  --used;
2723  array[used] = 0;
2724  return *this;
2725  }
GLenum array

◆ find()

template<typename TAlloc = irrAllocator<uchar16_t>>
size_t irr::core::ustring16< TAlloc >::find ( const ustring16< TAlloc > &  str,
const size_t  start = 0 
) const
inline

Finds another ustring16 in this ustring16.

Parameters
strThe string to find.
startThe start position of the search.
Returns
Positions where the ustring16 has been found, or ustring::npos if not found.

Definition at line 1956 of file irrUString.h.

1957  {
1958  size_t my_size = size();
1959  size_t their_size = str.size();
1960 
1961  if (their_size == 0 || my_size - start < their_size)
1962  return ustring16<TAlloc>::npos;
1963 
1964  const_iterator i(*this, start);
1965 
1966  size_t pos = start;
1967  while (!i.atEnd())
1968  {
1969  const_iterator i2(i);
1970  const_iterator j(str, 0);
1971  uchar32_t t1 = (uchar32_t)*i2;
1972  uchar32_t t2 = (uchar32_t)*j;
1973  while (t1 == t2)
1974  {
1975  ++i2;
1976  ++j;
1977  if (j.atEnd())
1978  return pos;
1979  t1 = (uchar32_t)*i2;
1980  t2 = (uchar32_t)*j;
1981  }
1982  ++i;
1983  ++pos;
1984  }
1985 
1986  return ustring16<TAlloc>::npos;
1987  }
size_t size() const
Definition: irrUString.h:1291
static const size_t npos
Definition: irrUString.h:808
GLuint start
Definition: SDL_opengl.h:1571
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t1
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
u32 uchar32_t
Definition: irrUString.h:85

◆ find_raw()

template<typename TAlloc = irrAllocator<uchar16_t>>
size_t irr::core::ustring16< TAlloc >::find_raw ( const ustring16< TAlloc > &  str,
const size_t  start = 0 
) const
inline

Finds another ustring16 in this ustring16.

Parameters
strThe string to find.
startThe start position of the search.
Returns
Positions where the string has been found, or -1 if not found.

Definition at line 1994 of file irrUString.h.

1995  {
1996  const uchar16_t* data = str.c_str();
1997  if (data && *data)
1998  {
1999  size_t len = 0;
2000 
2001  while (data[len])
2002  ++len;
2003 
2004  if (len > used)
2005  return ustring16<TAlloc>::npos;
2006 
2007  for (size_t i = start; i <= used - len; ++i)
2008  {
2009  size_t j = 0;
2010 
2011  while(data[j] && array[i+j] == data[j])
2012  ++j;
2013 
2014  if (!data[j])
2015  return i;
2016  }
2017  }
2018 
2019  return ustring16<TAlloc>::npos;
2020  }
u16 uchar16_t
Definition: irrUString.h:86
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
static const size_t npos
Definition: irrUString.h:808
GLuint start
Definition: SDL_opengl.h:1571
GLenum GLsizei len
GLenum array

◆ findFirst()

template<typename TAlloc = irrAllocator<uchar16_t>>
size_t irr::core::ustring16< TAlloc >::findFirst ( uchar32_t  c) const
inline

Finds first occurrence of character.

Parameters
cThe character to search for.
Returns
Position where the character has been found, or ustring::npos if not found.

Definition at line 1773 of file irrUString.h.

1774  {
1775  const_iterator i(*this, 0);
1776 
1777  size_t pos = 0;
1778  while (!i.atEnd())
1779  {
1780  uchar32_t t = *i;
1781  if (c == t)
1782  return pos;
1783  ++pos;
1784  ++i;
1785  }
1786 
1787  return ustring16<TAlloc>::npos;
1788  }
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
static const size_t npos
Definition: irrUString.h:808
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ findFirstChar()

template<typename TAlloc = irrAllocator<uchar16_t>>
size_t irr::core::ustring16< TAlloc >::findFirstChar ( const uchar32_t *const  c,
size_t  count = 1 
) const
inline

Finds first occurrence of a character of a list.

Parameters
cA list of characters to find. For example if the method should find the first occurrence of 'a' or 'b', this parameter should be "ab".
countThe amount of characters in the list. Usually, this should be strlen(c).
Returns
Position where one of the characters has been found, or ustring::npos if not found.

Definition at line 1794 of file irrUString.h.

1795  {
1796  if (!c || !count)
1797  return ustring16<TAlloc>::npos;
1798 
1799  const_iterator i(*this, 0);
1800 
1801  size_t pos = 0;
1802  while (!i.atEnd())
1803  {
1804  uchar32_t t = *i;
1805  for (size_t j = 0; j < count; ++j)
1806  if (t == c[j])
1807  return pos;
1808  ++pos;
1809  ++i;
1810  }
1811 
1812  return ustring16<TAlloc>::npos;
1813  }
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
static const size_t npos
Definition: irrUString.h:808
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ findFirstCharNotInList()

template<typename TAlloc = irrAllocator<uchar16_t>>
size_t irr::core::ustring16< TAlloc >::findFirstCharNotInList ( const uchar32_t *const  c,
size_t  count = 1 
) const
inline

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

Parameters
cA list of characters to NOT find. For example if the method should find the first occurrence of a character not 'a' or 'b', this parameter should be "ab".
countThe amount of characters in the list. Usually, this should be strlen(c).
Returns
Position where the character has been found, or ustring::npos if not found.

Definition at line 1820 of file irrUString.h.

1821  {
1822  if (!c || !count)
1823  return ustring16<TAlloc>::npos;
1824 
1825  const_iterator i(*this, 0);
1826 
1827  size_t pos = 0;
1828  while (!i.atEnd())
1829  {
1830  uchar32_t t = *i;
1831  size_t j;
1832  for (j = 0; j < count; ++j)
1833  if (t == c[j])
1834  break;
1835 
1836  if (j == count)
1837  return pos;
1838  ++pos;
1839  ++i;
1840  }
1841 
1842  return ustring16<TAlloc>::npos;
1843  }
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
static const size_t npos
Definition: irrUString.h:808
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ findLast()

template<typename TAlloc = irrAllocator<uchar16_t>>
size_t irr::core::ustring16< TAlloc >::findLast ( uchar32_t  c,
size_t  start = ustring16<TAlloc>::npos 
) const
inline

Finds last occurrence of character.

Parameters
cThe character to search for.
startThe start position of the reverse search ( default = ustring::npos, on end ).
Returns
Position where the character has been found, or ustring::npos if not found.

Definition at line 1905 of file irrUString.h.

1906  {
1907  size_t s = size();
1909  start = s - 1;
1910 
1911  const_iterator i(*this, start);
1912  size_t pos = start;
1913  while (!i.atStart())
1914  {
1915  uchar32_t t = *i;
1916  if (t == c)
1917  return pos;
1918  --pos;
1919  --i;
1920  }
1921 
1922  return ustring16<TAlloc>::npos;
1923  }
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
size_t size() const
Definition: irrUString.h:1291
static const size_t npos
Definition: irrUString.h:808
GLuint start
Definition: SDL_opengl.h:1571
GLdouble s
Definition: SDL_opengl.h:2063
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ findLastChar()

template<typename TAlloc = irrAllocator<uchar16_t>>
size_t irr::core::ustring16< TAlloc >::findLastChar ( const uchar32_t *const  c,
size_t  count = 1 
) const
inline

Finds last occurrence of a character in a list.

Parameters
cA list of strings to find. For example if the method should find the last occurrence of 'a' or 'b', this parameter should be "ab".
countThe amount 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 1929 of file irrUString.h.

1930  {
1931  if (!c || !count)
1932  return ustring16<TAlloc>::npos;
1933 
1934  const_iterator i(end());
1935  --i;
1936 
1937  size_t pos = size();
1938  while (!i.atStart())
1939  {
1940  uchar32_t t = *i;
1941  for (size_t j = 0; j < count; ++j)
1942  if (t == c[j])
1943  return pos;
1944  --pos;
1945  --i;
1946  }
1947 
1948  return ustring16<TAlloc>::npos;
1949  }
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
size_t size() const
Definition: irrUString.h:1291
static const size_t npos
Definition: irrUString.h:808
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ findLastCharNotInList()

template<typename TAlloc = irrAllocator<uchar16_t>>
size_t irr::core::ustring16< TAlloc >::findLastCharNotInList ( const uchar32_t *const  c,
size_t  count = 1 
) const
inline

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

Parameters
cA list of characters to NOT find. For example if the method should find the first occurrence of a character not 'a' or 'b', this parameter should be "ab".
countThe amount of characters in the list. Usually, this should be strlen(c).
Returns
Position where the character has been found, or ustring::npos if not found.

Definition at line 1849 of file irrUString.h.

1850  {
1851  if (!c || !count)
1852  return ustring16<TAlloc>::npos;
1853 
1854  const_iterator i(end());
1855  --i;
1856 
1857  size_t pos = size();
1858  if (pos == 0)
1859  return ustring16<TAlloc>::npos;
1860  --pos;
1861 
1862  while (!i.atStart())
1863  {
1864  uchar32_t t = *i;
1865  size_t j;
1866  for (j = 0; j < count; ++j)
1867  if (t == c[j])
1868  break;
1869 
1870  if (j == count)
1871  return pos;
1872  --pos;
1873  --i;
1874  }
1875 
1876  return ustring16<TAlloc>::npos;
1877  }
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
size_t size() const
Definition: irrUString.h:1291
static const size_t npos
Definition: irrUString.h:808
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ findNext()

template<typename TAlloc = irrAllocator<uchar16_t>>
size_t irr::core::ustring16< TAlloc >::findNext ( uchar32_t  c,
size_t  startPos 
) const
inline

Finds next occurrence of character.

Parameters
cThe character to search for.
startPosThe position in the string to start searching.
Returns
Position where the character has been found, or ustring::npos if not found.

Definition at line 1883 of file irrUString.h.

1884  {
1885  const_iterator i(*this, startPos);
1886 
1887  size_t pos = startPos;
1888  while (!i.atEnd())
1889  {
1890  uchar32_t t = *i;
1891  if (t == c)
1892  return pos;
1893  ++pos;
1894  ++i;
1895  }
1896 
1897  return ustring16<TAlloc>::npos;
1898  }
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
static const size_t npos
Definition: irrUString.h:808
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ getEncoding()

template<typename TAlloc = irrAllocator<uchar16_t>>
const unicode::EUTF_ENCODE irr::core::ustring16< TAlloc >::getEncoding ( ) const
inline

Gets the encoding of the Unicode string this class contains.

Returns
An enum describing the current encoding of this string.

Definition at line 3240 of file irrUString.h.

3241  {
3242  return encoding;
3243  }

◆ getEndianness()

template<typename TAlloc = irrAllocator<uchar16_t>>
const unicode::EUTF_ENDIAN irr::core::ustring16< TAlloc >::getEndianness ( ) const
inline

Gets the endianness of the Unicode string this class contains.

Returns
An enum describing the endianness of this string.

Definition at line 3247 of file irrUString.h.

◆ insert() [1/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::insert ( uchar32_t  c,
size_t  pos 
)
inline

Inserts a character into the string.

Parameters
cThe character to insert.
posThe position to insert the character.
Returns
A reference to our current string.

Definition at line 2632 of file irrUString.h.

2633  {
2634  u8 len = (c > 0xFFFF ? 2 : 1);
2635 
2636  if (used + len >= allocated)
2637  reallocate(used + len);
2638 
2639  used += len;
2640 
2641  iterator iter(*this, pos);
2642  for (size_t i = used - 2; i > iter.getPos(); --i)
2643  array[i] = array[i - len];
2644 
2645  if (c > 0xFFFF)
2646  {
2647  // c will be multibyte, so split it up into a surrogate pair.
2648  uchar16_t x = static_cast<uchar16_t>(c);
2649  uchar16_t vh = UTF16_HI_SURROGATE | ((((c >> 16) & ((1 << 5) - 1)) - 1) << 6) | (x >> 10);
2650  uchar16_t vl = UTF16_LO_SURROGATE | (x & ((1 << 10) - 1));
2651  array[iter.getPos()] = vh;
2652  array[iter.getPos()+1] = vl;
2653  }
2654  else
2655  {
2656  array[iter.getPos()] = static_cast<uchar16_t>(c);
2657  }
2658  array[used] = 0;
2659  return *this;
2660  }
u16 uchar16_t
Definition: irrUString.h:86
ustring16< TAlloc >::_ustring16_iterator iterator
Definition: irrUString.h:797
GLenum GLsizei len
unsigned char u8
8 bit unsigned variable.
Definition: irrTypes.h:22
GLint GLint GLint GLint GLint x
Definition: SDL_opengl.h:1574
GLenum array
const GLubyte * c

◆ insert() [2/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::insert ( const ustring16< TAlloc > &  c,
size_t  pos 
)
inline

Inserts a string into the string.

Parameters
cThe string to insert.
posThe position to insert the string.
Returns
A reference to our current string.

Definition at line 2667 of file irrUString.h.

2668  {
2669  size_t len = c.size_raw();
2670  if (len == 0) return *this;
2671 
2672  if (used + len >= allocated)
2673  reallocate(used + len);
2674 
2675  used += len;
2676 
2677  iterator iter(*this, pos);
2678  for (size_t i = used - 2; i > iter.getPos() + len; --i)
2679  array[i] = array[i - len];
2680 
2681  const uchar16_t* s = c.c_str();
2682  for (size_t i = 0; i < len; ++i)
2683  {
2684  array[pos++] = *s;
2685  ++s;
2686  }
2687 
2688  array[used] = 0;
2689  return *this;
2690  }
u16 uchar16_t
Definition: irrUString.h:86
ustring16< TAlloc >::_ustring16_iterator iterator
Definition: irrUString.h:797
GLenum GLsizei len
GLdouble s
Definition: SDL_opengl.h:2063
GLenum array
const GLubyte * c

◆ insert_raw()

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::insert_raw ( uchar16_t  c,
size_t  pos 
)
inline

Inserts a character into the string.

Parameters
cThe character to insert.
posThe position to insert the character.
Returns
A reference to our current string.

Definition at line 2697 of file irrUString.h.

2698  {
2699  if (used + 1 >= allocated)
2700  reallocate(used + 1);
2701 
2702  ++used;
2703 
2704  for (size_t i = used - 1; i > pos; --i)
2705  array[i] = array[i - 1];
2706 
2707  array[pos] = c;
2708  array[used] = 0;
2709  return *this;
2710  }
GLenum array
const GLubyte * c

◆ lastChar()

template<typename TAlloc = irrAllocator<uchar16_t>>
uchar32_t irr::core::ustring16< TAlloc >::lastChar ( ) const
inline

Gets the last char of the ustring16, or 0.

Returns
The last char of the ustring16, or 0.

Definition at line 2504 of file irrUString.h.

2505  {
2506  if (used < 1)
2507  return 0;
2508 
2509  if (UTF16_IS_SURROGATE_LO(array[used-1]))
2510  {
2511  // Make sure we have a paired surrogate.
2512  if (used < 2)
2513  return 0;
2514 
2515  // Check for an invalid surrogate.
2516  if (!UTF16_IS_SURROGATE_HI(array[used-2]))
2517  return 0;
2518 
2519  // Convert the surrogate pair into a single UTF-32 character.
2520  return unicode::toUTF32(array[used-2], array[used-1]);
2521  }
2522  else
2523  {
2524  return array[used-1];
2525  }
2526  }
#define UTF16_IS_SURROGATE_LO(c)
Definition: irrUString.h:73
#define UTF16_IS_SURROGATE_HI(c)
Definition: irrUString.h:72
uchar32_t toUTF32(uchar16_t high, uchar16_t low)
Definition: irrUString.h:103
GLenum array

◆ loadDataStream()

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::loadDataStream ( const char *  data,
size_t  data_size 
)
inline

Loads an unknown stream of data. Will attempt to determine if the stream is unicode data. Useful for loading from files.

Parameters
dataThe data stream to load from.
data_sizeThe length of the data string.
Returns
A reference to our current string.

Definition at line 3207 of file irrUString.h.

3208  {
3209  // Clear our string.
3210  *this = "";
3211  if (!data)
3212  return *this;
3213 
3215  switch (e)
3216  {
3217  default:
3218  case unicode::EUTFE_UTF8:
3219  append((uchar8_t*)data, data_size);
3220  break;
3221 
3222  case unicode::EUTFE_UTF16:
3225  append((uchar16_t*)data, data_size / 2);
3226  break;
3227 
3228  case unicode::EUTFE_UTF32:
3231  append((uchar32_t*)data, data_size / 4);
3232  break;
3233  }
3234 
3235  return *this;
3236  }
u16 uchar16_t
Definition: irrUString.h:86
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: SDL_opengl.h:1974
EUTF_ENCODE
Unicode encoding type.
Definition: irrUString.h:149
EUTF_ENCODE determineUnicodeBOM(const char *data)
Definition: irrUString.h:221
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
u8 uchar8_t
Definition: irrUString.h:87
u32 uchar32_t
Definition: irrUString.h:85

◆ operator !=() [1/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
bool irr::core::ustring16< TAlloc >::operator != ( const uchar16_t *const  str) const
inline

Inequality operator.

Definition at line 1276 of file irrUString.h.

1277  {
1278  return !(*this == str);
1279  }

◆ operator !=() [2/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
bool irr::core::ustring16< TAlloc >::operator != ( const ustring16< TAlloc > &  other) const
inline

Inequality operator.

Definition at line 1283 of file irrUString.h.

1284  {
1285  return !(*this == other);
1286  }

◆ operator []() [1/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
access irr::core::ustring16< TAlloc >::operator [] ( const size_t  index)
inline

Direct access operator.

Definition at line 1218 of file irrUString.h.

1219  {
1220  _IRR_DEBUG_BREAK_IF(index>=size()) // bad index
1221  iterator iter(*this, index);
1222  return iter.operator*();
1223  }
ustring16< TAlloc >::_ustring16_iterator iterator
Definition: irrUString.h:797
size_t size() const
Definition: irrUString.h:1291
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
Definition: irrTypes.h:185
GLuint index

◆ operator []() [2/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
const access irr::core::ustring16< TAlloc >::operator [] ( const size_t  index) const
inline

Direct access operator.

Definition at line 1227 of file irrUString.h.

1228  {
1229  _IRR_DEBUG_BREAK_IF(index>=size()) // bad index
1230  const_iterator iter(*this, index);
1231  return iter.operator*();
1232  }
size_t size() const
Definition: irrUString.h:1291
#define _IRR_DEBUG_BREAK_IF(_CONDITION_)
define a break macro for debugging.
Definition: irrTypes.h:185
GLuint index
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798

◆ operator+=() [1/9]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator+= ( char  c)
inline

Appends a character to this ustring16.

Parameters
cCharacter to append.
Returns
A reference to our current string.

Definition at line 2064 of file irrUString.h.

2065  {
2066  append((uchar32_t)c);
2067  return *this;
2068  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ operator+=() [2/9]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator+= ( uchar32_t  c)
inline

Appends a character to this ustring16.

Parameters
cCharacter to append.
Returns
A reference to our current string.

Definition at line 2074 of file irrUString.h.

2075  {
2076  append(c);
2077  return *this;
2078  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
const GLubyte * c

◆ operator+=() [3/9]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator+= ( short  c)
inline

Appends a number to this ustring16.

Parameters
cNumber to append.
Returns
A reference to our current string.

Definition at line 2084 of file irrUString.h.

2085  {
2087  return *this;
2088  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
string< c8 > stringc
Typedef for character strings.
Definition: irrString.h:1458
const GLubyte * c

◆ operator+=() [4/9]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator+= ( unsigned short  c)
inline

Appends a number to this ustring16.

Parameters
cNumber to append.
Returns
A reference to our current string.

Definition at line 2094 of file irrUString.h.

2095  {
2097  return *this;
2098  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
string< c8 > stringc
Typedef for character strings.
Definition: irrString.h:1458
const GLubyte * c

◆ operator+=() [5/9]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator+= ( long  c)
inline

Appends a number to this ustring16.

Parameters
cNumber to append.
Returns
A reference to our current string.

Definition at line 2126 of file irrUString.h.

2127  {
2129  return *this;
2130  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
string< c8 > stringc
Typedef for character strings.
Definition: irrString.h:1458
const GLubyte * c

◆ operator+=() [6/9]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator+= ( unsigned long  c)
inline

Appends a number to this ustring16.

Parameters
cNumber to append.
Returns
A reference to our current string.

Definition at line 2136 of file irrUString.h.

2137  {
2139  return *this;
2140  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
string< c8 > stringc
Typedef for character strings.
Definition: irrString.h:1458
const GLubyte * c

◆ operator+=() [7/9]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator+= ( double  c)
inline

Appends a number to this ustring16.

Parameters
cNumber to append.
Returns
A reference to our current string.

Definition at line 2146 of file irrUString.h.

2147  {
2149  return *this;
2150  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
string< c8 > stringc
Typedef for character strings.
Definition: irrString.h:1458
const GLubyte * c

◆ operator+=() [8/9]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator+= ( const uchar16_t *const  c)
inline

Appends a char ustring16 to this ustring16.

Parameters
cChar ustring16 to append.
Returns
A reference to our current string.

Definition at line 2156 of file irrUString.h.

2157  {
2158  append(c);
2159  return *this;
2160  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
const GLubyte * c

◆ operator+=() [9/9]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator+= ( const ustring16< TAlloc > &  other)
inline

Appends a ustring16 to this ustring16.

Parameters
otherustring16 to append.
Returns
A reference to our current string.

Definition at line 2166 of file irrUString.h.

2167  {
2168  append(other);
2169  return *this;
2170  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360

◆ operator<()

template<typename TAlloc = irrAllocator<uchar16_t>>
bool irr::core::ustring16< TAlloc >::operator< ( const ustring16< TAlloc > &  other) const
inline

Is smaller comparator.

Definition at line 1262 of file irrUString.h.

1263  {
1264  for (size_t i=0; array[i] && other.array[i]; ++i)
1265  {
1266  if (array[i] == other.array[i])
1267  continue;
1268  return array[i] < other.array[i];
1269  }
1270 
1271  return used < other.used;
1272  }
GLenum array

◆ operator=() [1/7]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16& irr::core::ustring16< TAlloc >::operator= ( const ustring16< TAlloc > &  other)
inline

Assignment operator.

Definition at line 1074 of file irrUString.h.

1075  {
1076  if (this == &other)
1077  return *this;
1078 
1079  used = other.size_raw();
1080  if (used >= allocated)
1081  {
1082  allocator.deallocate(array); // delete [] array;
1083  allocated = used + 1;
1084  array = allocator.allocate(used + 1); //new u16[used];
1085  }
1086 
1087  const uchar16_t* p = other.c_str();
1088  for (size_t i=0; i<=used; ++i, ++p)
1089  array[i] = *p;
1090 
1091  array[used] = 0;
1092 
1093  // Validate our new UTF-16 string.
1094  validate();
1095 
1096  return *this;
1097  }
u16 uchar16_t
Definition: irrUString.h:86
GLfloat GLfloat p
ustring16< TAlloc > & validate()
Definition: irrUString.h:2468
GLenum array

◆ operator=() [2/7]

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

Assignment operator for other string types.

Definition at line 1123 of file irrUString.h.

1124  {
1125  *this = other.c_str();
1126  return *this;
1127  }

◆ operator=() [3/7]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator= ( const uchar8_t *const  c)
inline

Assignment operator for UTF-8 strings.

Append our string now.

Definition at line 1131 of file irrUString.h.

1132  {
1133  if (!array)
1134  {
1135  array = allocator.allocate(1); //new u16[1];
1136  allocated = 1;
1137  }
1138  used = 0;
1139  array[used] = 0x0;
1140  if (!c) return *this;
1141 
1143  append(c);
1144  return *this;
1145  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
GLenum array
const GLubyte * c

◆ operator=() [4/7]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator= ( const uchar16_t *const  c)
inline

Assignment operator for UTF-16 strings.

Append our string now.

Definition at line 1149 of file irrUString.h.

1150  {
1151  if (!array)
1152  {
1153  array = allocator.allocate(1); //new u16[1];
1154  allocated = 1;
1155  }
1156  used = 0;
1157  array[used] = 0x0;
1158  if (!c) return *this;
1159 
1161  append(c);
1162  return *this;
1163  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
GLenum array
const GLubyte * c

◆ operator=() [5/7]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator= ( const uchar32_t *const  c)
inline

Assignment operator for UTF-32 strings.

Append our string now.

Definition at line 1167 of file irrUString.h.

1168  {
1169  if (!array)
1170  {
1171  array = allocator.allocate(1); //new u16[1];
1172  allocated = 1;
1173  }
1174  used = 0;
1175  array[used] = 0x0;
1176  if (!c) return *this;
1177 
1179  append(c);
1180  return *this;
1181  }
ustring16< TAlloc > & append(uchar32_t character)
Definition: irrUString.h:1360
GLenum array
const GLubyte * c

◆ operator=() [6/7]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator= ( const wchar_t *const  c)
inline

Assignment operator for wchar_t strings.

Note that this assumes that a correct unicode string is stored in the wchar_t string. Since wchar_t changes depending on its platform, it could either be a UTF-8, -16, or -32 string. This function assumes you are storing the correct unicode encoding inside the wchar_t string.

Definition at line 1188 of file irrUString.h.

1189  {
1190  if (sizeof(wchar_t) == 4)
1191  *this = reinterpret_cast<const uchar32_t* const>(c);
1192  else if (sizeof(wchar_t) == 2)
1193  *this = reinterpret_cast<const uchar16_t* const>(c);
1194  else if (sizeof(wchar_t) == 1)
1195  *this = reinterpret_cast<const uchar8_t* const>(c);
1196 
1197  return *this;
1198  }
const GLubyte * c

◆ operator=() [7/7]

template<typename TAlloc = irrAllocator<uchar16_t>>
template<class B >
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::operator= ( const B *const  c)
inline

Assignment operator for other strings.

Note that this assumes that a correct unicode string is stored in the string.

Definition at line 1204 of file irrUString.h.

1205  {
1206  if (sizeof(B) == 4)
1207  *this = reinterpret_cast<const uchar32_t* const>(c);
1208  else if (sizeof(B) == 2)
1209  *this = reinterpret_cast<const uchar16_t* const>(c);
1210  else if (sizeof(B) == 1)
1211  *this = reinterpret_cast<const uchar8_t* const>(c);
1212 
1213  return *this;
1214  }
const GLubyte * c

◆ operator==() [1/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
bool irr::core::ustring16< TAlloc >::operator== ( const uchar16_t *const  str) const
inline

Equality operator.

Definition at line 1236 of file irrUString.h.

1237  {
1238  if (!str)
1239  return false;
1240 
1241  size_t i;
1242  for (i=0; array[i] && str[i]; ++i)
1243  if (array[i] != str[i])
1244  return false;
1245 
1246  return !array[i] && !str[i];
1247  }
GLenum array

◆ operator==() [2/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
bool irr::core::ustring16< TAlloc >::operator== ( const ustring16< TAlloc > &  other) const
inline

Equality operator.

Definition at line 1251 of file irrUString.h.

1252  {
1253  for (size_t i=0; array[i] && other.array[i]; ++i)
1254  if (array[i] != other.array[i])
1255  return false;
1256 
1257  return used == other.used;
1258  }
GLenum array

◆ remove() [1/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::remove ( uchar32_t  c)
inline

Removes characters from a ustring16..

Parameters
cThe character to remove.
Returns
A reference to our current string.

Definition at line 2306 of file irrUString.h.

2307  {
2308  size_t pos = 0;
2309  size_t found = 0;
2310  size_t len = (c > 0xFFFF ? 2 : 1); // Remove characters equal to the size of c as a UTF-16 character.
2311  for (size_t i=0; i<=used; ++i)
2312  {
2313  uchar32_t uc32 = 0;
2314  if (!UTF16_IS_SURROGATE_HI(array[i]))
2315  uc32 |= array[i];
2316  else if (i + 1 <= used)
2317  {
2318  // Convert the surrogate pair into a single UTF-32 character.
2319  uc32 = unicode::toUTF32(array[i], array[i + 1]);
2320  }
2321  size_t len2 = (uc32 > 0xFFFF ? 2 : 1);
2322 
2323  if (uc32 == c)
2324  {
2325  found += len;
2326  continue;
2327  }
2328 
2329  array[pos++] = array[i];
2330  if (len2 == 2)
2331  array[pos++] = array[++i];
2332  }
2333  used -= found;
2334  array[used] = 0;
2335  return *this;
2336  }
#define UTF16_IS_SURROGATE_HI(c)
Definition: irrUString.h:72
GLenum GLsizei len
uchar32_t toUTF32(uchar16_t high, uchar16_t low)
Definition: irrUString.h:103
GLenum array
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ remove() [2/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::remove ( const ustring16< TAlloc > &  toRemove)
inline

Removes a ustring16 from the ustring16.

Parameters
toRemoveThe string to remove.
Returns
A reference to our current string.

Definition at line 2342 of file irrUString.h.

2343  {
2344  size_t size = toRemove.size_raw();
2345  if (size == 0) return *this;
2346 
2347  const uchar16_t* tra = toRemove.c_str();
2348  size_t pos = 0;
2349  size_t found = 0;
2350  for (size_t i=0; i<=used; ++i)
2351  {
2352  size_t j = 0;
2353  while (j < size)
2354  {
2355  if (array[i + j] != tra[j])
2356  break;
2357  ++j;
2358  }
2359  if (j == size)
2360  {
2361  found += size;
2362  i += size - 1;
2363  continue;
2364  }
2365 
2366  array[pos++] = array[i];
2367  }
2368  used -= found;
2369  array[used] = 0;
2370  return *this;
2371  }
u16 uchar16_t
Definition: irrUString.h:86
size_t size() const
Definition: irrUString.h:1291
GLsizeiptr size
GLenum array

◆ removeChars()

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::removeChars ( const ustring16< TAlloc > &  characters)
inline

Removes characters from the ustring16.

Parameters
charactersThe characters to remove.
Returns
A reference to our current string.

Definition at line 2377 of file irrUString.h.

2378  {
2379  if (characters.size_raw() == 0)
2380  return *this;
2381 
2382  size_t pos = 0;
2383  size_t found = 0;
2384  const_iterator iter(characters);
2385  for (size_t i=0; i<=used; ++i)
2386  {
2387  uchar32_t uc32 = 0;
2388  if (!UTF16_IS_SURROGATE_HI(array[i]))
2389  uc32 |= array[i];
2390  else if (i + 1 <= used)
2391  {
2392  // Convert the surrogate pair into a single UTF-32 character.
2393  uc32 = unicode::toUTF32(array[i], array[i+1]);
2394  }
2395  size_t len2 = (uc32 > 0xFFFF ? 2 : 1);
2396 
2397  bool cont = false;
2398  iter.toStart();
2399  while (!iter.atEnd())
2400  {
2401  uchar32_t c = *iter;
2402  if (uc32 == c)
2403  {
2404  found += (c > 0xFFFF ? 2 : 1); // Remove characters equal to the size of c as a UTF-16 character.
2405  ++i;
2406  cont = true;
2407  break;
2408  }
2409  ++iter;
2410  }
2411  if (cont) continue;
2412 
2413  array[pos++] = array[i];
2414  if (len2 == 2)
2415  array[pos++] = array[++i];
2416  }
2417  used -= found;
2418  array[used] = 0;
2419  return *this;
2420  }
#define UTF16_IS_SURROGATE_HI(c)
Definition: irrUString.h:72
uchar32_t toUTF32(uchar16_t high, uchar16_t low)
Definition: irrUString.h:103
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
GLenum array
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ replace() [1/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::replace ( uchar32_t  toReplace,
uchar32_t  replaceWith 
)
inline

Replaces all characters of a given type with another one.

Parameters
toReplaceCharacter to replace.
replaceWithCharacter replacing the old one.
Returns
A reference to our current string.

Definition at line 2177 of file irrUString.h.

2178  {
2179  iterator i(*this, 0);
2180  while (!i.atEnd())
2181  {
2182  typename ustring16<TAlloc>::access a = *i;
2183  if ((uchar32_t)a == toReplace)
2184  a = replaceWith;
2185  ++i;
2186  }
2187  return *this;
2188  }
ustring16< TAlloc >::_ustring16_iterator iterator
Definition: irrUString.h:797
ustring16< TAlloc >::_ustring16_iterator_access access
Definition: irrUString.h:435
GLboolean GLboolean GLboolean GLboolean a
u32 uchar32_t
Definition: irrUString.h:85

◆ replace() [2/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::replace ( const ustring16< TAlloc > &  toReplace,
const ustring16< TAlloc > &  replaceWith 
)
inline

Replaces all instances of a string with another one.

Parameters
toReplaceThe string to replace.
replaceWithThe string replacing the old one.
Returns
A reference to our current string.

Definition at line 2195 of file irrUString.h.

2196  {
2197  if (toReplace.size() == 0)
2198  return *this;
2199 
2200  const uchar16_t* other = toReplace.c_str();
2201  const uchar16_t* replace = replaceWith.c_str();
2202  const size_t other_size = toReplace.size_raw();
2203  const size_t replace_size = replaceWith.size_raw();
2204 
2205  // A character for character replace. The string will not shrink or grow.
2206  if (replace_size == other_size)
2207  {
2208  size_t pos = 0;
2209  while ((pos = find_raw(other, pos)) != ustring16<TAlloc>::npos)
2210  {
2211  for (size_t i = 0; i < replace_size; ++i)
2212  array[pos + i] = replace[i];
2213  ++pos;
2214  }
2215  return *this;
2216  }
2217 
2218  // We are going to be removing some characters. The string will shrink.
2219  if (replace_size < other_size)
2220  {
2221  size_t i = 0;
2222  for (size_t pos = 0; pos <= used; ++i, ++pos)
2223  {
2224  // Is this potentially a match?
2225  if (array[pos] == *other)
2226  {
2227  // Check to see if we have a match.
2228  size_t j;
2229  for (j = 0; j < other_size; ++j)
2230  {
2231  if (array[pos + j] != other[j])
2232  break;
2233  }
2234 
2235  // If we have a match, replace characters.
2236  if (j == other_size)
2237  {
2238  for (j = 0; j < replace_size; ++j)
2239  array[i + j] = replace[j];
2240  i += replace_size - 1;
2241  pos += other_size - 1;
2242  continue;
2243  }
2244  }
2245 
2246  // No match found, just copy characters.
2247  array[i - 1] = array[pos];
2248  }
2249  array[i] = 0;
2250  used = i;
2251 
2252  return *this;
2253  }
2254 
2255  // Determine the delta.
2256  size_t delta = replace_size - other_size;
2257 
2258  // We are going to be adding characters, so the string size will increase.
2259  // Count the number of times toReplace exists in the string so we can allocate the new size.
2260  size_t find_count = 0;
2261  size_t pos = 0;
2262  while ((pos = find_raw(other, pos)) != ustring16<TAlloc>::npos)
2263  {
2264  ++find_count;
2265  ++pos;
2266  }
2267 
2268  // Re-allocate the string now, if needed.
2269  size_t len = delta * find_count;
2270  if (used + len >= allocated)
2271  reallocate(used + len);
2272 
2273  // Start replacing.
2274  pos = 0;
2275  while ((pos = find_raw(other, pos)) != ustring16<TAlloc>::npos)
2276  {
2277  uchar16_t* start = array + pos + other_size - 1;
2278  uchar16_t* ptr = array + used;
2279  uchar16_t* end = array + used + delta;
2280 
2281  // Shift characters to make room for the string.
2282  while (ptr != start)
2283  {
2284  *end = *ptr;
2285  --ptr;
2286  --end;
2287  }
2288 
2289  // Add the new string now.
2290  for (size_t i = 0; i < replace_size; ++i)
2291  array[pos + i] = replace[i];
2292 
2293  pos += replace_size;
2294  used += delta;
2295  }
2296 
2297  // Terminate the string and return ourself.
2298  array[used] = 0;
2299  return *this;
2300  }
u16 uchar16_t
Definition: irrUString.h:86
size_t find_raw(const ustring16< TAlloc > &str, const size_t start=0) const
Definition: irrUString.h:1994
GLuint GLuint end
Definition: SDL_opengl.h:1571
static const size_t npos
Definition: irrUString.h:808
GLuint start
Definition: SDL_opengl.h:1571
GLenum GLsizei len
ustring16< TAlloc > & replace(uchar32_t toReplace, uchar32_t replaceWith)
Definition: irrUString.h:2177
GLenum array

◆ replace_raw()

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::replace_raw ( uchar16_t  c,
size_t  pos 
)
inline

Replaces a character in the string.

Parameters
cThe new character.
posThe position of the character to replace.
Returns
A reference to our current string.

Definition at line 2732 of file irrUString.h.

2733  {
2734  array[pos] = c;
2735  return *this;
2736  }
GLenum array
const GLubyte * c

◆ reserve()

template<typename TAlloc = irrAllocator<uchar16_t>>
void irr::core::ustring16< TAlloc >::reserve ( size_t  count)
inline

Reserves some memory.

Parameters
countThe amount of characters to reserve.

Definition at line 1761 of file irrUString.h.

1762  {
1763  if (count < allocated)
1764  return;
1765 
1766  reallocate(count);
1767  }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571

◆ size()

template<typename TAlloc = irrAllocator<uchar16_t>>
size_t irr::core::ustring16< TAlloc >::size ( ) const
inline

Returns the length of a ustring16 in full characters.

Returns
Length of a ustring16 in full characters.

Definition at line 1291 of file irrUString.h.

1292  {
1293  const_iterator i(*this, 0);
1294  size_t pos = 0;
1295  while (!i.atEnd())
1296  {
1297  ++i;
1298  ++pos;
1299  }
1300  return pos;
1301  }
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798

◆ size_raw()

template<typename TAlloc = irrAllocator<uchar16_t>>
size_t irr::core::ustring16< TAlloc >::size_raw ( ) const
inline

Returns the raw number of UTF-16 code points in the string which includes the individual surrogates.

Returns
The raw number of UTF-16 code points, excluding the trialing NUL.

Definition at line 2622 of file irrUString.h.

2623  {
2624  return used;
2625  }

◆ split() [1/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
template<class container >
size_t irr::core::ustring16< TAlloc >::split ( container &  ret,
const uchar32_t *const  c,
size_t  count = 1,
bool  ignoreEmptyTokens = true,
bool  keepSeparators = false 
) const
inline

Split the ustring16 into parts.

This method will split a ustring16 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
cC-style ustring16 of delimiter characters
countNumber of delimiter characters
ignoreEmptyTokensFlag to avoid empty substrings in the result container. If two delimiters occur without a character in between, an empty substring would be placed in the result. If this flag is set, only non-empty strings are stored.
keepSeparatorsFlag which allows to add the separator to the result ustring16. If this flag is true, the concatenation of the substrings results in the original ustring16. Otherwise, only the characters between the delimiters are returned.
Returns
The number of resulting substrings

Definition at line 2548 of file irrUString.h.

2549  {
2550  if (!c)
2551  return 0;
2552 
2553  const_iterator i(*this);
2554  const size_t oldSize=ret.size();
2555  size_t pos = 0;
2556  size_t lastpos = 0;
2557  size_t lastpospos = 0;
2558  bool lastWasSeparator = false;
2559  while (!i.atEnd())
2560  {
2561  uchar32_t ch = *i;
2562  bool foundSeparator = false;
2563  for (size_t j=0; j<count; ++j)
2564  {
2565  if (ch == c[j])
2566  {
2567  if ((!ignoreEmptyTokens || pos - lastpos != 0) &&
2568  !lastWasSeparator)
2569  ret.push_back(ustring16<TAlloc>(&array[lastpospos], pos - lastpos));
2570  foundSeparator = true;
2571  lastpos = (keepSeparators ? pos : pos + 1);
2572  lastpospos = (keepSeparators ? i.getPos() : i.getPos() + 1);
2573  break;
2574  }
2575  }
2576  lastWasSeparator = foundSeparator;
2577  ++pos;
2578  ++i;
2579  }
2580  size_t s = size() + 1;
2581  if (s > lastpos)
2582  ret.push_back(ustring16<TAlloc>(&array[lastpospos], s - lastpos));
2583  return ret.size()-oldSize;
2584  }
GLuint GLuint GLsizei count
Definition: SDL_opengl.h:1571
size_t size() const
Definition: irrUString.h:1291
GLdouble s
Definition: SDL_opengl.h:2063
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
GLenum array
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ split() [2/2]

template<typename TAlloc = irrAllocator<uchar16_t>>
template<class container >
size_t irr::core::ustring16< TAlloc >::split ( container &  ret,
const ustring16< TAlloc > &  c,
bool  ignoreEmptyTokens = true,
bool  keepSeparators = false 
) const
inline

Split the ustring16 into parts.

This method will split a ustring16 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
cA unicode string of delimiter characters
ignoreEmptyTokensFlag to avoid empty substrings in the result container. If two delimiters occur without a character in between, an empty substring would be placed in the result. If this flag is set, only non-empty strings are stored.
keepSeparatorsFlag which allows to add the separator to the result ustring16. If this flag is true, the concatenation of the substrings results in the original ustring16. Otherwise, only the characters between the delimiters are returned.
Returns
The number of resulting substrings

Definition at line 2605 of file irrUString.h.

2606  {
2607  core::array<uchar32_t> v = c.toUTF32();
2608  return split(ret, v.pointer(), v.size(), ignoreEmptyTokens, keepSeparators);
2609  }
const GLdouble * v
Definition: SDL_opengl.h:2064
size_t split(container &ret, const uchar32_t *const c, size_t count=1, bool ignoreEmptyTokens=true, bool keepSeparators=false) const
Split the ustring16 into parts.
Definition: irrUString.h:2548
const GLubyte * c

◆ subString()

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc> irr::core::ustring16< TAlloc >::subString ( size_t  begin,
size_t  length 
) const
inline

Returns a substring.

Parameters
beginStart of substring.
lengthLength of substring.
Returns
A reference to our current string.

Definition at line 2027 of file irrUString.h.

2028  {
2029  size_t len = size();
2030 
2031  // Check our inputs to see if we can exit early.
2032  if ((length == 0) || (begin>=len))
2033  return ustring16<TAlloc>("");
2034 
2035  // Clamp to maximum value.
2037  length = len - begin;
2038 
2039  // TODO: Check for near overflow values.
2040  //if (begin > ustring16<TAlloc>::npos - length)
2041 
2042  // Clamp to the string length.
2043  if ((length + begin) > len)
2044  length = len - begin;
2045 
2046  ustring16<TAlloc> o;
2047  o.reserve((length+1) * 2);
2048 
2049  const_iterator i(*this, begin);
2050  while (!i.atEnd() && length)
2051  {
2052  o.append(*i);
2053  ++i;
2054  --length;
2055  }
2056 
2057  return o;
2058  }
size_t size() const
Definition: irrUString.h:1291
static const size_t npos
Definition: irrUString.h:808
GLenum GLsizei len
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
GLuint GLsizei GLsizei * length

◆ toPATH_s()

template<typename TAlloc = irrAllocator<uchar16_t>>
io::path irr::core::ustring16< TAlloc >::toPATH_s ( const unicode::EUTF_ENDIAN  endian = unicode::EUTFEE_NATIVE,
const bool  addBOM = false 
) const
inline

Converts the string to a properly encoded io::path string.

Parameters
endianThe desired endianness of the string.
addBOMIf true, the proper unicode byte-order mark will be prefixed to the string.
Returns
An io::path string containing the properly encoded string.

Definition at line 3193 of file irrUString.h.

3194  {
3195 #if defined(_IRR_WCHAR_FILESYSTEM)
3196  return toWCHAR_s(endian, addBOM);
3197 #else
3198  return toUTF8_s(addBOM);
3199 #endif
3200  }
core::string< uchar8_t > toUTF8_s(const bool addBOM=false) const
Definition: irrUString.h:2799
core::string< wchar_t > toWCHAR_s(const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
Converts the string to a wchar_t encoded string.
Definition: irrUString.h:3108

◆ toUTF16()

template<typename TAlloc = irrAllocator<uchar16_t>>
core::array<uchar16_t> irr::core::ustring16< TAlloc >::toUTF16 ( const unicode::EUTF_ENDIAN  endian = unicode::EUTFEE_NATIVE,
const bool  addBOM = false 
) const
inline

Converts the string to a UTF-16 encoded string array. Unfortunately, no toUTF16_s() version exists due to limitations with Irrlicht's string class.

Parameters
endianThe desired endianness of the string.
addBOMIf true, the proper unicode byte-order mark will be prefixed to the string.
Returns
An array containing the UTF-16 encoded string.

Definition at line 2956 of file irrUString.h.

2957  {
2958  core::array<uchar16_t> ret(used + (addBOM ? unicode::BOM_UTF16_LEN : 0) + 1);
2959  uchar16_t* ptr = ret.pointer();
2960 
2961  // Add the BOM if specified.
2962  if (addBOM)
2963  {
2964  if (endian == unicode::EUTFEE_NATIVE)
2965  *ptr = unicode::BOM;
2966  else if (endian == unicode::EUTFEE_LITTLE)
2967  {
2968  uchar8_t* ptr8 = reinterpret_cast<uchar8_t*>(ptr);
2969  *ptr8++ = unicode::BOM_ENCODE_UTF16_LE[0];
2970  *ptr8 = unicode::BOM_ENCODE_UTF16_LE[1];
2971  }
2972  else
2973  {
2974  uchar8_t* ptr8 = reinterpret_cast<uchar8_t*>(ptr);
2975  *ptr8++ = unicode::BOM_ENCODE_UTF16_BE[0];
2976  *ptr8 = unicode::BOM_ENCODE_UTF16_BE[1];
2977  }
2978  ++ptr;
2979  }
2980 
2981  memcpy((void*)ptr, (void*)array, used * sizeof(uchar16_t));
2982  if (endian != unicode::EUTFEE_NATIVE && getEndianness() != endian)
2983  {
2984  for (size_t i = 0; i <= used; ++i)
2985  *ptr++ = unicode::swapEndian16(*ptr);
2986  }
2987  ret.set_used(used + (addBOM ? unicode::BOM_UTF16_LEN : 0));
2988  ret.push_back(0);
2989  return ret;
2990  }
u16 uchar16_t
Definition: irrUString.h:86
const u8 BOM_UTF16_LEN
Definition: irrUString.h:133
const unicode::EUTF_ENDIAN getEndianness() const
Definition: irrUString.h:3247
const u16 BOM
The Unicode byte order mark.
Definition: irrUString.h:129
const u8 BOM_ENCODE_UTF16_BE[2]
Definition: irrUString.h:138
uchar16_t swapEndian16(const uchar16_t &c)
Definition: irrUString.h:113
u8 uchar8_t
Definition: irrUString.h:87
GLenum array
const u8 BOM_ENCODE_UTF16_LE[2]
Definition: irrUString.h:139

◆ toUTF32()

template<typename TAlloc = irrAllocator<uchar16_t>>
core::array<uchar32_t> irr::core::ustring16< TAlloc >::toUTF32 ( const unicode::EUTF_ENDIAN  endian = unicode::EUTFEE_NATIVE,
const bool  addBOM = false 
) const
inline

Converts the string to a UTF-32 encoded string array. Unfortunately, no toUTF32_s() version exists due to limitations with Irrlicht's string class.

Parameters
endianThe desired endianness of the string.
addBOMIf true, the proper unicode byte-order mark will be prefixed to the string.
Returns
An array containing the UTF-32 encoded string.

Definition at line 3053 of file irrUString.h.

3054  {
3055  core::array<uchar32_t> ret(size() + (addBOM ? unicode::BOM_UTF32_LEN : 0) + 1);
3056  const_iterator iter(*this, 0);
3057 
3058  // Add the BOM if specified.
3059  if (addBOM)
3060  {
3061  if (endian == unicode::EUTFEE_NATIVE)
3062  ret.push_back(unicode::BOM);
3063  else
3064  {
3065  union
3066  {
3067  uchar32_t full;
3068  u8 chunk[4];
3069  } t;
3070 
3071  if (endian == unicode::EUTFEE_LITTLE)
3072  {
3073  t.chunk[0] = unicode::BOM_ENCODE_UTF32_LE[0];
3074  t.chunk[1] = unicode::BOM_ENCODE_UTF32_LE[1];
3075  t.chunk[2] = unicode::BOM_ENCODE_UTF32_LE[2];
3076  t.chunk[3] = unicode::BOM_ENCODE_UTF32_LE[3];
3077  }
3078  else
3079  {
3080  t.chunk[0] = unicode::BOM_ENCODE_UTF32_BE[0];
3081  t.chunk[1] = unicode::BOM_ENCODE_UTF32_BE[1];
3082  t.chunk[2] = unicode::BOM_ENCODE_UTF32_BE[2];
3083  t.chunk[3] = unicode::BOM_ENCODE_UTF32_BE[3];
3084  }
3085  ret.push_back(t.full);
3086  }
3087  }
3088  ret.push_back(0);
3089 
3090  while (!iter.atEnd())
3091  {
3092  uchar32_t c = *iter;
3093  if (endian != unicode::EUTFEE_NATIVE && getEndianness() != endian)
3095  ret.push_back(c);
3096  ++iter;
3097  }
3098  return ret;
3099  }
GLdouble GLdouble t
Definition: SDL_opengl.h:2071
const unicode::EUTF_ENDIAN getEndianness() const
Definition: irrUString.h:3247
size_t size() const
Definition: irrUString.h:1291
const u16 BOM
The Unicode byte order mark.
Definition: irrUString.h:129
uchar32_t swapEndian32(const uchar32_t &c)
Definition: irrUString.h:120
unsigned char u8
8 bit unsigned variable.
Definition: irrTypes.h:22
const u8 BOM_ENCODE_UTF32_LE[4]
Definition: irrUString.h:141
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
const u8 BOM_ENCODE_UTF32_BE[4]
Definition: irrUString.h:140
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85
const u8 BOM_UTF32_LEN
Definition: irrUString.h:134

◆ toUTF8()

template<typename TAlloc = irrAllocator<uchar16_t>>
core::array<uchar8_t> irr::core::ustring16< TAlloc >::toUTF8 ( const bool  addBOM = false) const
inline

Converts the string to a UTF-8 encoded string array.

Parameters
addBOMIf true, the proper unicode byte-order mark will be prefixed to the string.
Returns
An array containing the UTF-8 encoded string.

Definition at line 2856 of file irrUString.h.

2857  {
2858  core::array<uchar8_t> ret(used * 4 + (addBOM ? unicode::BOM_UTF8_LEN : 0) + 1);
2859  const_iterator iter(*this, 0);
2860 
2861  // Add the byte order mark if the user wants it.
2862  if (addBOM)
2863  {
2864  ret.push_back(unicode::BOM_ENCODE_UTF8[0]);
2865  ret.push_back(unicode::BOM_ENCODE_UTF8[1]);
2866  ret.push_back(unicode::BOM_ENCODE_UTF8[2]);
2867  }
2868 
2869  while (!iter.atEnd())
2870  {
2871  uchar32_t c = *iter;
2872  if (c > 0xFFFF)
2873  { // 4 bytes
2874  uchar8_t b1 = (0x1E << 3) | ((c >> 18) & 0x7);
2875  uchar8_t b2 = (0x2 << 6) | ((c >> 12) & 0x3F);
2876  uchar8_t b3 = (0x2 << 6) | ((c >> 6) & 0x3F);
2877  uchar8_t b4 = (0x2 << 6) | (c & 0x3F);
2878  ret.push_back(b1);
2879  ret.push_back(b2);
2880  ret.push_back(b3);
2881  ret.push_back(b4);
2882  }
2883  else if (c > 0x7FF)
2884  { // 3 bytes
2885  uchar8_t b1 = (0xE << 4) | ((c >> 12) & 0xF);
2886  uchar8_t b2 = (0x2 << 6) | ((c >> 6) & 0x3F);
2887  uchar8_t b3 = (0x2 << 6) | (c & 0x3F);
2888  ret.push_back(b1);
2889  ret.push_back(b2);
2890  ret.push_back(b3);
2891  }
2892  else if (c > 0x7F)
2893  { // 2 bytes
2894  uchar8_t b1 = (0x6 << 5) | ((c >> 6) & 0x1F);
2895  uchar8_t b2 = (0x2 << 6) | (c & 0x3F);
2896  ret.push_back(b1);
2897  ret.push_back(b2);
2898  }
2899  else
2900  { // 1 byte
2901  ret.push_back(static_cast<uchar8_t>(c));
2902  }
2903  ++iter;
2904  }
2905  ret.push_back(0);
2906  return ret;
2907  }
const u8 BOM_ENCODE_UTF8[3]
Unicode byte order marks for file operations.
Definition: irrUString.h:137
u8 uchar8_t
Definition: irrUString.h:87
const u8 BOM_UTF8_LEN
The size of the Unicode byte order mark in terms of the Unicode character size.
Definition: irrUString.h:132
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ toUTF8_s()

template<typename TAlloc = irrAllocator<uchar16_t>>
core::string<uchar8_t> irr::core::ustring16< TAlloc >::toUTF8_s ( const bool  addBOM = false) const
inline

Converts the string to a UTF-8 encoded string.

Parameters
addBOMIf true, the proper unicode byte-order mark will be prefixed to the string.
Returns
A string containing the UTF-8 encoded string.

Definition at line 2799 of file irrUString.h.

2800  {
2801  core::string<uchar8_t> ret;
2802  ret.reserve(used * 4 + (addBOM ? unicode::BOM_UTF8_LEN : 0) + 1);
2803  const_iterator iter(*this, 0);
2804 
2805  // Add the byte order mark if the user wants it.
2806  if (addBOM)
2807  {
2808  ret.append(unicode::BOM_ENCODE_UTF8[0]);
2809  ret.append(unicode::BOM_ENCODE_UTF8[1]);
2810  ret.append(unicode::BOM_ENCODE_UTF8[2]);
2811  }
2812 
2813  while (!iter.atEnd())
2814  {
2815  uchar32_t c = *iter;
2816  if (c > 0xFFFF)
2817  { // 4 bytes
2818  uchar8_t b1 = (0x1E << 3) | ((c >> 18) & 0x7);
2819  uchar8_t b2 = (0x2 << 6) | ((c >> 12) & 0x3F);
2820  uchar8_t b3 = (0x2 << 6) | ((c >> 6) & 0x3F);
2821  uchar8_t b4 = (0x2 << 6) | (c & 0x3F);
2822  ret.append(b1);
2823  ret.append(b2);
2824  ret.append(b3);
2825  ret.append(b4);
2826  }
2827  else if (c > 0x7FF)
2828  { // 3 bytes
2829  uchar8_t b1 = (0xE << 4) | ((c >> 12) & 0xF);
2830  uchar8_t b2 = (0x2 << 6) | ((c >> 6) & 0x3F);
2831  uchar8_t b3 = (0x2 << 6) | (c & 0x3F);
2832  ret.append(b1);
2833  ret.append(b2);
2834  ret.append(b3);
2835  }
2836  else if (c > 0x7F)
2837  { // 2 bytes
2838  uchar8_t b1 = (0x6 << 5) | ((c >> 6) & 0x1F);
2839  uchar8_t b2 = (0x2 << 6) | (c & 0x3F);
2840  ret.append(b1);
2841  ret.append(b2);
2842  }
2843  else
2844  { // 1 byte
2845  ret.append(static_cast<uchar8_t>(c));
2846  }
2847  ++iter;
2848  }
2849  return ret;
2850  }
const u8 BOM_ENCODE_UTF8[3]
Unicode byte order marks for file operations.
Definition: irrUString.h:137
u8 uchar8_t
Definition: irrUString.h:87
const u8 BOM_UTF8_LEN
The size of the Unicode byte order mark in terms of the Unicode character size.
Definition: irrUString.h:132
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:798
const GLubyte * c
u32 uchar32_t
Definition: irrUString.h:85

◆ toWCHAR()

template<typename TAlloc = irrAllocator<uchar16_t>>
core::array<wchar_t> irr::core::ustring16< TAlloc >::toWCHAR ( const unicode::EUTF_ENDIAN  endian = unicode::EUTFEE_NATIVE,
const bool  addBOM = false 
) const
inline

Converts the string to a wchar_t encoded string array.

The size of a wchar_t changes depending on the platform. This function will store a correct UTF-8, -16, or -32 encoded string depending on the size of a wchar_t.

Parameters
endianThe desired endianness of the string.
addBOMIf true, the proper unicode byte-order mark will be prefixed to the string.
Returns
An array containing the wchar_t encoded string.

Definition at line 3148 of file irrUString.h.

3149  {
3150  if (sizeof(wchar_t) == 4)
3151  {
3152  core::array<uchar32_t> a(toUTF32(endian, addBOM));
3153  core::array<wchar_t> ret(a.size());
3154  ret.set_used(a.size());
3155  memcpy((void*)ret.pointer(), (void*)a.pointer(), a.size() * sizeof(uchar32_t));
3156  return ret;
3157  }
3158  if (sizeof(wchar_t) == 2)
3159  {
3160  if (endian == unicode::EUTFEE_NATIVE && addBOM == false)
3161  {
3162  core::array<wchar_t> ret(used);
3163  ret.set_used(used);
3164  memcpy((void*)ret.pointer(), (void*)array, used * sizeof(uchar16_t));
3165  return ret;
3166  }
3167  else
3168  {
3169  core::array<uchar16_t> a(toUTF16(endian, addBOM));
3170  core::array<wchar_t> ret(a.size());
3171  ret.set_used(a.size());
3172  memcpy((void*)ret.pointer(), (void*)a.pointer(), a.size() * sizeof(uchar16_t));
3173  return ret;
3174  }
3175  }
3176  if (sizeof(wchar_t) == 1)
3177  {
3178  core::array<uchar8_t> a(toUTF8(addBOM));
3179  core::array<wchar_t> ret(a.size());
3180  ret.set_used(a.size());
3181  memcpy((void*)ret.pointer(), (void*)a.pointer(), a.size() * sizeof(uchar8_t));
3182  return ret;
3183  }
3184 
3185  // Shouldn't happen.
3186  return core::array<wchar_t>();
3187  }
u16 uchar16_t
Definition: irrUString.h:86
core::array< uchar16_t > toUTF16(const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
Definition: irrUString.h:2956
core::array< uchar8_t > toUTF8(const bool addBOM=false) const
Definition: irrUString.h:2856
core::array< uchar32_t > toUTF32(const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
Definition: irrUString.h:3053
u8 uchar8_t
Definition: irrUString.h:87
GLenum array
GLboolean GLboolean GLboolean GLboolean a
u32 uchar32_t
Definition: irrUString.h:85

◆ toWCHAR_s()

template<typename TAlloc = irrAllocator<uchar16_t>>
core::string<wchar_t> irr::core::ustring16< TAlloc >::toWCHAR_s ( const unicode::EUTF_ENDIAN  endian = unicode::EUTFEE_NATIVE,
const bool  addBOM = false 
) const
inline

Converts the string to a wchar_t encoded string.

The size of a wchar_t changes depending on the platform. This function will store a correct UTF-8, -16, or -32 encoded string depending on the size of a wchar_t.

Parameters
endianThe desired endianness of the string.
addBOMIf true, the proper unicode byte-order mark will be prefixed to the string.
Returns
A string containing the wchar_t encoded string.

Definition at line 3108 of file irrUString.h.

3109  {
3110  if (sizeof(wchar_t) == 4)
3111  {
3112  core::array<uchar32_t> a(toUTF32(endian, addBOM));
3113  core::stringw ret(a.pointer());
3114  return ret;
3115  }
3116  else if (sizeof(wchar_t) == 2)
3117  {
3118  if (endian == unicode::EUTFEE_NATIVE && addBOM == false)
3119  {
3120  core::stringw ret(array);
3121  return ret;
3122  }
3123  else
3124  {
3125  core::array<uchar16_t> a(toUTF16(endian, addBOM));
3126  core::stringw ret(a.pointer());
3127  return ret;
3128  }
3129  }
3130  else if (sizeof(wchar_t) == 1)
3131  {
3132  core::array<uchar8_t> a(toUTF8(addBOM));
3133  core::stringw ret(a.pointer());
3134  return ret;
3135  }
3136 
3137  // Shouldn't happen.
3138  return core::stringw();
3139  }
core::array< uchar16_t > toUTF16(const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
Definition: irrUString.h:2956
core::array< uchar8_t > toUTF8(const bool addBOM=false) const
Definition: irrUString.h:2856
core::array< uchar32_t > toUTF32(const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
Definition: irrUString.h:3053
GLenum array
GLboolean GLboolean GLboolean GLboolean a
string< wchar_t > stringw
Typedef for wide character strings.
Definition: irrString.h:1461

◆ trim()

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::trim ( const ustring16< TAlloc > &  whitespace = " \t\n\r")
inline

Trims the ustring16. Removes the specified characters (by default, Latin-1 whitespace) from the begining and the end of the ustring16.

Parameters
whitespaceThe characters that are to be considered as whitespace.
Returns
A reference to our current string.

Definition at line 2427 of file irrUString.h.

2428  {
2429  core::array<uchar32_t> utf32white = whitespace.toUTF32();
2430 
2431  // find start and end of the substring without the specified characters
2432  const size_t begin = findFirstCharNotInList(utf32white.const_pointer(), whitespace.used + 1);
2434  return (*this="");
2435 
2436  const size_t end = findLastCharNotInList(utf32white.const_pointer(), whitespace.used + 1);
2438  return (*this = subString(begin, ustring16<TAlloc>::npos));
2439  else return (*this = subString(begin, (end + 1) - begin));
2440  }
GLuint GLuint end
Definition: SDL_opengl.h:1571
static const size_t npos
Definition: irrUString.h:808
size_t findLastCharNotInList(const uchar32_t *const c, size_t count=1) const
Definition: irrUString.h:1849
size_t findFirstCharNotInList(const uchar32_t *const c, size_t count=1) const
Definition: irrUString.h:1820
ustring16< TAlloc > subString(size_t begin, size_t length) const
Definition: irrUString.h:2027

◆ validate()

template<typename TAlloc = irrAllocator<uchar16_t>>
ustring16<TAlloc>& irr::core::ustring16< TAlloc >::validate ( )
inline

Validate the existing ustring16, checking for valid surrogate pairs and checking for proper termination.

Returns
A reference to our current string.

Definition at line 2468 of file irrUString.h.

2469  {
2470  // Validate all unicode characters.
2471  for (size_t i=0; i<allocated; ++i)
2472  {
2473  // Terminate on existing null.
2474  if (array[i] == 0)
2475  {
2476  used = i;
2477  return *this;
2478  }
2479  if (UTF16_IS_SURROGATE(array[i]))
2480  {
2481  if (((i+1) >= allocated) || UTF16_IS_SURROGATE_LO(array[i]))
2483  else if (UTF16_IS_SURROGATE_HI(array[i]) && !UTF16_IS_SURROGATE_LO(array[i+1]))
2485  ++i;
2486  }
2487  if (array[i] >= 0xFDD0 && array[i] <= 0xFDEF)
2489  }
2490 
2491  // terminate
2492  used = 0;
2493  if (allocated > 0)
2494  {
2495  used = allocated - 1;
2496  array[used] = 0;
2497  }
2498  return *this;
2499  }
#define UTF16_IS_SURROGATE_LO(c)
Definition: irrUString.h:73
#define UTF16_IS_SURROGATE_HI(c)
Definition: irrUString.h:72
const irr::u16 UTF_REPLACEMENT_CHARACTER
The unicode replacement character. Used to replace invalid characters.
Definition: irrUString.h:97
GLenum array
#define UTF16_IS_SURROGATE(c)
Is a UTF-16 code point a surrogate?
Definition: irrUString.h:71

Member Data Documentation

◆ npos

template<typename TAlloc = irrAllocator<uchar16_t>>
const size_t irr::core::ustring16< TAlloc >::npos = -1
static

-------------------—/// end iterator classes /// -------------------—/// ---------------—/// static variables /// ---------------—///

Definition at line 808 of file irrUString.h.


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