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 CEGUI_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 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
860 if (std_str.size() < str_idx)
861 CEGUI_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 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
974 if (str_cplen == npos)
975 CEGUI_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 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1068 if (chars_len == npos)
1069 CEGUI_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 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1155 if (d_cplength <= idx)
1156 CEGUI_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 CEGUI_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 CEGUI_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 CEGUI_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 CEGUI_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))
1384 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 CEGUI_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 CEGUI_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 CEGUI_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 CEGUI_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))
1729 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 CEGUI_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 CEGUI_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 CEGUI_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 CEGUI_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 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2106 if (std_str.size() < str_idx)
2107 CEGUI_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 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2185 CEGUI_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 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2223 CEGUI_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 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2354 if (chars_len == npos)
2355 CEGUI_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);
2440 if (d_cplength <= idx)
2441 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2444 len = d_cplength - idx;
2448 memmove(&ptr()[idx], &ptr()[idx + len], (d_cplength - idx - len) *
sizeof(utf32));
2465 return erase(safe_iter_dif(pos, begin()), 1);
2483 return erase(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg));
2503 resize(num, utf32());
2523 if (num < d_cplength)
2529 append(num - d_cplength, code_point);
2558 return replace(idx, len, str, 0, npos);
2584 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), str, 0, npos);
2614 if ((d_cplength < idx) || (str.d_cplength < str_idx))
2615 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2617 if (((str_idx + str_num) > str.d_cplength) || (str_num == npos))
2618 str_num = str.d_cplength - str_idx;
2620 if (((len + idx) > d_cplength) || (len == npos))
2621 len = d_cplength - idx;
2623 size_type newsz = d_cplength + str_num - len;
2627 if ((idx + len) < d_cplength)
2628 memmove(&ptr()[idx + str_num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2630 memcpy(&ptr()[idx], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
2662 return replace(idx, len, std_str, 0, npos);
2692 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), std_str, 0, npos);
2726 if (d_cplength < idx)
2727 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2729 if (std_str.size() < str_idx)
2730 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
2732 if (((str_idx + str_num) > std_str.size()) || (str_num == npos))
2733 str_num = (
size_type)std_str.size() - str_idx;
2735 if (((len + idx) > d_cplength) || (len == npos))
2736 len = d_cplength - idx;
2738 size_type newsz = d_cplength + str_num - len;
2742 if ((idx + len) < d_cplength)
2743 memmove(&ptr()[idx + str_num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2745 utf32* pt = &ptr()[idx + str_num - 1];
2748 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_idx + str_num]));
2783 return replace(idx, len, utf8_str, utf_length(utf8_str));
2815 return replace(iter_beg, iter_end, utf8_str, utf_length(utf8_str));
2848 if (d_cplength < idx)
2849 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2851 if (str_len == npos)
2852 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
2854 if (((len + idx) > d_cplength) || (len == npos))
2855 len = d_cplength - idx;
2857 size_type encsz = encoded_size(utf8_str, str_len);
2858 size_type newsz = d_cplength + encsz - len;
2862 if ((idx + len) < d_cplength)
2863 memmove(&ptr()[idx + encsz], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2865 encode(utf8_str, &ptr()[idx], encsz, str_len);
2903 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), utf8_str, str_len);
2930 if (d_cplength < idx)
2931 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2934 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
2936 if (((len + idx) > d_cplength) || (len == npos))
2937 len = d_cplength - idx;
2939 size_type newsz = d_cplength + num - len;
2943 if ((idx + len) < d_cplength)
2944 memmove(&ptr()[idx + num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2946 utf32* pt = &ptr()[idx + num - 1];
2982 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), num, code_point);
3012 if (iter_newBeg == iter_newEnd)
3014 erase(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg));
3018 size_type str_len = safe_iter_dif(iter_newEnd, iter_newBeg);
3019 size_type idx = safe_iter_dif(iter_beg, begin());
3020 size_type len = safe_iter_dif(iter_end, iter_beg);
3022 if ((len + idx) > d_cplength)
3023 len = d_cplength - idx;
3025 size_type newsz = d_cplength + str_len - len;
3029 if ((idx + len) < d_cplength)
3030 memmove(&ptr()[idx + str_len], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
3032 memcpy(&ptr()[idx], iter_newBeg.d_ptr, str_len *
sizeof(utf32));
3061 return replace(idx, len, cstr, strlen(cstr));
3088 return replace(iter_beg, iter_end, cstr, strlen(cstr));
3116 if (d_cplength < idx)
3117 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
3119 if (chars_len == npos)
3120 CEGUI_THROW(std::length_error(
"Length for the char array can not be 'npos'"));
3122 if (((len + idx) > d_cplength) || (len == npos))
3123 len = d_cplength - idx;
3125 size_type newsz = d_cplength + chars_len - len;
3129 if ((idx + len) < d_cplength)
3130 memmove(&ptr()[idx + chars_len], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
3132 utf32* pt = &ptr()[idx + chars_len - 1];
3135 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
3168 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), chars, chars_len);
3191 if (idx < d_cplength)
3193 const utf32* pt = &ptr()[idx];
3195 while (idx < d_cplength)
3197 if (*pt++ == code_point)
3224 if (idx >= d_cplength)
3225 idx = d_cplength - 1;
3229 const utf32* pt = &ptr()[idx];
3233 if (*pt-- == code_point)
3236 }
while (idx-- != 0);
3262 if ((str.d_cplength == 0) && (idx < d_cplength))
3265 if (idx < d_cplength)
3268 while (d_cplength - idx >= str.d_cplength)
3270 if (0 == compare(idx, str.d_cplength, str))
3297 if (str.d_cplength == 0)
3298 return (idx < d_cplength) ? idx : d_cplength;
3300 if (str.d_cplength <= d_cplength)
3302 if (idx > (d_cplength - str.d_cplength))
3303 idx = d_cplength - str.d_cplength;
3307 if (0 == compare(idx, str.d_cplength, str))
3310 }
while (idx-- != 0);
3337 std::string::size_type sze = std_str.size();
3339 if ((sze == 0) && (idx < d_cplength))
3342 if (idx < d_cplength)
3345 while (d_cplength - idx >= sze)
3347 if (0 == compare(idx, (
size_type)sze, std_str))
3378 std::string::size_type sze = std_str.size();
3381 return (idx < d_cplength) ? idx : d_cplength;
3383 if (sze <= d_cplength)
3385 if (idx > (d_cplength - sze))
3386 idx = d_cplength - sze;
3390 if (0 == compare(idx, (
size_type)sze, std_str))
3393 }
while (idx-- != 0);
3424 return find(utf8_str, idx, utf_length(utf8_str));
3451 return rfind(utf8_str, idx, utf_length(utf8_str));
3481 if (str_len == npos)
3482 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3484 size_type sze = encoded_size(utf8_str, str_len);
3486 if ((sze == 0) && (idx < d_cplength))
3489 if (idx < d_cplength)
3492 while (d_cplength - idx >= sze)
3494 if (0 == compare(idx, sze, utf8_str, sze))
3532 if (str_len == npos)
3533 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3535 size_type sze = encoded_size(utf8_str, str_len);
3538 return (idx < d_cplength) ? idx : d_cplength;
3540 if (sze <= d_cplength)
3542 if (idx > (d_cplength - sze))
3543 idx = d_cplength - sze;
3547 if (0 == compare(idx, sze, utf8_str, sze))
3550 }
while (idx-- != 0);
3576 return find(cstr, idx, strlen(cstr));
3598 return rfind(cstr, idx, strlen(cstr));
3623 if (chars_len == npos)
3624 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
3626 if ((chars_len == 0) && (idx < d_cplength))
3629 if (idx < d_cplength)
3632 while (d_cplength - idx >= chars_len)
3634 if (0 == compare(idx, chars_len, chars, chars_len))
3667 if (chars_len == npos)
3668 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
3671 return (idx < d_cplength) ? idx : d_cplength;
3673 if (chars_len <= d_cplength)
3675 if (idx > (d_cplength - chars_len))
3676 idx = d_cplength - chars_len;
3680 if (0 == compare(idx, chars_len, chars, chars_len))
3683 }
while (idx-- != 0);
3710 if (idx < d_cplength)
3712 const utf32* pt = &ptr()[idx];
3716 if (npos != str.
find(*pt++))
3719 }
while (++idx != d_cplength);
3742 if (idx < d_cplength)
3744 const utf32* pt = &ptr()[idx];
3748 if (npos == str.
find(*pt++))
3751 }
while (++idx != d_cplength);
3779 if (idx < d_cplength)
3781 const utf32* pt = &ptr()[idx];
3785 if (npos != find_codepoint(std_str, *pt++))
3788 }
while (++idx != d_cplength);
3815 if (idx < d_cplength)
3817 const utf32* pt = &ptr()[idx];
3821 if (npos == find_codepoint(std_str, *pt++))
3824 }
while (++idx != d_cplength);
3856 return find_first_of(utf8_str, idx, utf_length(utf8_str));
3883 return find_first_not_of(utf8_str, idx, utf_length(utf8_str));
3913 if (str_len == npos)
3914 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3916 if (idx < d_cplength)
3918 size_type encsze = encoded_size(utf8_str, str_len);
3920 const utf32* pt = &ptr()[idx];
3924 if (npos != find_codepoint(utf8_str, encsze, *pt++))
3927 }
while (++idx != d_cplength);
3961 if (str_len == npos)
3962 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3964 if (idx < d_cplength)
3966 size_type encsze = encoded_size(utf8_str, str_len);
3968 const utf32* pt = &ptr()[idx];
3972 if (npos == find_codepoint(utf8_str, encsze, *pt++))
3975 }
while (++idx != d_cplength);
3999 return find(code_point, idx);
4020 if (idx < d_cplength)
4024 if ((*
this)[idx] != code_point)
4027 }
while(idx++ < d_cplength);
4053 return find_first_of(cstr, idx, strlen(cstr));
4075 return find_first_not_of(cstr, idx, strlen(cstr));
4100 if (chars_len == npos)
4101 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4103 if (idx < d_cplength)
4105 const utf32* pt = &ptr()[idx];
4109 if (npos != find_codepoint(chars, chars_len, *pt++))
4112 }
while (++idx != d_cplength);
4141 if (chars_len == npos)
4142 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4144 if (idx < d_cplength)
4146 const utf32* pt = &ptr()[idx];
4150 if (npos == find_codepoint(chars, chars_len, *pt++))
4153 }
while (++idx != d_cplength);
4182 if (idx >= d_cplength)
4183 idx = d_cplength - 1;
4185 const utf32* pt = &ptr()[idx];
4189 if (npos != str.
find(*pt--))
4192 }
while (idx-- != 0);
4217 if (idx >= d_cplength)
4218 idx = d_cplength - 1;
4220 const utf32* pt = &ptr()[idx];
4224 if (npos == str.
find(*pt--))
4227 }
while (idx-- != 0);
4257 if (idx >= d_cplength)
4258 idx = d_cplength - 1;
4260 const utf32* pt = &ptr()[idx];
4264 if (npos != find_codepoint(std_str, *pt--))
4267 }
while (idx-- != 0);
4296 if (idx >= d_cplength)
4297 idx = d_cplength - 1;
4299 const utf32* pt = &ptr()[idx];
4303 if (npos == find_codepoint(std_str, *pt--))
4306 }
while (idx-- != 0);
4338 return find_last_of(utf8_str, idx, utf_length(utf8_str));
4365 return find_last_not_of(utf8_str, idx, utf_length(utf8_str));
4395 if (str_len == npos)
4396 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
4400 if (idx >= d_cplength)
4401 idx = d_cplength - 1;
4403 size_type encsze = encoded_size(utf8_str, str_len);
4405 const utf32* pt = &ptr()[idx];
4409 if (npos != find_codepoint(utf8_str, encsze, *pt--))
4412 }
while (idx-- != 0);
4446 if (str_len == npos)
4447 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
4451 if (idx >= d_cplength)
4452 idx = d_cplength - 1;
4454 size_type encsze = encoded_size(utf8_str, str_len);
4456 const utf32* pt = &ptr()[idx];
4460 if (npos == find_codepoint(utf8_str, encsze, *pt--))
4463 }
while (idx-- != 0);
4487 return rfind(code_point, idx);
4508 if (idx >= d_cplength)
4509 idx = d_cplength - 1;
4513 if ((*
this)[idx] != code_point)
4516 }
while(idx-- != 0);
4542 return find_last_of(cstr, idx, strlen(cstr));
4564 return find_last_not_of(cstr, idx, strlen(cstr));
4589 if (chars_len == npos)
4590 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4594 if (idx >= d_cplength)
4595 idx = d_cplength - 1;
4597 const utf32* pt = &ptr()[idx];
4601 if (npos != find_codepoint(chars, chars_len, *pt--))
4604 }
while (idx-- != 0);
4633 if (chars_len == npos)
4634 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4638 if (idx >= d_cplength)
4639 idx = d_cplength - 1;
4641 const utf32* pt = &ptr()[idx];
4645 if (npos == find_codepoint(chars, chars_len, *pt--))
4648 }
while (idx-- != 0);
4676 if (d_cplength < idx)
4677 CEGUI_THROW(std::out_of_range(
"Index is out of range for this CEGUI::String"));
4679 return String(*
this, idx, len);
4718 return iterator(&ptr()[d_cplength]);
4790 bool grow(size_type new_size);
4796 void setlen(size_type len)
4799 ptr()[len] = (utf32)(0);
4805 d_reserve = STR_QUICKBUFF_SIZE;
4807 d_encodedbufflen = 0;
4808 d_encodeddatlen = 0;
4814 bool inside(utf32* inptr)
4816 if (inptr < ptr() || ptr() + d_cplength <= inptr)
4823 size_type safe_iter_dif(
const const_iterator& iter1,
const const_iterator& iter2)
const
4825 return (iter1.d_ptr == 0) ? 0 : (iter1 - iter2);
4833 size_type encode(
const utf32* src, utf8* dest, size_type dest_len, size_type src_len = 0)
const
4838 src_len = utf_length(src);
4841 size_type destCapacity = dest_len;
4844 for (uint idx = 0; idx < src_len; ++idx)
4846 utf32 cp = src[idx];
4849 if (destCapacity < encoded_size(cp))
4859 else if (cp < 0x0800)
4861 *dest++ = (utf8)((cp >> 6) | 0xC0);
4862 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4865 else if (cp < 0x10000)
4867 *dest++ = (utf8)((cp >> 12) | 0xE0);
4868 *dest++ = (utf8)(((cp >> 6) & 0x3F) | 0x80);
4869 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4874 *dest++ = (utf8)((cp >> 18) | 0xF0);
4875 *dest++ = (utf8)(((cp >> 12) & 0x3F) | 0x80);
4876 *dest++ = (utf8)(((cp >> 6) & 0x3F) | 0x80);
4877 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4883 return dest_len - destCapacity;
4886 size_type encode(
const utf8* src, utf32* dest, size_type dest_len, size_type src_len = 0)
const
4891 src_len = utf_length(src);
4894 size_type destCapacity = dest_len;
4897 for (uint idx = 0; ((idx < src_len) && (destCapacity > 0));)
4900 utf8 cu = src[idx++];
4908 cp = ((cu & 0x1F) << 6);
4909 cp |= (src[idx++] & 0x3F);
4913 cp = ((cu & 0x0F) << 12);
4914 cp |= ((src[idx++] & 0x3F) << 6);
4915 cp |= (src[idx++] & 0x3F);
4919 cp = ((cu & 0x07) << 18);
4920 cp |= ((src[idx++] & 0x3F) << 12);
4921 cp |= ((src[idx++] & 0x3F) << 6);
4922 cp |= (src[idx++] & 0x3F);
4929 return dest_len - destCapacity;
4933 size_type encoded_size(utf32 code_point)
const
4935 if (code_point < 0x80)
4937 else if (code_point < 0x0800)
4939 else if (code_point < 0x10000)
4946 size_type encoded_size(
const utf32* buf)
const
4948 return encoded_size(buf, utf_length(buf));
4952 size_type encoded_size(
const utf32* buf, size_type len)
const
4954 size_type count = 0;
4958 count += encoded_size(*buf++);
4965 size_type encoded_size(
const utf8* buf)
const
4967 return encoded_size(buf, utf_length(buf));
4971 size_type encoded_size(
const utf8* buf, size_type len)
const
4974 size_type count = 0;
4985 else if (tcp < 0xE0)
4990 else if (tcp < 0xF0)
5011 size_type utf_length(
const utf8* utf8_str)
const
5021 size_type utf_length(
const utf32* utf32_str)
const
5024 while (*utf32_str++)
5031 utf8* build_utf8_buff(
void)
const;
5034 int utf32_comp_utf32(
const utf32* buf1,
const utf32* buf2, size_type cp_count)
const
5039 while ((--cp_count) && (*buf1 == *buf2))
5042 return *buf1 - *buf2;
5046 int utf32_comp_char(
const utf32* buf1,
const char* buf2, size_type cp_count)
const
5051 while ((--cp_count) && (*buf1 == static_cast<utf32>(static_cast<unsigned char>(*buf2))))
5054 return *buf1 -
static_cast<utf32
>(
static_cast<unsigned char>(*buf2));
5058 int utf32_comp_utf8(
const utf32* buf1,
const utf8* buf2, size_type cp_count)
const
5076 cp = ((cu & 0x1F) << 6);
5077 cp |= (*buf2++ & 0x3F);
5081 cp = ((cu & 0x0F) << 12);
5082 cp |= ((*buf2++ & 0x3F) << 6);
5083 cp |= (*buf2++ & 0x3F);
5087 cp = ((cu & 0x07) << 18);
5088 cp |= ((*buf2++ & 0x3F) << 12);
5089 cp |= ((*buf2++ & 0x3F) << 6);
5090 cp |= (*buf2++ & 0x3F);
5093 }
while ((*buf1++ == cp) && (--cp_count));
5095 return (*--buf1) - cp;
5099 size_type find_codepoint(
const std::string& str, utf32 code_point)
const
5101 size_type idx = 0, sze = (size_type)str.size();
5105 if (code_point == static_cast<utf32>(static_cast<unsigned char>(str[idx])))
5115 size_type find_codepoint(
const utf8* str, size_type len, utf32 code_point)
const
5122 while (idx != len) {
5131 cp = ((cu & 0x1F) << 6);
5132 cp |= (*str++ & 0x3F);
5136 cp = ((cu & 0x0F) << 12);
5137 cp |= ((*str++ & 0x3F) << 6);
5138 cp |= (*str++ & 0x3F);
5142 cp = ((cu & 0x07) << 18);
5143 cp |= ((*str++ & 0x3F) << 12);
5144 cp |= ((*str++ & 0x3F) << 6);
5145 cp |= (*str++ & 0x3F);
5148 if (code_point == cp)
5159 size_type find_codepoint(
const char* chars, size_type chars_len, utf32 code_point)
const
5161 for (size_type idx = 0; idx != chars_len; ++idx)
5163 if (code_point == static_cast<utf32>(static_cast<unsigned char>(chars[idx])))
5180 bool CEGUIEXPORT
operator==(
const String& str1,
const String& str2);
5186 bool CEGUIEXPORT
operator==(
const String& str,
const std::string& std_str);
5192 bool CEGUIEXPORT
operator==(
const std::string& std_str,
const String& str);
5198 bool CEGUIEXPORT
operator==(
const String& str,
const utf8* utf8_str);
5204 bool CEGUIEXPORT
operator==(
const utf8* utf8_str,
const String& str);
5210 bool CEGUIEXPORT
operator!=(
const String& str1,
const String& str2);
5216 bool CEGUIEXPORT
operator!=(
const String& str,
const std::string& std_str);
5222 bool CEGUIEXPORT
operator!=(
const std::string& std_str,
const String& str);
5228 bool CEGUIEXPORT
operator!=(
const String& str,
const utf8* utf8_str);
5234 bool CEGUIEXPORT
operator!=(
const utf8* utf8_str,
const String& str);
5240 bool CEGUIEXPORT
operator<(
const String& str1,
const String& str2);
5246 bool CEGUIEXPORT
operator<(
const String& str,
const std::string& std_str);
5252 bool CEGUIEXPORT
operator<(
const std::string& std_str,
const String& str);
5258 bool CEGUIEXPORT
operator<(
const String& str,
const utf8* utf8_str);
5264 bool CEGUIEXPORT
operator<(
const utf8* utf8_str,
const String& str);
5270 bool CEGUIEXPORT
operator>(
const String& str1,
const String& str2);
5276 bool CEGUIEXPORT
operator>(
const String& str,
const std::string& std_str);
5282 bool CEGUIEXPORT
operator>(
const std::string& std_str,
const String& str);
5288 bool CEGUIEXPORT
operator>(
const String& str,
const utf8* utf8_str);
5294 bool CEGUIEXPORT
operator>(
const utf8* utf8_str,
const String& str);
5300 bool CEGUIEXPORT
operator<=(
const String& str1,
const String& str2);
5306 bool CEGUIEXPORT
operator<=(
const String& str,
const std::string& std_str);
5312 bool CEGUIEXPORT
operator<=(
const std::string& std_str,
const String& str);
5318 bool CEGUIEXPORT
operator<=(
const String& str,
const utf8* utf8_str);
5324 bool CEGUIEXPORT
operator<=(
const utf8* utf8_str,
const String& str);
5330 bool CEGUIEXPORT
operator>=(
const String& str1,
const String& str2);
5336 bool CEGUIEXPORT
operator>=(
const String& str,
const std::string& std_str);
5342 bool CEGUIEXPORT
operator>=(
const std::string& std_str,
const String& str);
5348 bool CEGUIEXPORT
operator>=(
const String& str,
const utf8* utf8_str);
5354 bool CEGUIEXPORT
operator>=(
const utf8* utf8_str,
const String& str);
5360 bool CEGUIEXPORT
operator==(
const String& str,
const char* c_str);
5366 bool CEGUIEXPORT
operator==(
const char* c_str,
const String& str);
5372 bool CEGUIEXPORT
operator!=(
const String& str,
const char* c_str);
5378 bool CEGUIEXPORT
operator!=(
const char* c_str,
const String& str);
5384 bool CEGUIEXPORT
operator<(
const String& str,
const char* c_str);
5390 bool CEGUIEXPORT
operator<(
const char* c_str,
const String& str);
5396 bool CEGUIEXPORT
operator>(
const String& str,
const char* c_str);
5402 bool CEGUIEXPORT
operator>(
const char* c_str,
const String& str);
5408 bool CEGUIEXPORT
operator<=(
const String& str,
const char* c_str);
5414 bool CEGUIEXPORT
operator<=(
const char* c_str,
const String& str);
5420 bool CEGUIEXPORT
operator>=(
const String& str,
const char* c_str);
5426 bool CEGUIEXPORT
operator>=(
const char* c_str,
const String& str);
5446 String CEGUIEXPORT
operator+(
const String& str1,
const String& str2);
5463 String CEGUIEXPORT
operator+(
const String& str,
const std::string& std_str);
5480 String CEGUIEXPORT
operator+(
const std::string& std_str,
const String& str);
5497 String CEGUIEXPORT
operator+(
const String& str,
const utf8* utf8_str);
5514 String CEGUIEXPORT
operator+(
const utf8* utf8_str,
const String& str);
5531 String CEGUIEXPORT
operator+(
const String& str, utf32 code_point);
5548 String CEGUIEXPORT
operator+(utf32 code_point,
const String& str);
5565 String CEGUIEXPORT
operator+(
const String& str,
const char* c_str);
5582 String CEGUIEXPORT
operator+(
const char* c_str,
const String& str);
5588 CEGUIEXPORT std::ostream& operator<<(std::ostream& s,
const String& str);
5607 void CEGUIEXPORT
swap(String& str1, String& str2);
5613 #endif // end of guard _CEGUIString_h_