33 #if (__cplusplus > 199711L) || (_MSC_VER >= 1600) || defined(__GXX_EXPERIMENTAL_CXX0X__)
34 # define USTRING_CPP0X
35 # if defined(__GXX_EXPERIMENTAL_CXX0X__) && ((__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 5)))
36 # define USTRING_CPP0X_NEWLITERALS
46 #define __BYTE_ORDER 0
47 #define __LITTLE_ENDIAN 0
48 #define __BIG_ENDIAN 1
49 #elif defined(__MACH__) && defined(__APPLE__)
50 #include <machine/endian.h>
51 #elif defined(__FreeBSD__) || defined(__DragonFly__)
52 #include <sys/endian.h>
61 #ifndef USTRING_NO_STL
68 #include "irrAllocator.h"
71 #include "irrString.h"
79 #define UTF16_IS_SURROGATE(c) (((c) & 0xF800) == 0xD800)
80 #define UTF16_IS_SURROGATE_HI(c) (((c) & 0xFC00) == 0xD800)
81 #define UTF16_IS_SURROGATE_LO(c) (((c) & 0xFC00) == 0xDC00)
88 #ifdef USTRING_CPP0X_NEWLITERALS
114 uchar32_t x = ((high & ((1 << 6) -1)) << 10) | (low & ((1 << 10) -1));
115 uchar32_t wu = ((high >> 6) & ((1 << 5) - 1)) + 1;
116 return (wu << 16) | x;
123 return ((c >> 8) & 0x00FF) | ((c << 8) & 0xFF00);
130 return ((c >> 24) & 0x000000FF) |
131 ((c >> 8) & 0x0000FF00) |
132 ((c << 8) & 0x00FF0000) |
133 ((c << 24) & 0xFF000000);
184 #define COPY_ARRAY(source, size) \
185 memcpy(ret.pointer(), source, size); \
188 core::array<u8> ret(4);
195 #ifdef __BIG_ENDIAN__
208 #ifdef __BIG_ENDIAN__
247 template <
typename TAlloc = irrAllocator<u
char16_t> >
451 #ifndef USTRING_NO_STL
453 std::bidirectional_iterator_tag,
465 typedef std::iterator<std::bidirectional_iterator_tag, access, ptrdiff_t, const access, const access>
_Base;
469 #ifndef USTRING_NO_STL
495 while (i != 0 &&
pos < sr)
543 if (
pos == 0)
return *
this;
563 if (v == 0)
return *
this;
574 while (i != 0 &&
pos < sr)
591 if (v == 0)
return *
this;
601 while (i != 0 &&
pos != 0)
821 #if __BYTE_ORDER == __BIG_ENDIAN
835 #if __BYTE_ORDER == __BIG_ENDIAN
845 template <
class B,
class A>
849 #if __BYTE_ORDER == __BIG_ENDIAN
858 #ifndef USTRING_NO_STL
860 template <
class B,
class A,
typename Alloc>
864 #if __BYTE_ORDER == __BIG_ENDIAN
869 *
this = other.c_str();
874 template <
typename Itr>
878 #if __BYTE_ORDER == __BIG_ENDIAN
883 reserve(std::distance(first, last));
886 for (; first != last; ++first)
892 #ifndef USTRING_CPP0X_NEWLITERALS
897 #if __BYTE_ORDER == __BIG_ENDIAN
912 #if __BYTE_ORDER == __BIG_ENDIAN
927 #if __BYTE_ORDER == __BIG_ENDIAN
941 #if __BYTE_ORDER == __BIG_ENDIAN
955 #if __BYTE_ORDER == __BIG_ENDIAN
969 #if __BYTE_ORDER == __BIG_ENDIAN
983 #if __BYTE_ORDER == __BIG_ENDIAN
997 #if __BYTE_ORDER == __BIG_ENDIAN
1011 #if __BYTE_ORDER == __BIG_ENDIAN
1025 #if __BYTE_ORDER == __BIG_ENDIAN
1031 if (
sizeof(
wchar_t) == 4)
1033 else if (
sizeof(
wchar_t) == 2)
1035 else if (
sizeof(
wchar_t) == 1)
1044 #if __BYTE_ORDER == __BIG_ENDIAN
1050 if (
sizeof(
wchar_t) == 4)
1052 else if (
sizeof(
wchar_t) == 2)
1054 else if (
sizeof(
wchar_t) == 1)
1059 #ifdef USTRING_CPP0X
1066 other.allocated = 0;
1094 for (u32 i=0; i<=
used; ++i, ++
p)
1106 #ifdef USTRING_CPP0X
1115 array = other.array;
1128 template <
class B,
class A>
1131 *
this = other.
c_str();
1146 if (!c)
return *
this;
1164 if (!c)
return *
this;
1182 if (!c)
return *
this;
1196 if (
sizeof(
wchar_t) == 4)
1197 *
this =
reinterpret_cast<const uchar32_t* const
>(c);
1198 else if (
sizeof(
wchar_t) == 2)
1199 *
this =
reinterpret_cast<const uchar16_t* const
>(c);
1200 else if (
sizeof(
wchar_t) == 1)
1201 *
this =
reinterpret_cast<const uchar8_t* const
>(c);
1213 *
this =
reinterpret_cast<const uchar32_t* const
>(c);
1214 else if (
sizeof(B) == 2)
1215 *
this =
reinterpret_cast<const uchar16_t* const
>(c);
1216 else if (
sizeof(B) == 1)
1217 *
this =
reinterpret_cast<const uchar8_t* const
>(c);
1226 _IRR_DEBUG_BREAK_IF(index>=
size())
1228 return iter.operator*();
1235 _IRR_DEBUG_BREAK_IF(index>=
size())
1237 return iter.operator*();
1248 for(i=0;
array[i] && str[i]; ++i)
1249 if (
array[i] != str[i])
1252 return !
array[i] && !str[i];
1259 for(u32 i=0;
array[i] && other.
array[i]; ++i)
1270 for(u32 i=0;
array[i] && other.
array[i]; ++i)
1284 return !(*
this == str);
1291 return !(*
this == other);
1334 for(i=0; i < n &&
array[i] && oa[i]; ++i)
1335 if (
array[i] != oa[i])
1340 return (i == n) || (
used == other.
used);
1353 for(i=0; i < n &&
array[i] && str[i]; ++i)
1354 if (
array[i] != str[i])
1359 return (i == n) || (
array[i] == 0 && str[i] == 0);
1371 if (character > 0xFFFF)
1432 }
while(*
p++ && len < length);
1443 for (u32 l = 0; l<len;)
1446 if (((c2[l] >> 6) & 0x03) == 0x02)
1451 else if (c2[l] == 0xC0 || c2[l] == 0xC1)
1456 else if ((c2[l] & 0xF8) == 0xF0)
1469 if (valid && (((c2[l+1] >> 6) & 0x03) == 0x02)) ++l2;
else valid =
false;
1470 if (valid && (((c2[l+2] >> 6) & 0x03) == 0x02)) ++l2;
else valid =
false;
1471 if (valid && (((c2[l+3] >> 6) & 0x03) == 0x02)) ++l2;
else valid =
false;
1480 uchar8_t b1 = ((c2[l] & 0x7) << 2) | ((c2[l+1] >> 4) & 0x3);
1481 uchar8_t b2 = ((c2[l+1] & 0xF) << 4) | ((c2[l+2] >> 2) & 0xF);
1482 uchar8_t b3 = ((c2[l+2] & 0x3) << 6) | (c2[l+3] & 0x3F);
1495 else if ((c2[l] & 0xF0) == 0xE0)
1508 if (valid && (((c2[l+1] >> 6) & 0x03) == 0x02)) ++l2;
else valid =
false;
1509 if (valid && (((c2[l+2] >> 6) & 0x03) == 0x02)) ++l2;
else valid =
false;
1518 uchar8_t b1 = ((c2[l] & 0xF) << 4) | ((c2[l+1] >> 2) & 0xF);
1519 uchar8_t b2 = ((c2[l+1] & 0x3) << 6) | (c2[l+2] & 0x3F);
1524 else if ((c2[l] & 0xE0) == 0xC0)
1535 if (((c2[l+1] >> 6) & 0x03) != 0x02)
1544 uchar8_t b2 = ((c2[l] & 0x3) << 6) | (c2[l+1] & 0x3F);
1607 }
while(*
p++ && len < length);
1619 for (u32 l = start; l < start + len; ++l)
1664 }
while(*
p++ && len < length);
1677 for (u32 l = 0; l<len; ++l)
1695 else if (ch >= 0xD800 && ch <= 0xDFFF)
1723 for (u32 l=0; l<len; ++l)
1739 if (other.
size() == 0)
1742 if (other.
size() < length)
1753 while (!iter.atEnd() && l)
1811 for (u32 j=0; j<count; ++j)
1838 for (j=0; j<count; ++j)
1863 s32 pos =
size() - 1;
1864 while (!i.atStart())
1868 for (j=0; j<count; ++j)
1910 start = core::clamp ( start < 0 ? (s32)s : start, 0, (s32)s ) - 1;
1914 while (!i.atStart())
1939 while (!i.atStart())
1942 for (u32 j=0; j<count; ++j)
1959 u32 my_size =
size();
1960 u32 their_size = str.
size();
1962 if (their_size == 0 || my_size - start < their_size)
2008 for (u32 i=start; i<=
used-len; ++i)
2012 while(data[j] &&
array[i+j] == data[j])
2033 if ((length <= 0) || (
begin>=len))
2036 if ((length+
begin) > len)
2043 while (!i.atEnd() && length)
2079 append(core::stringc(c));
2089 append(core::stringc(c));
2094 #ifdef USTRING_CPP0X_NEWLITERALS
2100 append(core::stringc(c));
2110 append(core::stringc(c));
2121 append(core::stringc(c));
2131 append(core::stringc(c));
2141 append(core::stringc(c));
2190 if (toReplace.
size() == 0)
2195 const u32 other_size = toReplace.
size_raw();
2196 const u32 replace_size = replaceWith.
size_raw();
2199 s32 delta = replace_size - other_size;
2205 while ((pos =
find_raw(other, pos)) != -1)
2207 for (u32 i = 0; i < replace_size; ++i)
2218 for (u32 pos = 0; pos <=
used; ++i, ++pos)
2221 if (
array[pos] == *other)
2225 for (j = 0; j < other_size; ++j)
2227 if (
array[pos + j] != other[j])
2232 if (j == other_size)
2234 for (j = 0; j < replace_size; ++j)
2236 i += replace_size - 1;
2237 pos += other_size - 1;
2255 while ((pos =
find_raw(other, pos)) != -1)
2262 u32 len = delta * find_count;
2268 while ((pos =
find_raw(other, pos)) != -1)
2275 while (ptr != start)
2283 for (u32 i = 0; i < replace_size; ++i)
2286 pos += replace_size;
2303 u32 len = (c > 0xFFFF ? 2 : 1);
2304 for (u32 i=0; i<=
used; ++i)
2309 else if (i + 1 <=
used)
2314 u32 len2 = (uc32 > 0xFFFF ? 2 : 1);
2338 if (
size == 0)
return *
this;
2343 for (u32 i=0; i<=
used; ++i)
2348 if (
array[i + j] != tra[j])
2378 for (u32 i=0; i<=
used; ++i)
2383 else if (i + 1 <=
used)
2388 u32 len2 = (uc32 > 0xFFFF ? 2 : 1);
2392 while (!iter.atEnd())
2397 found += (c > 0xFFFF ? 2 : 1);
2422 core::array<uchar32_t> utf32white = whitespace.
toUTF32();
2441 _IRR_DEBUG_BREAK_IF(index>
used)
2446 u32 len = (t > 0xFFFF ? 2 : 1);
2448 for (u32 j =
static_cast<u32
>(i.getPos()) + len; j <=
used; ++j)
2479 if (
array[i] >= 0xFDD0 &&
array[i] <= 0xFDEF)
2539 template<
class container>
2540 u32
split(container& ret,
const uchar32_t*
const c, u32 count=1,
bool ignoreEmptyTokens=
true,
bool keepSeparators=
false)
const
2546 const u32 oldSize=ret.size();
2550 bool lastWasSeparator =
false;
2554 bool foundSeparator =
false;
2555 for (u32 j=0; j<count; ++j)
2559 if ((!ignoreEmptyTokens || pos - lastpos != 0) &&
2562 foundSeparator =
true;
2563 lastpos = (keepSeparators ? pos : pos + 1);
2564 lastpospos = (keepSeparators ? i.getPos() : i.getPos() + 1);
2568 lastWasSeparator = foundSeparator;
2575 return ret.size()-oldSize;
2596 template<
class container>
2599 core::array<uchar32_t> v = c.
toUTF32();
2600 return split(ret, v.pointer(), v.size(), ignoreEmptyTokens, keepSeparators);
2626 u8 len = (c > 0xFFFF ? 2 : 1);
2634 for (u32 i =
used - 2; i > iter.getPos(); --i)
2643 array[iter.getPos()] = vh;
2644 array[iter.getPos()+1] = vl;
2662 if (len == 0)
return *
this;
2670 for (u32 i =
used - 2; i > iter.getPos() + len; --i)
2674 for (u32 i = 0; i < len; ++i)
2696 for (u32 i =
used - 1; i > pos; --i)
2710 for (u32 i=pos; i<=
used; ++i)
2791 core::string<uchar8_t>
toUTF8_s(
const bool addBOM =
false)
const
2793 core::string<uchar8_t> ret;
2805 while (!iter.atEnd())
2810 uchar8_t b1 = (0x1E << 3) | ((c >> 18) & 0x7);
2811 uchar8_t b2 = (0x2 << 6) | ((c >> 12) & 0x3F);
2812 uchar8_t b3 = (0x2 << 6) | ((c >> 6) & 0x3F);
2813 uchar8_t b4 = (0x2 << 6) | (c & 0x3F);
2821 uchar8_t b1 = (0xE << 4) | ((c >> 12) & 0xF);
2822 uchar8_t b2 = (0x2 << 6) | ((c >> 6) & 0x3F);
2823 uchar8_t b3 = (0x2 << 6) | (c & 0x3F);
2830 uchar8_t b1 = (0x6 << 5) | ((c >> 6) & 0x1F);
2831 uchar8_t b2 = (0x2 << 6) | (c & 0x3F);
2837 ret.append(
static_cast<uchar8_t>(c));
2848 core::array<uchar8_t>
toUTF8(
const bool addBOM =
false)
const
2861 while (!iter.atEnd())
2866 uchar8_t b1 = (0x1E << 3) | ((c >> 18) & 0x7);
2867 uchar8_t b2 = (0x2 << 6) | ((c >> 12) & 0x3F);
2868 uchar8_t b3 = (0x2 << 6) | ((c >> 6) & 0x3F);
2869 uchar8_t b4 = (0x2 << 6) | (c & 0x3F);
2877 uchar8_t b1 = (0xE << 4) | ((c >> 12) & 0xF);
2878 uchar8_t b2 = (0x2 << 6) | ((c >> 6) & 0x3F);
2879 uchar8_t b3 = (0x2 << 6) | (c & 0x3F);
2886 uchar8_t b1 = (0x6 << 5) | ((c >> 6) & 0x1F);
2887 uchar8_t b2 = (0x2 << 6) | (c & 0x3F);
2893 ret.push_back(
static_cast<uchar8_t>(c));
2902 #ifdef USTRING_CPP0X_NEWLITERALS
2907 core::string<char16_t> toUTF16_s(const unicode::EUTF_ENDIAN endian = unicode::EUTFEE_NATIVE, const bool addBOM = false) const
2909 core::string<char16_t> ret;
2934 char16_t* ptr = ret.c_str();
2935 for (u32 i = 0; i < ret.size(); ++i)
2976 for (u32 i = 0; i <=
used; ++i)
2985 #ifdef USTRING_CPP0X_NEWLITERALS
2990 core::string<char32_t> toUTF32_s(const unicode::EUTF_ENDIAN endian = unicode::EUTFEE_NATIVE, const bool addBOM = false) const
2992 core::string<char32_t> ret;
3027 while (!iter.atEnd())
3077 ret.push_back(t.full);
3082 while (!iter.atEnd())
3102 if (
sizeof(
wchar_t) == 4)
3104 core::array<uchar32_t> a(
toUTF32(endian, addBOM));
3105 core::stringw ret(a.pointer());
3108 else if (
sizeof(
wchar_t) == 2)
3112 core::stringw ret(
array);
3117 core::array<uchar16_t> a(
toUTF16(endian, addBOM));
3118 core::stringw ret(a.pointer());
3122 else if (
sizeof(
wchar_t) == 1)
3124 core::array<uchar8_t> a(
toUTF8(addBOM));
3125 core::stringw ret(a.pointer());
3130 return core::stringw();
3142 if (
sizeof(
wchar_t) == 4)
3144 core::array<uchar32_t> a(
toUTF32(endian, addBOM));
3145 core::array<wchar_t> ret(a.size());
3146 ret.set_used(a.size());
3147 memcpy((
void*)ret.pointer(), (
void*)a.pointer(), a.size() *
sizeof(
uchar32_t));
3150 if (
sizeof(
wchar_t) == 2)
3154 core::array<wchar_t> ret(
used);
3161 core::array<uchar16_t> a(
toUTF16(endian, addBOM));
3162 core::array<wchar_t> ret(a.size());
3163 ret.set_used(a.size());
3164 memcpy((
void*)ret.pointer(), (
void*)a.pointer(), a.size() *
sizeof(
uchar16_t));
3168 if (
sizeof(
wchar_t) == 1)
3170 core::array<uchar8_t> a(
toUTF8(addBOM));
3171 core::array<wchar_t> ret(a.size());
3172 ret.set_used(a.size());
3173 memcpy((
void*)ret.pointer(), (
void*)a.pointer(), a.size() *
sizeof(
uchar8_t));
3178 return core::array<wchar_t>();
3187 #if defined(_IRR_WCHAR_FILESYSTEM)
3257 if (old_array == 0)
return;
3259 u32 amount =
used < new_size ?
used : new_size;
3260 for (u32 i=0; i<=amount; ++i)
3261 array[i] = old_array[i];
3285 template <
typename TAlloc>
3295 template <
typename TAlloc,
class B>
3305 template <
class B,
typename TAlloc>
3315 template <
typename TAlloc,
typename B,
typename BAlloc>
3325 template <
typename TAlloc,
typename B,
typename BAlloc>
3335 template <
typename TAlloc,
typename B,
typename A,
typename BAlloc>
3345 template <
typename TAlloc,
typename B,
typename A,
typename BAlloc>
3355 template <
typename TAlloc>
3365 template <
typename TAlloc>
3374 #ifdef USTRING_CPP0X_NEWLITERALS
3376 template <
typename TAlloc>
3377 inline ustring16<TAlloc>
operator+(
const ustring16<TAlloc>& left,
const uchar32_t right)
3379 ustring16<TAlloc> ret(left);
3386 template <
typename TAlloc>
3387 inline ustring16<TAlloc>
operator+(
const uchar32_t left,
const ustring16<TAlloc>& right)
3389 ustring16<TAlloc> ret(left);
3397 template <
typename TAlloc>
3401 ret += core::stringc(right);
3407 template <
typename TAlloc>
3417 template <
typename TAlloc>
3421 ret += core::stringc(right);
3427 template <
typename TAlloc>
3437 template <
typename TAlloc>
3441 ret += core::stringc(right);
3447 template <
typename TAlloc>
3457 template <
typename TAlloc>
3461 ret += core::stringc(right);
3467 template <
typename TAlloc>
3477 template <
typename TAlloc>
3481 ret += core::stringc(right);
3487 template <
typename TAlloc>
3497 template <
typename TAlloc>
3501 ret += core::stringc(right);
3507 template <
typename TAlloc>
3517 template <
typename TAlloc>
3521 ret += core::stringc(right);
3527 template <
typename TAlloc>
3537 template <
typename TAlloc>
3541 ret += core::stringc(right);
3547 template <
typename TAlloc>
3556 #ifdef USTRING_CPP0X
3558 template <
typename TAlloc>
3559 inline ustring16<TAlloc>&&
operator+(
const ustring16<TAlloc>& left, ustring16<TAlloc>&& right)
3563 return std::move(right);
3568 template <
typename TAlloc>
3569 inline ustring16<TAlloc>&&
operator+(ustring16<TAlloc>&& left,
const ustring16<TAlloc>& right)
3573 return std::move(left);
3578 template <
typename TAlloc>
3579 inline ustring16<TAlloc>&&
operator+(ustring16<TAlloc>&& left, ustring16<TAlloc>&& right)
3582 if ((right.size_raw() <= left.capacity() - left.size_raw()) ||
3583 (right.capacity() - right.size_raw() < left.size_raw()))
3586 return std::move(left);
3590 right.insert(left, 0);
3591 return std::move(right);
3597 template <
typename TAlloc,
class B>
3598 inline ustring16<TAlloc>&&
operator+(ustring16<TAlloc>&& left,
const B*
const right)
3602 return std::move(left);
3607 template <
class B,
typename TAlloc>
3608 inline ustring16<TAlloc>&&
operator+(
const B*
const left, ustring16<TAlloc>&& right)
3612 return std::move(right);
3617 template <
typename TAlloc,
typename B,
typename BAlloc>
3618 inline ustring16<TAlloc>&&
operator+(
const string<B, BAlloc>& left, ustring16<TAlloc>&& right)
3622 return std::move(right);
3627 template <
typename TAlloc,
typename B,
typename BAlloc>
3628 inline ustring16<TAlloc>&&
operator+(ustring16<TAlloc>&& left,
const string<B, BAlloc>& right)
3632 return std::move(left);
3637 template <
typename TAlloc,
typename B,
typename A,
typename BAlloc>
3638 inline ustring16<TAlloc>&&
operator+(
const std::basic_string<B, A, BAlloc>& left, ustring16<TAlloc>&& right)
3642 return std::move(right);
3647 template <
typename TAlloc,
typename B,
typename A,
typename BAlloc>
3648 inline ustring16<TAlloc>&&
operator+(ustring16<TAlloc>&& left,
const std::basic_string<B, A, BAlloc>& right)
3652 return std::move(left);
3657 template <
typename TAlloc>
3658 inline ustring16<TAlloc>
operator+(ustring16<TAlloc>&& left,
const char right)
3661 return std::move(left);
3666 template <
typename TAlloc>
3667 inline ustring16<TAlloc>
operator+(
const char left, ustring16<TAlloc>&& right)
3670 return std::move(right);
3674 #ifdef USTRING_CPP0X_NEWLITERALS
3676 template <
typename TAlloc>
3680 return std::move(left);
3685 template <
typename TAlloc>
3689 return std::move(right);
3695 template <
typename TAlloc>
3696 inline ustring16<TAlloc>
operator+(ustring16<TAlloc>&& left,
const short right)
3698 left.
append(core::stringc(right));
3699 return std::move(left);
3704 template <
typename TAlloc>
3705 inline ustring16<TAlloc>
operator+(
const short left, ustring16<TAlloc>&& right)
3707 right.
insert(core::stringc(left), 0);
3708 return std::move(right);
3713 template <
typename TAlloc>
3714 inline ustring16<TAlloc>
operator+(ustring16<TAlloc>&& left,
const unsigned short right)
3716 left.
append(core::stringc(right));
3717 return std::move(left);
3722 template <
typename TAlloc>
3723 inline ustring16<TAlloc>
operator+(
const unsigned short left, ustring16<TAlloc>&& right)
3725 right.
insert(core::stringc(left), 0);
3726 return std::move(right);
3731 template <
typename TAlloc>
3732 inline ustring16<TAlloc>
operator+(ustring16<TAlloc>&& left,
const int right)
3734 left.
append(core::stringc(right));
3735 return std::move(left);
3740 template <
typename TAlloc>
3741 inline ustring16<TAlloc>
operator+(
const int left, ustring16<TAlloc>&& right)
3743 right.
insert(core::stringc(left), 0);
3744 return std::move(right);
3749 template <
typename TAlloc>
3750 inline ustring16<TAlloc>
operator+(ustring16<TAlloc>&& left,
const unsigned int right)
3752 left.
append(core::stringc(right));
3753 return std::move(left);
3758 template <
typename TAlloc>
3759 inline ustring16<TAlloc>
operator+(
const unsigned int left, ustring16<TAlloc>&& right)
3761 right.
insert(core::stringc(left), 0);
3762 return std::move(right);
3767 template <
typename TAlloc>
3768 inline ustring16<TAlloc>
operator+(ustring16<TAlloc>&& left,
const long right)
3770 left.
append(core::stringc(right));
3771 return std::move(left);
3776 template <
typename TAlloc>
3777 inline ustring16<TAlloc>
operator+(
const long left, ustring16<TAlloc>&& right)
3779 right.
insert(core::stringc(left), 0);
3780 return std::move(right);
3785 template <
typename TAlloc>
3786 inline ustring16<TAlloc>
operator+(ustring16<TAlloc>&& left,
const unsigned long right)
3788 left.
append(core::stringc(right));
3789 return std::move(left);
3794 template <
typename TAlloc>
3795 inline ustring16<TAlloc>
operator+(
const unsigned long left, ustring16<TAlloc>&& right)
3797 right.
insert(core::stringc(left), 0);
3798 return std::move(right);
3803 template <
typename TAlloc>
3804 inline ustring16<TAlloc>
operator+(ustring16<TAlloc>&& left,
const float right)
3806 left.
append(core::stringc(right));
3807 return std::move(left);
3812 template <
typename TAlloc>
3813 inline ustring16<TAlloc>
operator+(
const float left, ustring16<TAlloc>&& right)
3815 right.
insert(core::stringc(left), 0);
3816 return std::move(right);
3821 template <
typename TAlloc>
3822 inline ustring16<TAlloc>
operator+(ustring16<TAlloc>&& left,
const double right)
3824 left.
append(core::stringc(right));
3825 return std::move(left);
3830 template <
typename TAlloc>
3831 inline ustring16<TAlloc>
operator+(
const double left, ustring16<TAlloc>&& right)
3833 right.
insert(core::stringc(left), 0);
3834 return std::move(right);
3839 #ifndef USTRING_NO_STL
3841 template <
typename TAlloc>
3849 template <
typename TAlloc>
3858 #ifndef USTRING_NO_STL
3865 class hash :
public std::unary_function<core::ustring, size_t>
3870 size_t ret = 2166136261U;
3872 size_t stride = 1 + s.
size_raw() / 10;
3875 while (i != s.
end())
3878 ret = 16777619U * ret ^ (size_t)s[(u32)index];
Hashing algorithm for hashing a ustring.
Definition: irrUString.h:3866
size_t operator()(const core::ustring &s) const
Definition: irrUString.h:3868
Iterator to iterate through a UTF-16 string.
Definition: irrUString.h:462
_ustring16_const_iterator(const ustring16< TAlloc > &s, const u32 p)
Definition: irrUString.h:486
bool atStart() const
Is the iterator at the start of the string?
Definition: irrUString.h:703
const access const_reference
Definition: irrUString.h:467
_ustring16_const_iterator _Iter
Definition: irrUString.h:464
pointer operator->()
Accesses the full character at the iterator's position.
Definition: irrUString.h:697
const ustring16< TAlloc > * ref
Definition: irrUString.h:737
void toEnd()
Moves the iterator to the end of the string.
Definition: irrUString.h:724
_Iter operator-(const difference_type v) const
Return a new iterator that is a variable number of full characters backward from the current position...
Definition: irrUString.h:621
difference_type operator-(const _Iter &iter) const
Returns the distance between two iterators.
Definition: irrUString.h:629
bool operator==(const _Iter &iter) const
Test for equalness.
Definition: irrUString.h:505
_Iter operator--(int)
Switch to the previous full character in the string, returning the previous position.
Definition: irrUString.h:552
_Base::pointer pointer
Definition: irrUString.h:473
_Iter & operator+=(const difference_type v)
Advance a specified number of full characters in the string.
Definition: irrUString.h:561
bool atEnd() const
Is the iterator at the end of the string?
Definition: irrUString.h:709
_Iter & operator--()
Switch to the previous full character in the string.
Definition: irrUString.h:541
void toStart()
Moves the iterator to the start of the string.
Definition: irrUString.h:718
_Iter & operator++()
Switch to the next full character in the string.
Definition: irrUString.h:521
_Iter operator+(const difference_type v) const
Return a new iterator that is a variable number of full characters forward from the current position.
Definition: irrUString.h:613
std::iterator< std::bidirectional_iterator_tag, access, ptrdiff_t, const access, const access > _Base
Definition: irrUString.h:465
const_reference operator*() const
Accesses the full character at the iterator's position.
Definition: irrUString.h:659
_Base::difference_type difference_type
Definition: irrUString.h:471
_Base::difference_type distance_type
Definition: irrUString.h:472
u32 pos
Definition: irrUString.h:738
const_reference reference
Definition: irrUString.h:474
_ustring16_const_iterator(const _Iter &i)
Constructors.
Definition: irrUString.h:484
_Iter operator++(int)
Switch to the next full character in the string, returning the previous position.
Definition: irrUString.h:533
bool operator!=(const _Iter &iter) const
Test for unequalness.
Definition: irrUString.h:513
const_pointer operator->() const
Accesses the full character at the iterator's position.
Definition: irrUString.h:691
reference operator*()
Accesses the full character at the iterator's position.
Definition: irrUString.h:675
_ustring16_const_iterator(const ustring16< TAlloc > &s)
Definition: irrUString.h:485
u32 getPos() const
Returns the iterator's position.
Definition: irrUString.h:731
_Base::value_type value_type
Definition: irrUString.h:470
_Iter & operator-=(const difference_type v)
Go back a specified number of full characters in the string.
Definition: irrUString.h:589
const access const_pointer
Definition: irrUString.h:466
---------------—/// iterator classes /// ---------------—///
Definition: irrUString.h:258
_ustring16_iterator_access & operator-=(int val)
Subtracts from the value by a specified amount.
Definition: irrUString.h:323
_ustring16_iterator_access & operator/=(int val)
Divides the value by a specified amount.
Definition: irrUString.h:341
void _set(uchar32_t c)
Sets a uchar32_t at our current position.
Definition: irrUString.h:413
uchar32_t operator+(int val) const
Adds to the value by a specified amount.
Definition: irrUString.h:359
_ustring16_iterator_access & operator%=(int val)
Modulos the value by a specified amount.
Definition: irrUString.h:350
u32 pos
Definition: irrUString.h:445
uchar32_t operator++(int)
Increments the value by 1, returning the old value.
Definition: irrUString.h:287
_ustring16_iterator_access(const ustring16< TAlloc > *s, u32 p)
Definition: irrUString.h:260
uchar32_t operator--(int)
Decrements the value by 1, returning the old value.
Definition: irrUString.h:304
uchar32_t _get() const
Gets a uchar32_t from our current position.
Definition: irrUString.h:398
uchar32_t operator*(int val) const
Multiplies the value by a specified amount.
Definition: irrUString.h:375
_ustring16_iterator_access & operator--()
Decrements the value by 1.
Definition: irrUString.h:296
_ustring16_iterator_access & operator*=(int val)
Multiples the value by a specified amount.
Definition: irrUString.h:332
_ustring16_iterator_access & operator+=(int val)
Adds to the value by a specified amount.
Definition: irrUString.h:314
const ustring16< TAlloc > * ref
Definition: irrUString.h:444
uchar32_t operator/(int val) const
Divides the value by a specified amount.
Definition: irrUString.h:383
uchar32_t operator-(int val) const
Subtracts from the value by a specified amount.
Definition: irrUString.h:367
uchar32_t operator%(int val) const
Modulos the value by a specified amount.
Definition: irrUString.h:391
_ustring16_iterator_access & operator=(const uchar32_t c)
Allow one to change the character in the unicode string.
Definition: irrUString.h:271
_ustring16_iterator_access & operator++()
Increments the value by 1.
Definition: irrUString.h:279
Iterator to iterate through a UTF-16 string.
Definition: irrUString.h:743
_ustring16_iterator(const ustring16< TAlloc > &s, const u32 p)
Definition: irrUString.h:763
_ustring16_iterator(const _Iter &i)
Constructors.
Definition: irrUString.h:761
access reference
Definition: irrUString.h:755
_Base::difference_type difference_type
Definition: irrUString.h:752
_Base::distance_type distance_type
Definition: irrUString.h:753
_Base::const_pointer const_pointer
Definition: irrUString.h:747
reference operator*()
Accesses the full character at the iterator's position.
Definition: irrUString.h:782
access pointer
Definition: irrUString.h:754
pointer operator->()
Accesses the full character at the iterator's position.
Definition: irrUString.h:804
_ustring16_iterator _Iter
Definition: irrUString.h:745
_ustring16_const_iterator _Base
Definition: irrUString.h:746
_Base::value_type value_type
Definition: irrUString.h:751
_ustring16_iterator(const ustring16< TAlloc > &s)
Definition: irrUString.h:762
_Base::const_reference const_reference
Definition: irrUString.h:748
reference operator*() const
Accesses the full character at the iterator's position.
Definition: irrUString.h:766
pointer operator->() const
Accesses the full character at the iterator's position.
Definition: irrUString.h:798
UTF-16 string class.
Definition: irrUString.h:249
ustring16< TAlloc > & erase_raw(u32 pos)
Removes a character from string.
Definition: irrUString.h:2708
ustring16< TAlloc > & removeChars(const ustring16< TAlloc > &characters)
Removes characters from the ustring16.
Definition: irrUString.h:2370
const unicode::EUTF_ENCODE getEncoding() const
Gets the encoding of the Unicode string this class contains.
Definition: irrUString.h:3232
ustring16< TAlloc > & operator=(const B *const c)
Assignment operator for other strings.
Definition: irrUString.h:1210
ustring16< TAlloc > & insert_raw(uchar16_t c, u32 pos)
Inserts a character into the string.
Definition: irrUString.h:2689
ustring16< TAlloc >::_ustring16_iterator_access access
Definition: irrUString.h:447
ustring16< TAlloc > & loadDataStream(const char *data, size_t data_size)
Loads an unknown stream of data.
Definition: irrUString.h:3199
ustring16(const uchar8_t *const c, u32 length)
Constructor for copying a UTF-8 string from a pointer with a given length.
Definition: irrUString.h:952
ustring16(const uchar16_t *const c)
Constructor for copying a UTF-16 string from a pointer.
Definition: irrUString.h:966
bool equalsn(const ustring16< TAlloc > &other, u32 n) const
Compares the first n characters of this string with another.
Definition: irrUString.h:1330
ustring16< TAlloc > & remove(const ustring16< TAlloc > &toRemove)
Removes a ustring16 from the ustring16.
Definition: irrUString.h:2335
ustring16(const uchar32_t *const c, u32 length)
Constructor for copying a UTF-32 from a pointer with a given length.
Definition: irrUString.h:1008
ustring16< TAlloc > & operator=(const uchar16_t *const c)
Assignment operator for UTF-16 strings.
Definition: irrUString.h:1155
uchar16_t * array
Definition: irrUString.h:3273
ustring16< TAlloc > & replace(uchar32_t toReplace, uchar32_t replaceWith)
Replaces all characters of a given type with another one.
Definition: irrUString.h:2170
void reallocate(u32 new_size)
Reallocate the string, making it bigger or smaller.
Definition: irrUString.h:3251
u32 size() const
Returns the length of a ustring16 in full characters.
Definition: irrUString.h:1297
bool operator==(const uchar16_t *const str) const
Equality operator.
Definition: irrUString.h:1242
ustring16< TAlloc >::_ustring16_const_iterator const_iterator
Definition: irrUString.h:811
ustring16< TAlloc > & remove(uchar32_t c)
Removes characters from a ustring16.
Definition: irrUString.h:2299
ustring16< TAlloc > & append(const uchar32_t *const other, u32 length=0xffffffff)
Appends a UTF-32 string to this ustring16.
Definition: irrUString.h:1638
ustring16< TAlloc > & insert(const ustring16< TAlloc > &c, u32 pos)
Inserts a string into the string.
Definition: irrUString.h:2659
bool operator<(const ustring16< TAlloc > &other) const
Is smaller comparator.
Definition: irrUString.h:1268
u32 capacity() const
Gets the size of the allocated memory buffer for the string.
Definition: irrUString.h:2606
ustring16(const string< B, A > &other)
Constructor from other string types.
Definition: irrUString.h:846
ustring16(Itr first, Itr last)
Constructor from iterator.
Definition: irrUString.h:875
s32 findFirstChar(const uchar32_t *const c, u32 count=1) const
Finds first occurrence of a character of a list.
Definition: irrUString.h:1800
ustring16< TAlloc > & validate()
Validate the existing ustring16, checking for valid surrogate pairs and checking for proper terminati...
Definition: irrUString.h:2460
ustring16< TAlloc > subString(u32 begin, s32 length) const
Returns a substring.
Definition: irrUString.h:2028
s32 find(const ustring16< TAlloc > &str, const u32 start=0) const
Finds another ustring16 in this ustring16.
Definition: irrUString.h:1957
core::array< uchar8_t > toUTF8(const bool addBOM=false) const
Converts the string to a UTF-8 encoded string array.
Definition: irrUString.h:2848
u32 used
Definition: irrUString.h:3276
s32 findLastChar(const uchar32_t *const c, u32 count=1) const
Finds last occurrence of a character in a list.
Definition: irrUString.h:1930
const_iterator begin() const
Returns an iterator to the beginning of the string.
Definition: irrUString.h:2742
u32 split(container &ret, const ustring16< TAlloc > &c, bool ignoreEmptyTokens=true, bool keepSeparators=false) const
Split the ustring16 into parts.
Definition: irrUString.h:2597
ustring16< TAlloc > & append(const ustring16< TAlloc > &other, u32 length)
Appends a certain amount of characters of a ustring16 to this ustring16.
Definition: irrUString.h:1737
bool equalsn(const uchar16_t *const str, u32 n) const
Compares the first n characters of this string with another.
Definition: irrUString.h:1348
core::array< uchar32_t > toUTF32(const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
Converts the string to a UTF-32 encoded string array.
Definition: irrUString.h:3045
ustring16< TAlloc > & operator=(const uchar8_t *const c)
Assignment operator for UTF-8 strings.
Definition: irrUString.h:1137
s32 findLast(uchar32_t c, s32 start=-1) const
Finds last occurrence of character.
Definition: irrUString.h:1907
u32 split(container &ret, const uchar32_t *const c, u32 count=1, bool ignoreEmptyTokens=true, bool keepSeparators=false) const
Split the ustring16 into parts.
Definition: irrUString.h:2540
ustring16(const ustring16< TAlloc > &other)
Constructor.
Definition: irrUString.h:832
ustring16(const uchar8_t *const c)
Constructor for copying a UTF-8 string from a pointer.
Definition: irrUString.h:924
bool empty() const
Informs if the ustring is empty or not.
Definition: irrUString.h:1312
void reserve(u32 count)
Reserves some memory.
Definition: irrUString.h:1767
const_iterator cbegin() const
Returns an iterator to the beginning of the string.
Definition: irrUString.h:2751
ustring16< TAlloc > & erase(u32 index)
Erases a character from the ustring16.
Definition: irrUString.h:2439
ustring16(const char *const c, u32 length)
Constructor for copying a character string from a pointer with a given length.
Definition: irrUString.h:909
ustring16< TAlloc > & replace(const ustring16< TAlloc > &toReplace, const ustring16< TAlloc > &replaceWith)
Replaces all instances of a string with another one.
Definition: irrUString.h:2188
ustring16< TAlloc > & operator+=(char c)
Appends a character to this ustring16.
Definition: irrUString.h:2057
~ustring16()
Destructor.
Definition: irrUString.h:1073
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.
Definition: irrUString.h:3140
ustring16()
-------------------—/// end iterator classes /// -------------------—///
Definition: irrUString.h:818
iterator end()
Returns an iterator to the end of the string.
Definition: irrUString.h:2760
ustring16< TAlloc > & append(const uchar8_t *const other, u32 length=0xffffffff)
Appends a UTF-8 string to this ustring16.
Definition: irrUString.h:1397
s32 findNext(uchar32_t c, u32 startPos) const
Finds next occurrence of character.
Definition: irrUString.h:1885
ustring16< TAlloc > & trim(const ustring16< TAlloc > &whitespace=" \t\n\r")
Trims the ustring16.
Definition: irrUString.h:2420
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:3100
u32 size_raw() const
Returns the raw number of UTF-16 code points in the string which includes the individual surrogates.
Definition: irrUString.h:2614
ustring16 & operator=(const ustring16< TAlloc > &other)
Assignment operator.
Definition: irrUString.h:1080
ustring16(const wchar_t *const c, u32 length)
Constructor for copying a wchar_t string from a pointer with a given length.
Definition: irrUString.h:1041
s32 find_raw(const ustring16< TAlloc > &str, const u32 start=0) const
Finds another ustring16 in this ustring16.
Definition: irrUString.h:1995
ustring16< TAlloc > & append(const ustring16< TAlloc > &other)
Appends a ustring16 to this ustring16.
Definition: irrUString.h:1714
ustring16< TAlloc > & insert(uchar32_t c, u32 pos)
Inserts a character into the string.
Definition: irrUString.h:2624
ustring16< TAlloc >::_ustring16_iterator iterator
Definition: irrUString.h:810
ustring16< TAlloc > & append(uchar32_t character)
Appends a character to this ustring16.
Definition: irrUString.h:1366
ustring16< TAlloc > & operator=(const wchar_t *const c)
Assignment operator for wchar_t strings.
Definition: irrUString.h:1194
bool operator!=(const uchar16_t *const str) const
Inequality operator.
Definition: irrUString.h:1282
const uchar16_t * c_str() const
Returns a pointer to the raw UTF-16 string data.
Definition: irrUString.h:1320
ustring16(const char *const c)
Constructor for copying a character string from a pointer.
Definition: irrUString.h:894
s32 findFirstCharNotInList(const uchar32_t *const c, u32 count=1) const
Finds first position of a character not in a given list.
Definition: irrUString.h:1826
u32 allocated
Definition: irrUString.h:3275
ustring16(const std::basic_string< B, A, Alloc > &other)
Constructor from std::string.
Definition: irrUString.h:861
ustring16(const uchar32_t *const c)
Constructor for copying a UTF-32 string from a pointer.
Definition: irrUString.h:994
ustring16< TAlloc > & operator=(const string< B, A > &other)
Assignment operator for other string types.
Definition: irrUString.h:1129
s32 findLastCharNotInList(const uchar32_t *const c, u32 count=1) const
Finds last position of a character not in a given list.
Definition: irrUString.h:1855
const_iterator end() const
Returns an iterator to the end of the string.
Definition: irrUString.h:2770
ustring16(const uchar16_t *const c, u32 length)
Constructor for copying a UTF-16 string from a pointer with a given length.
Definition: irrUString.h:980
io::path toPATH_s(const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
Converts the string to a properly encoded io::path string.
Definition: irrUString.h:3185
s32 findFirst(uchar32_t c) const
Finds first occurrence of character.
Definition: irrUString.h:1779
uchar32_t lastChar() const
Gets the last char of the ustring16, or 0.
Definition: irrUString.h:2496
ustring16(const char c)
Constructor for copying a UTF-8 string from a single char.
Definition: irrUString.h:938
ustring16< TAlloc > & replace_raw(uchar16_t c, u32 pos)
Replaces a character in the string.
Definition: irrUString.h:2724
access operator[](const u32 index)
Direct access operator.
Definition: irrUString.h:1224
const_iterator cend() const
Returns an iterator to the end of the string.
Definition: irrUString.h:2780
ustring16(const wchar_t *const c)
Constructor for copying a wchar_t string from a pointer.
Definition: irrUString.h:1022
core::string< uchar8_t > toUTF8_s(const bool addBOM=false) const
Converts the string to a UTF-8 encoded string.
Definition: irrUString.h:2791
ustring16< TAlloc > & append(const uchar16_t *const other, u32 length=0xffffffff)
Appends a UTF-16 string to this ustring16.
Definition: irrUString.h:1573
core::array< uchar16_t > toUTF16(const unicode::EUTF_ENDIAN endian=unicode::EUTFEE_NATIVE, const bool addBOM=false) const
Converts the string to a UTF-16 encoded string array.
Definition: irrUString.h:2948
TAlloc allocator
Definition: irrUString.h:3277
unicode::EUTF_ENCODE encoding
Definition: irrUString.h:3274
ustring16< TAlloc > & operator=(const uchar32_t *const c)
Assignment operator for UTF-32 strings.
Definition: irrUString.h:1173
const unicode::EUTF_ENDIAN getEndianness() const
Gets the endianness of the Unicode string this class contains.
Definition: irrUString.h:3239
iterator begin()
Returns an iterator to the beginning of the string.
Definition: irrUString.h:2733
static const irr::u16 UTF16_LO_SURROGATE
Definition: irrUString.h:76
static const irr::u16 UTF16_HI_SURROGATE
UTF-16 surrogate start values.
Definition: irrUString.h:75
#define UTF16_IS_SURROGATE(c)
Is a UTF-16 code point a surrogate?
Definition: irrUString.h:79
#define COPY_ARRAY(source, size)
#define UTF16_IS_SURROGATE_LO(c)
Definition: irrUString.h:81
#define UTF16_IS_SURROGATE_HI(c)
Definition: irrUString.h:80
const irr::u16 UTF_REPLACEMENT_CHARACTER
The unicode replacement character. Used to replace invalid characters.
Definition: irrUString.h:105
EUTF_ENCODE determineUnicodeBOM(const char *data)
Detects if the given data stream starts with a unicode BOM.
Definition: irrUString.h:233
core::array< u8 > getUnicodeBOM(EUTF_ENCODE mode)
Returns the specified unicode byte order mark in a byte array.
Definition: irrUString.h:182
const u8 BOM_ENCODE_UTF32_LEN
Definition: irrUString.h:154
const u8 BOM_ENCODE_UTF16_LE[2]
Definition: irrUString.h:147
const u8 BOM_ENCODE_UTF16_LEN
Definition: irrUString.h:153
const u8 BOM_ENCODE_UTF8[3]
Unicode byte order marks for file operations.
Definition: irrUString.h:145
const u8 BOM_UTF8_LEN
The size of the Unicode byte order mark in terms of the Unicode character size.
Definition: irrUString.h:140
uchar32_t toUTF32(uchar16_t high, uchar16_t low)
Convert a UTF-16 surrogate pair into a UTF-32 character.
Definition: irrUString.h:111
const u16 BOM
The Unicode byte order mark.
Definition: irrUString.h:137
const u8 BOM_UTF16_LEN
Definition: irrUString.h:141
const u8 BOM_ENCODE_UTF16_BE[2]
Definition: irrUString.h:146
const u8 BOM_ENCODE_UTF32_LE[4]
Definition: irrUString.h:149
const u8 BOM_ENCODE_UTF8_LEN
The size in bytes of the Unicode byte marks for file operations.
Definition: irrUString.h:152
EUTF_ENDIAN
Unicode endianness.
Definition: irrUString.h:171
@ EUTFEE_NATIVE
Definition: irrUString.h:172
@ EUTFEE_LITTLE
Definition: irrUString.h:173
@ EUTFEE_BIG
Definition: irrUString.h:174
EUTF_ENCODE
Unicode encoding type.
Definition: irrUString.h:158
@ EUTFE_UTF16_BE
Definition: irrUString.h:163
@ EUTFE_UTF16_LE
Definition: irrUString.h:162
@ EUTFE_UTF32
Definition: irrUString.h:164
@ EUTFE_UTF32_LE
Definition: irrUString.h:165
@ EUTFE_NONE
Definition: irrUString.h:159
@ EUTFE_UTF32_BE
Definition: irrUString.h:166
@ EUTFE_UTF16
Definition: irrUString.h:161
@ EUTFE_UTF8
Definition: irrUString.h:160
uchar16_t swapEndian16(const uchar16_t &c)
Swaps the endianness of a 16-bit value.
Definition: irrUString.h:121
const u8 BOM_ENCODE_UTF32_BE[4]
Definition: irrUString.h:148
const u8 BOM_UTF32_LEN
Definition: irrUString.h:142
uchar32_t swapEndian32(const uchar32_t &c)
Swaps the endianness of a 32-bit value.
Definition: irrUString.h:128
ustring16< TAlloc > operator+(const ustring16< TAlloc > &left, const ustring16< TAlloc > &right)
Appends two ustring16s.
Definition: irrUString.h:3286
std::ostream & operator<<(std::ostream &out, const ustring16< TAlloc > &in)
Writes a ustring16 to an ostream.
Definition: irrUString.h:3842
ustring16< irrAllocator< uchar16_t > > ustring
Definition: irrUString.h:3281
u16 uchar16_t
Definition: irrUString.h:94
u32 uchar32_t
Definition: irrUString.h:93
u8 uchar8_t
Definition: irrUString.h:95
std::string p(std::string path)
Definition: test_filepath.cpp:59