30 #ifndef _CEGUIString_h_
31 #define _CEGUIString_h_
33 #include "CEGUIBase.h"
41 #define STR_QUICKBUFF_SIZE 32
80 mutable utf8* d_encodedbuff;
84 utf32 d_quickbuff[STR_QUICKBUFF_SIZE];
95 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
96 class const_iterator :
public std::iterator<std::random_access_iterator_tag, utf32>
98 class
const_iterator :
public std::iterator<std::random_access_iterator_tag, utf32, std::ptrdiff_t, const utf32*, const utf32&>
126 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
127 # pragma warning (push)
128 # pragma warning (disable : 4284)
135 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
136 # pragma warning (pop)
174 return temp += offset;
179 return *
this += -offset;
185 return temp -= offset;
190 return d_ptr - iter.d_ptr;
195 return *(*
this + offset);
200 return d_ptr == iter.d_ptr;
205 return !(*
this == iter);
210 return d_ptr < iter.d_ptr;
215 return (!(iter < *
this));
220 return (!(iter < *
this));
225 return (!(*
this < iter));
230 return iter + offset;
251 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
252 # pragma warning (push)
253 # pragma warning (disable : 4284)
261 #if defined(_MSC_VER) && (_MSC_VER <= 1200)
262 # pragma warning (pop)
293 this->d_ptr += offset;
300 return temp + offset;
305 return *
this += -offset;
311 return temp -= offset;
321 return *(*
this + offset);
326 return iter + offset;
335 #if defined(_MSC_VER) && ((_MSC_VER <= 1200) || ((_MSC_VER <= 1300) && defined(_STLPORT_VERSION)))
336 typedef std::reverse_iterator<const_iterator, const_pointer, const_reference, difference_type>
const_reverse_iterator;
345 #if defined(_MSC_VER) && ((_MSC_VER <= 1200) || ((_MSC_VER <= 1300) && defined(_STLPORT_VERSION)))
346 typedef std::reverse_iterator<iterator, pointer, reference, difference_type>
reverse_iterator;
359 bool operator() (
const String& a,
const String& b)
const
361 const size_t la = a.
length();
362 const size_t lb = b.
length();
364 return (memcmp(a.
ptr(), b.
ptr(), la*
sizeof(utf32)) < 0);
427 assign(str, str_idx, str_num);
480 assign(std_str, str_idx, str_num);
540 assign(utf8_str, chars_len);
564 assign(num, code_point);
587 append(iter_beg, iter_end);
630 assign(chars, chars_len);
668 bool empty(
void)
const
670 return (d_cplength == 0);
684 return (((
size_type)-1) /
sizeof(utf32));
702 return d_reserve - 1;
748 return compare(0, d_cplength, str);
782 if ((d_cplength < idx) || (str.d_cplength < str_idx))
783 throw std::out_of_range(
"Index is out of range for CEGUI::String");
785 if ((len == npos) || (idx + len > d_cplength))
786 len = d_cplength - idx;
788 if ((str_len == npos) || (str_idx + str_len > str.d_cplength))
789 str_len = str.d_cplength - str_idx;
791 int val = (len == 0) ? 0 : utf32_comp_utf32(&ptr()[idx], &str.
ptr()[str_idx], (len < str_len) ? len : str_len);
793 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_len) ? -1 : (len == str_len) ? 0 : 1;
816 int compare(
const std::string& std_str)
const
818 return compare(0, d_cplength, std_str);
857 if (d_cplength < idx)
858 throw std::out_of_range(
"Index is out of range for CEGUI::String");
860 if (std_str.size() < str_idx)
861 throw std::out_of_range(
"Index is out of range for std::string");
863 if ((len == npos) || (idx + len > d_cplength))
864 len = d_cplength - idx;
866 if ((str_len == npos) || (str_idx + str_len > std_str.size()))
867 str_len = (
size_type)std_str.size() - str_idx;
869 int val = (len == 0) ? 0 : utf32_comp_char(&ptr()[idx], &std_str.c_str()[str_idx], (len < str_len) ? len : str_len);
871 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_len) ? -1 : (len == str_len) ? 0 : 1;
896 int compare(
const utf8* utf8_str)
const
898 return compare(0, d_cplength, utf8_str, encoded_size(utf8_str));
933 return compare(idx, len, utf8_str, encoded_size(utf8_str));
971 if (d_cplength < idx)
972 throw std::out_of_range(
"Index is out of range for CEGUI::String");
974 if (str_cplen == npos)
975 throw std::length_error(
"Length for utf8 encoded string can not be 'npos'");
977 if ((len == npos) || (idx + len > d_cplength))
978 len = d_cplength - idx;
980 int val = (len == 0) ? 0 : utf32_comp_utf8(&ptr()[idx], utf8_str, (len < str_cplen) ? len : str_cplen);
982 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_cplen) ? -1 : (len == str_cplen) ? 0 : 1;
1001 int compare(
const char* cstr)
const
1003 return compare(0, d_cplength, cstr, strlen(cstr));
1032 return compare(idx, len, cstr, strlen(cstr));
1065 if (d_cplength < idx)
1066 throw std::out_of_range(
"Index is out of range for CEGUI::String");
1068 if (chars_len == npos)
1069 throw std::length_error(
"Length for char array can not be 'npos'");
1071 if ((len == npos) || (idx + len > d_cplength))
1072 len = d_cplength - idx;
1074 int val = (len == 0) ? 0 : utf32_comp_char(&ptr()[idx], chars, (len < chars_len) ? len : chars_len);
1076 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < chars_len) ? -1 : (len == chars_len) ? 0 : 1;
1099 return (ptr()[idx]);
1135 if (d_cplength <= idx)
1136 throw std::out_of_range(
"Index is out of range for CEGUI::String");
1155 if (d_cplength <= idx)
1156 throw std::out_of_range(
"Index is out of range for CEGUI::String");
1178 const char* c_str(
void)
const
1180 return (
const char*)build_utf8_buff();
1196 const utf8* data(
void)
const
1198 return build_utf8_buff();
1207 return (d_reserve > STR_QUICKBUFF_SIZE) ? d_buffer : d_quickbuff;
1214 const utf32* ptr(
void)
const
1216 return (d_reserve > STR_QUICKBUFF_SIZE) ? d_buffer : d_quickbuff;
1243 if (d_cplength < idx)
1244 throw std::out_of_range(
"Index is out of range for CEGUI::String");
1249 return encode(&ptr()[idx], buf, npos, len);
1273 using namespace std;
1275 if (d_cplength < idx)
1276 throw out_of_range(
"Index was out of range for CEGUI::String object");
1280 return encoded_size(&ptr()[idx], ceguimin(num, maxlen));
1321 if (str.d_cplength < str_idx)
1322 throw std::out_of_range(
"Index was out of range for CEGUI::String object");
1324 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
1325 str_num = str.d_cplength - str_idx;
1329 memcpy(ptr(), &str.
ptr()[str_idx], str_num *
sizeof(utf32));
1350 String& operator=(
const std::string& std_str)
1352 return assign(std_str);
1380 if (std_str.size() < str_idx)
1381 throw std::out_of_range(
"Index was out of range for std::string object");
1383 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
1391 ((*this)[str_num]) = static_cast<utf32>(static_cast<unsigned char>(std_str[str_num + str_idx]));
1417 return assign(utf8_str, utf_length(utf8_str));
1440 return assign(utf8_str, utf_length(utf8_str));
1466 if (str_num == npos)
1467 throw std::length_error(
"Length for utf8 encoded string can not be 'npos'");
1469 size_type enc_sze = encoded_size(utf8_str, str_num);
1472 encode(utf8_str, ptr(), d_reserve, str_num);
1489 return assign(1, code_point);
1510 throw std::length_error(
"Code point count can not be 'npos'");
1537 return assign(cstr, strlen(cstr));
1555 return assign(cstr, strlen(cstr));
1579 for (
size_type i = 0; i < chars_len; ++i)
1581 *pt++ =
static_cast<utf32
>(
static_cast<unsigned char>(*chars++));
1602 d_cplength = str.d_cplength;
1603 str.d_cplength = temp_len;
1606 d_reserve = str.d_reserve;
1607 str.d_reserve = temp_res;
1609 utf32* temp_buf = d_buffer;
1610 d_buffer = str.d_buffer;
1611 str.d_buffer = temp_buf;
1614 if (temp_res <= STR_QUICKBUFF_SIZE)
1616 utf32 temp_qbf[STR_QUICKBUFF_SIZE];
1618 memcpy(temp_qbf, d_quickbuff, STR_QUICKBUFF_SIZE *
sizeof(utf32));
1619 memcpy(d_quickbuff, str.d_quickbuff, STR_QUICKBUFF_SIZE *
sizeof(utf32));
1620 memcpy(str.d_quickbuff, temp_qbf, STR_QUICKBUFF_SIZE *
sizeof(utf32));
1666 if (str.d_cplength < str_idx)
1667 throw std::out_of_range(
"Index is out of range for CEGUI::String");
1669 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
1670 str_num = str.d_cplength - str_idx;
1672 grow(d_cplength + str_num);
1673 memcpy(&ptr()[d_cplength], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
1674 setlen(d_cplength + str_num);
1695 String& operator+=(
const std::string& std_str)
1697 return append(std_str);
1725 if (std_str.size() < str_idx)
1726 throw std::out_of_range(
"Index is out of range for std::string");
1728 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
1731 size_type newsze = d_cplength + str_num;
1734 utf32* pt = &ptr()[newsze-1];
1737 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_num]));
1764 return append(utf8_str, utf_length(utf8_str));
1787 return append(utf8_str, utf_length(utf8_str));
1815 throw std::length_error(
"Length for utf8 encoded string can not be 'npos'");
1817 size_type encsz = encoded_size(utf8_str, len);
1821 encode(utf8_str, &ptr()[d_cplength], encsz, len);
1842 return append(1, code_point);
1863 throw std::length_error(
"Code point count can not be 'npos'");
1868 utf32* p = &ptr()[d_cplength];
1890 void push_back(utf32 code_point)
1892 append(1, code_point);
1912 return replace(end(), end(), iter_beg, iter_end);
1930 return append(cstr, strlen(cstr));
1948 return append(cstr, strlen(cstr));
1969 if (chars_len == npos)
1970 throw std::length_error(
"Length for char array can not be 'npos'");
1972 size_type newsz = d_cplength + chars_len;
1976 utf32* pt = &ptr()[newsz-1];
1979 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
2008 return insert(idx, str, 0, npos);
2035 if ((d_cplength < idx) || (str.d_cplength < str_idx))
2036 throw std::out_of_range(
"Index is out of range for CEGUI::String");
2038 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
2039 str_num = str.d_cplength - str_idx;
2043 memmove(&ptr()[idx + str_num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2044 memcpy(&ptr()[idx], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
2072 return insert(idx, std_str, 0, npos);
2103 if (d_cplength < idx)
2104 throw std::out_of_range(
"Index is out of range for CEGUI::String");
2106 if (std_str.size() < str_idx)
2107 throw std::out_of_range(
"Index is out of range for std::string");
2109 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
2110 str_num = (
size_type)std_str.size() - str_idx;
2115 memmove(&ptr()[idx + str_num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2117 utf32* pt = &ptr()[idx + str_num - 1];
2120 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_idx + str_num]));
2151 return insert(idx, utf8_str, utf_length(utf8_str));
2181 if (d_cplength < idx)
2182 throw std::out_of_range(
"Index is out of range for CEGUI::String");
2185 throw std::length_error(
"Length of utf8 encoded string can not be 'npos'");
2187 size_type encsz = encoded_size(utf8_str, len);
2191 memmove(&ptr()[idx + encsz], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2192 encode(utf8_str, &ptr()[idx], encsz, len);
2219 if (d_cplength < idx)
2220 throw std::out_of_range(
"Index is out of range for CEGUI::String");
2223 throw std::length_error(
"Code point count can not be 'npos'");
2228 memmove(&ptr()[idx + num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2230 utf32* pt = &ptr()[idx + num - 1];
2260 insert(safe_iter_dif(pos, begin()), num, code_point);
2280 insert(pos, 1, code_point);
2304 replace(iter_pos, iter_pos, iter_beg, iter_end);
2326 return insert(idx, cstr, strlen(cstr));
2351 if (d_cplength < idx)
2352 throw std::out_of_range(
"Index is out of range for CEGUI::String");
2354 if (chars_len == npos)
2355 throw std::length_error(
"Length of char array can not be 'npos'");
2357 size_type newsz = d_cplength + chars_len;
2360 memmove(&ptr()[idx + chars_len], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2362 utf32* pt = &ptr()[idx + chars_len - 1];
2365 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
2416 return erase(idx, 1);
2436 if (d_cplength < idx)
2437 throw std::out_of_range(
"Index is out of range foe CEGUI::String");
2440 len = d_cplength - idx;
2444 memmove(&ptr()[idx], &ptr()[idx + len], (d_cplength - idx - len) *
sizeof(utf32));
2461 return erase(safe_iter_dif(pos, begin()), 1);
2479 return erase(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg));
2499 resize(num, utf32());
2519 if (num < d_cplength)
2525 append(num - d_cplength, code_point);
2554 return replace(idx, len, str, 0, npos);
2580 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), str, 0, npos);
2610 if ((d_cplength < idx) || (str.d_cplength < str_idx))
2611 throw std::out_of_range(
"Index is out of range for CEGUI::String");
2613 if (((str_idx + str_num) > str.d_cplength) || (str_num == npos))
2614 str_num = str.d_cplength - str_idx;
2616 if (((len + idx) > d_cplength) || (len == npos))
2617 len = d_cplength - idx;
2619 size_type newsz = d_cplength + str_num - len;
2623 if ((idx + len) < d_cplength)
2624 memmove(&ptr()[idx + str_num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2626 memcpy(&ptr()[idx], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
2658 return replace(idx, len, std_str, 0, npos);
2688 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), std_str, 0, npos);
2722 if (d_cplength < idx)
2723 throw std::out_of_range(
"Index is out of range for CEGUI::String");
2725 if (std_str.size() < str_idx)
2726 throw std::out_of_range(
"Index is out of range for std::string");
2728 if (((str_idx + str_num) > std_str.size()) || (str_num == npos))
2729 str_num = (
size_type)std_str.size() - str_idx;
2731 if (((len + idx) > d_cplength) || (len == npos))
2732 len = d_cplength - idx;
2734 size_type newsz = d_cplength + str_num - len;
2738 if ((idx + len) < d_cplength)
2739 memmove(&ptr()[idx + str_num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2741 utf32* pt = &ptr()[idx + str_num - 1];
2744 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_idx + str_num]));
2779 return replace(idx, len, utf8_str, utf_length(utf8_str));
2811 return replace(iter_beg, iter_end, utf8_str, utf_length(utf8_str));
2844 if (d_cplength < idx)
2845 throw std::out_of_range(
"Index is out of range for CEGUI::String");
2847 if (str_len == npos)
2848 throw std::length_error(
"Length for utf8 encoded string can not be 'npos'");
2850 if (((len + idx) > d_cplength) || (len == npos))
2851 len = d_cplength - idx;
2853 size_type encsz = encoded_size(utf8_str, str_len);
2854 size_type newsz = d_cplength + encsz - len;
2858 if ((idx + len) < d_cplength)
2859 memmove(&ptr()[idx + encsz], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2861 encode(utf8_str, &ptr()[idx], encsz, str_len);
2899 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), utf8_str, str_len);
2926 if (d_cplength < idx)
2927 throw std::out_of_range(
"Index is out of range for CEGUI::String");
2930 throw std::length_error(
"Code point count can not be 'npos'");
2932 if (((len + idx) > d_cplength) || (len == npos))
2933 len = d_cplength - idx;
2935 size_type newsz = d_cplength + num - len;
2939 if ((idx + len) < d_cplength)
2940 memmove(&ptr()[idx + num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2942 utf32* pt = &ptr()[idx + num - 1];
2978 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), num, code_point);
3008 if (iter_beg == iter_end)
3010 erase(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg));
3014 size_type str_len = safe_iter_dif(iter_newEnd, iter_newBeg);
3015 size_type idx = safe_iter_dif(iter_beg, begin());
3016 size_type len = safe_iter_dif(iter_end, iter_beg);
3018 if ((len + idx) > d_cplength)
3019 len = d_cplength - idx;
3021 size_type newsz = d_cplength + str_len - len;
3025 if ((idx + len) < d_cplength)
3026 memmove(&ptr()[idx + str_len], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
3028 memcpy(&ptr()[idx], iter_newBeg.d_ptr, str_len *
sizeof(utf32));
3057 return replace(idx, len, cstr, strlen(cstr));
3084 return replace(iter_beg, iter_end, cstr, strlen(cstr));
3112 if (d_cplength < idx)
3113 throw std::out_of_range(
"Index is out of range for CEGUI::String");
3115 if (chars_len == npos)
3116 throw std::length_error(
"Length for the char array can not be 'npos'");
3118 if (((len + idx) > d_cplength) || (len == npos))
3119 len = d_cplength - idx;
3121 size_type newsz = d_cplength + chars_len - len;
3125 if ((idx + len) < d_cplength)
3126 memmove(&ptr()[idx + chars_len], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
3128 utf32* pt = &ptr()[idx + chars_len - 1];
3131 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
3164 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), chars, chars_len);
3187 if (idx < d_cplength)
3189 const utf32* pt = &ptr()[idx];
3191 while (idx < d_cplength)
3193 if (*pt++ == code_point)
3220 if (idx >= d_cplength)
3221 idx = d_cplength - 1;
3225 const utf32* pt = &ptr()[idx];
3229 if (*pt-- == code_point)
3232 }
while (idx-- != 0);
3258 if ((str.d_cplength == 0) && (idx < d_cplength))
3261 if (idx < d_cplength)
3264 while (d_cplength - idx >= str.d_cplength)
3266 if (0 == compare(idx, str.d_cplength, str))
3293 if (str.d_cplength == 0)
3294 return (idx < d_cplength) ? idx : d_cplength;
3296 if (str.d_cplength <= d_cplength)
3298 if (idx > (d_cplength - str.d_cplength))
3299 idx = d_cplength - str.d_cplength;
3303 if (0 == compare(idx, str.d_cplength, str))
3306 }
while (idx-- != 0);
3333 std::string::size_type sze = std_str.size();
3335 if ((sze == 0) && (idx < d_cplength))
3338 if (idx < d_cplength)
3341 while (d_cplength - idx >= sze)
3343 if (0 == compare(idx, (
size_type)sze, std_str))
3374 std::string::size_type sze = std_str.size();
3377 return (idx < d_cplength) ? idx : d_cplength;
3379 if (sze <= d_cplength)
3381 if (idx > (d_cplength - sze))
3382 idx = d_cplength - sze;
3386 if (0 == compare(idx, (
size_type)sze, std_str))
3389 }
while (idx-- != 0);
3420 return find(utf8_str, idx, utf_length(utf8_str));
3447 return rfind(utf8_str, idx, utf_length(utf8_str));
3477 if (str_len == npos)
3478 throw std::length_error(
"Length for utf8 encoded string can not be 'npos'");
3480 size_type sze = encoded_size(utf8_str, str_len);
3482 if ((sze == 0) && (idx < d_cplength))
3485 if (idx < d_cplength)
3488 while (d_cplength - idx >= sze)
3490 if (0 == compare(idx, sze, utf8_str, sze))
3528 if (str_len == npos)
3529 throw std::length_error(
"Length for utf8 encoded string can not be 'npos'");
3531 size_type sze = encoded_size(utf8_str, str_len);
3534 return (idx < d_cplength) ? idx : d_cplength;
3536 if (sze <= d_cplength)
3538 if (idx > (d_cplength - sze))
3539 idx = d_cplength - sze;
3543 if (0 == compare(idx, sze, utf8_str, sze))
3546 }
while (idx-- != 0);
3572 return find(cstr, idx, strlen(cstr));
3594 return rfind(cstr, idx, strlen(cstr));
3619 if (chars_len == npos)
3620 throw std::length_error(
"Length for char array can not be 'npos'");
3622 if ((chars_len == 0) && (idx < d_cplength))
3625 if (idx < d_cplength)
3628 while (d_cplength - idx >= chars_len)
3630 if (0 == compare(idx, chars_len, chars, chars_len))
3663 if (chars_len == npos)
3664 throw std::length_error(
"Length for char array can not be 'npos'");
3667 return (idx < d_cplength) ? idx : d_cplength;
3669 if (chars_len <= d_cplength)
3671 if (idx > (d_cplength - chars_len))
3672 idx = d_cplength - chars_len;
3676 if (0 == compare(idx, chars_len, chars, chars_len))
3679 }
while (idx-- != 0);
3706 if (idx < d_cplength)
3708 const utf32* pt = &ptr()[idx];
3712 if (npos != str.
find(*pt++))
3715 }
while (++idx != d_cplength);
3738 if (idx < d_cplength)
3740 const utf32* pt = &ptr()[idx];
3744 if (npos == str.
find(*pt++))
3747 }
while (++idx != d_cplength);
3775 if (idx < d_cplength)
3777 const utf32* pt = &ptr()[idx];
3781 if (npos != find_codepoint(std_str, *pt++))
3784 }
while (++idx != d_cplength);
3811 if (idx < d_cplength)
3813 const utf32* pt = &ptr()[idx];
3817 if (npos == find_codepoint(std_str, *pt++))
3820 }
while (++idx != d_cplength);
3852 return find_first_of(utf8_str, idx, utf_length(utf8_str));
3879 return find_first_not_of(utf8_str, idx, utf_length(utf8_str));
3909 if (str_len == npos)
3910 throw std::length_error(
"Length for utf8 encoded string can not be 'npos'");
3912 if (idx < d_cplength)
3914 size_type encsze = encoded_size(utf8_str, str_len);
3916 const utf32* pt = &ptr()[idx];
3920 if (npos != find_codepoint(utf8_str, encsze, *pt++))
3923 }
while (++idx != d_cplength);
3957 if (str_len == npos)
3958 throw std::length_error(
"Length for utf8 encoded string can not be 'npos'");
3960 if (idx < d_cplength)
3962 size_type encsze = encoded_size(utf8_str, str_len);
3964 const utf32* pt = &ptr()[idx];
3968 if (npos == find_codepoint(utf8_str, encsze, *pt++))
3971 }
while (++idx != d_cplength);
3995 return find(code_point, idx);
4016 if (idx < d_cplength)
4020 if ((*
this)[idx] != code_point)
4023 }
while(idx++ < d_cplength);
4049 return find_first_of(cstr, idx, strlen(cstr));
4071 return find_first_not_of(cstr, idx, strlen(cstr));
4096 if (chars_len == npos)
4097 throw std::length_error(
"Length for char array can not be 'npos'");
4099 if (idx < d_cplength)
4101 const utf32* pt = &ptr()[idx];
4105 if (npos != find_codepoint(chars, chars_len, *pt++))
4108 }
while (++idx != d_cplength);
4137 if (chars_len == npos)
4138 throw std::length_error(
"Length for char array can not be 'npos'");
4140 if (idx < d_cplength)
4142 const utf32* pt = &ptr()[idx];
4146 if (npos == find_codepoint(chars, chars_len, *pt++))
4149 }
while (++idx != d_cplength);
4178 if (idx >= d_cplength)
4179 idx = d_cplength - 1;
4181 const utf32* pt = &ptr()[idx];
4185 if (npos != str.
find(*pt--))
4188 }
while (idx-- != 0);
4213 if (idx >= d_cplength)
4214 idx = d_cplength - 1;
4216 const utf32* pt = &ptr()[idx];
4220 if (npos == str.
find(*pt--))
4223 }
while (idx-- != 0);
4253 if (idx >= d_cplength)
4254 idx = d_cplength - 1;
4256 const utf32* pt = &ptr()[idx];
4260 if (npos != find_codepoint(std_str, *pt--))
4263 }
while (idx-- != 0);
4292 if (idx >= d_cplength)
4293 idx = d_cplength - 1;
4295 const utf32* pt = &ptr()[idx];
4299 if (npos == find_codepoint(std_str, *pt--))
4302 }
while (idx-- != 0);
4334 return find_last_of(utf8_str, idx, utf_length(utf8_str));
4361 return find_last_not_of(utf8_str, idx, utf_length(utf8_str));
4391 if (str_len == npos)
4392 throw std::length_error(
"Length for utf8 encoded string can not be 'npos'");
4396 if (idx >= d_cplength)
4397 idx = d_cplength - 1;
4399 size_type encsze = encoded_size(utf8_str, str_len);
4401 const utf32* pt = &ptr()[idx];
4405 if (npos != find_codepoint(utf8_str, encsze, *pt--))
4408 }
while (idx-- != 0);
4442 if (str_len == npos)
4443 throw std::length_error(
"Length for utf8 encoded string can not be 'npos'");
4447 if (idx >= d_cplength)
4448 idx = d_cplength - 1;
4450 size_type encsze = encoded_size(utf8_str, str_len);
4452 const utf32* pt = &ptr()[idx];
4456 if (npos == find_codepoint(utf8_str, encsze, *pt--))
4459 }
while (idx-- != 0);
4483 return rfind(code_point, idx);
4504 if (idx >= d_cplength)
4505 idx = d_cplength - 1;
4509 if ((*
this)[idx] != code_point)
4512 }
while(idx-- != 0);
4538 return find_last_of(cstr, idx, strlen(cstr));
4560 return find_last_not_of(cstr, idx, strlen(cstr));
4585 if (chars_len == npos)
4586 throw std::length_error(
"Length for char array can not be 'npos'");
4590 if (idx >= d_cplength)
4591 idx = d_cplength - 1;
4593 const utf32* pt = &ptr()[idx];
4597 if (npos != find_codepoint(chars, chars_len, *pt--))
4600 }
while (idx-- != 0);
4629 if (chars_len == npos)
4630 throw std::length_error(
"Length for char array can not be 'npos'");
4634 if (idx >= d_cplength)
4635 idx = d_cplength - 1;
4637 const utf32* pt = &ptr()[idx];
4641 if (npos == find_codepoint(chars, chars_len, *pt--))
4644 }
while (idx-- != 0);
4672 if (d_cplength < idx)
4673 throw std::out_of_range(
"Index is out of range for this CEGUI::String");
4675 return String(*
this, idx, len);
4714 return iterator(&ptr()[d_cplength]);
4786 bool grow(size_type new_size);
4792 void setlen(size_type len)
4795 ptr()[len] = (utf32)(0);
4801 d_reserve = STR_QUICKBUFF_SIZE;
4803 d_encodedbufflen = 0;
4804 d_encodeddatlen = 0;
4810 bool inside(utf32* inptr)
4812 if (inptr < ptr() || ptr() + d_cplength <= inptr)
4819 size_type safe_iter_dif(
const const_iterator& iter1,
const const_iterator& iter2)
const
4821 return (iter1.d_ptr == 0) ? 0 : (iter1 - iter2);
4829 size_type encode(
const utf32* src, utf8* dest, size_type dest_len, size_type src_len = 0)
const
4834 src_len = utf_length(src);
4837 size_type destCapacity = dest_len;
4840 for (uint idx = 0; idx < src_len; ++idx)
4842 utf32 cp = src[idx];
4845 if (destCapacity < encoded_size(cp))
4855 else if (cp < 0x0800)
4857 *dest++ = (utf8)((cp >> 6) | 0xC0);
4858 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4861 else if (cp < 0x10000)
4863 *dest++ = (utf8)((cp >> 12) | 0xE0);
4864 *dest++ = (utf8)(((cp >> 6) & 0x3F) | 0x80);
4865 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4870 *dest++ = (utf8)((cp >> 18) | 0xF0);
4871 *dest++ = (utf8)(((cp >> 12) & 0x3F) | 0x80);
4872 *dest++ = (utf8)(((cp >> 6) & 0x3F) | 0x80);
4873 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4879 return dest_len - destCapacity;
4882 size_type encode(
const utf8* src, utf32* dest, size_type dest_len, size_type src_len = 0)
const
4887 src_len = utf_length(src);
4890 size_type destCapacity = dest_len;
4893 for (uint idx = 0; ((idx < src_len) && (destCapacity > 0));)
4896 utf8 cu = src[idx++];
4904 cp = ((cu & 0x1F) << 6);
4905 cp |= (src[idx++] & 0x3F);
4909 cp = ((cu & 0x0F) << 12);
4910 cp |= ((src[idx++] & 0x3F) << 6);
4911 cp |= (src[idx++] & 0x3F);
4915 cp = ((cu & 0x07) << 18);
4916 cp |= ((src[idx++] & 0x3F) << 12);
4917 cp |= ((src[idx++] & 0x3F) << 6);
4918 cp |= (src[idx++] & 0x3F);
4925 return dest_len - destCapacity;
4929 size_type encoded_size(utf32 code_point)
const
4931 if (code_point < 0x80)
4933 else if (code_point < 0x0800)
4935 else if (code_point < 0x10000)
4942 size_type encoded_size(
const utf32* buf)
const
4944 return encoded_size(buf, utf_length(buf));
4948 size_type encoded_size(
const utf32* buf, size_type len)
const
4950 size_type count = 0;
4954 count += encoded_size(*buf++);
4961 size_type encoded_size(
const utf8* buf)
const
4963 return encoded_size(buf, utf_length(buf));
4967 size_type encoded_size(
const utf8* buf, size_type len)
const
4970 size_type count = 0;
4980 else if (tcp < 0xE0)
4985 else if (tcp < 0xF0)
5002 size_type utf_length(
const utf8* utf8_str)
const
5012 size_type utf_length(
const utf32* utf32_str)
const
5015 while (*utf32_str++)
5022 utf8* build_utf8_buff(
void)
const;
5025 int utf32_comp_utf32(
const utf32* buf1,
const utf32* buf2, size_type cp_count)
const
5030 while ((--cp_count) && (*buf1 == *buf2))
5033 return *buf1 - *buf2;
5037 int utf32_comp_char(
const utf32* buf1,
const char* buf2, size_type cp_count)
const
5042 while ((--cp_count) && (*buf1 == static_cast<utf32>(static_cast<unsigned char>(*buf2))))
5045 return *buf1 -
static_cast<utf32
>(
static_cast<unsigned char>(*buf2));
5049 int utf32_comp_utf8(
const utf32* buf1,
const utf8* buf2, size_type cp_count)
const
5067 cp = ((cu & 0x1F) << 6);
5068 cp |= (*buf2++ & 0x3F);
5072 cp = ((cu & 0x0F) << 12);
5073 cp |= ((*buf2++ & 0x3F) << 6);
5074 cp |= (*buf2++ & 0x3F);
5078 cp = ((cu & 0x07) << 18);
5079 cp |= ((*buf2++ & 0x3F) << 12);
5080 cp |= ((*buf2++ & 0x3F) << 6);
5081 cp |= (*buf2++ & 0x3F);
5084 }
while ((*buf1++ == cp) && (--cp_count));
5086 return (*--buf1) - cp;
5090 size_type find_codepoint(
const std::string& str, utf32 code_point)
const
5092 size_type idx = 0, sze = (size_type)str.size();
5096 if (code_point == static_cast<utf32>(static_cast<unsigned char>(str[idx])))
5106 size_type find_codepoint(
const utf8* str, size_type len, utf32 code_point)
const
5113 while (idx != len) {
5122 cp = ((cu & 0x1F) << 6);
5123 cp |= (*str++ & 0x3F);
5127 cp = ((cu & 0x0F) << 12);
5128 cp |= ((*str++ & 0x3F) << 6);
5129 cp |= (*str++ & 0x3F);
5133 cp = ((cu & 0x07) << 18);
5134 cp |= ((*str++ & 0x3F) << 12);
5135 cp |= ((*str++ & 0x3F) << 6);
5136 cp |= (*str++ & 0x3F);
5139 if (code_point == cp)
5150 size_type find_codepoint(
const char* chars, size_type chars_len, utf32 code_point)
const
5152 for (size_type idx = 0; idx != chars_len; ++idx)
5154 if (code_point == static_cast<utf32>(static_cast<unsigned char>(chars[idx])))
5171 bool CEGUIEXPORT
operator==(
const String& str1,
const String& str2);
5177 bool CEGUIEXPORT
operator==(
const String& str,
const std::string& std_str);
5183 bool CEGUIEXPORT
operator==(
const std::string& std_str,
const String& str);
5189 bool CEGUIEXPORT
operator==(
const String& str,
const utf8* utf8_str);
5195 bool CEGUIEXPORT
operator==(
const utf8* utf8_str,
const String& str);
5201 bool CEGUIEXPORT
operator!=(
const String& str1,
const String& str2);
5207 bool CEGUIEXPORT
operator!=(
const String& str,
const std::string& std_str);
5213 bool CEGUIEXPORT
operator!=(
const std::string& std_str,
const String& str);
5219 bool CEGUIEXPORT
operator!=(
const String& str,
const utf8* utf8_str);
5225 bool CEGUIEXPORT
operator!=(
const utf8* utf8_str,
const String& str);
5231 bool CEGUIEXPORT
operator<(
const String& str1,
const String& str2);
5237 bool CEGUIEXPORT
operator<(
const String& str,
const std::string& std_str);
5243 bool CEGUIEXPORT
operator<(
const std::string& std_str,
const String& str);
5249 bool CEGUIEXPORT
operator<(
const String& str,
const utf8* utf8_str);
5255 bool CEGUIEXPORT
operator<(
const utf8* utf8_str,
const String& str);
5261 bool CEGUIEXPORT
operator>(
const String& str1,
const String& str2);
5267 bool CEGUIEXPORT
operator>(
const String& str,
const std::string& std_str);
5273 bool CEGUIEXPORT
operator>(
const std::string& std_str,
const String& str);
5279 bool CEGUIEXPORT
operator>(
const String& str,
const utf8* utf8_str);
5285 bool CEGUIEXPORT
operator>(
const utf8* utf8_str,
const String& str);
5291 bool CEGUIEXPORT
operator<=(
const String& str1,
const String& str2);
5297 bool CEGUIEXPORT
operator<=(
const String& str,
const std::string& std_str);
5303 bool CEGUIEXPORT
operator<=(
const std::string& std_str,
const String& str);
5309 bool CEGUIEXPORT
operator<=(
const String& str,
const utf8* utf8_str);
5315 bool CEGUIEXPORT
operator<=(
const utf8* utf8_str,
const String& str);
5321 bool CEGUIEXPORT
operator>=(
const String& str1,
const String& str2);
5327 bool CEGUIEXPORT
operator>=(
const String& str,
const std::string& std_str);
5333 bool CEGUIEXPORT
operator>=(
const std::string& std_str,
const String& str);
5339 bool CEGUIEXPORT
operator>=(
const String& str,
const utf8* utf8_str);
5345 bool CEGUIEXPORT
operator>=(
const utf8* utf8_str,
const String& str);
5351 bool CEGUIEXPORT
operator==(
const String& str,
const char* c_str);
5357 bool CEGUIEXPORT
operator==(
const char* c_str,
const String& str);
5363 bool CEGUIEXPORT
operator!=(
const String& str,
const char* c_str);
5369 bool CEGUIEXPORT
operator!=(
const char* c_str,
const String& str);
5375 bool CEGUIEXPORT
operator<(
const String& str,
const char* c_str);
5381 bool CEGUIEXPORT
operator<(
const char* c_str,
const String& str);
5387 bool CEGUIEXPORT
operator>(
const String& str,
const char* c_str);
5393 bool CEGUIEXPORT
operator>(
const char* c_str,
const String& str);
5399 bool CEGUIEXPORT
operator<=(
const String& str,
const char* c_str);
5405 bool CEGUIEXPORT
operator<=(
const char* c_str,
const String& str);
5411 bool CEGUIEXPORT
operator>=(
const String& str,
const char* c_str);
5417 bool CEGUIEXPORT
operator>=(
const char* c_str,
const String& str);
5437 String CEGUIEXPORT
operator+(
const String& str1,
const String& str2);
5454 String CEGUIEXPORT
operator+(
const String& str,
const std::string& std_str);
5471 String CEGUIEXPORT
operator+(
const std::string& std_str,
const String& str);
5488 String CEGUIEXPORT
operator+(
const String& str,
const utf8* utf8_str);
5505 String CEGUIEXPORT
operator+(
const utf8* utf8_str,
const String& str);
5522 String CEGUIEXPORT
operator+(
const String& str, utf32 code_point);
5539 String CEGUIEXPORT
operator+(utf32 code_point,
const String& str);
5556 String CEGUIEXPORT
operator+(
const String& str,
const char* c_str);
5573 String CEGUIEXPORT
operator+(
const char* c_str,
const String& str);
5579 CEGUIEXPORT std::ostream& operator<<(std::ostream& s,
const String& str);
5598 void CEGUIEXPORT
swap(String& str1, String& str2);
5604 #endif // end of guard _CEGUIString_h_