32 #include "CEGUI/Base.h"
47 #if CEGUI_STRING_CLASS == CEGUI_STRING_CLASS_UNICODE
52 #define CEGUI_STR_QUICKBUFF_SIZE 32
86 mutable utf8* d_encodedbuff;
90 utf32 d_quickbuff[CEGUI_STR_QUICKBUFF_SIZE];
98 class iterator :
public std::iterator<std::random_access_iterator_tag, utf32>
102 explicit iterator(utf32*
const ptr) : d_ptr(ptr) {}
104 utf32& operator*()
const
109 utf32* operator->()
const
149 return temp += offset;
154 return *
this += -offset;
160 return temp -= offset;
165 return *(*
this + offset);
170 {
return lhs.d_ptr - rhs.d_ptr; }
173 {
return iter + offset; }
177 {
return lhs.d_ptr == rhs.d_ptr; }
181 {
return lhs.d_ptr != rhs.d_ptr; }
185 {
return lhs.d_ptr < rhs.d_ptr; }
189 {
return lhs.d_ptr > rhs.d_ptr; }
193 {
return lhs.d_ptr <= rhs.d_ptr; }
197 {
return lhs.d_ptr >= rhs.d_ptr; }
203 class const_iterator :
public std::iterator<std::random_access_iterator_tag, const utf32>
210 const utf32& operator*()
const
215 const utf32* operator->()
const
255 return temp += offset;
260 return *
this += -offset;
266 return temp -= offset;
271 return *(*
this + offset);
281 {
return iter + offset; }
285 {
return lhs.d_ptr - rhs.d_ptr; }
289 {
return lhs.d_ptr == rhs.d_ptr; }
293 {
return lhs.d_ptr != rhs.d_ptr; }
297 {
return lhs.d_ptr < rhs.d_ptr; }
301 {
return lhs.d_ptr > rhs.d_ptr; }
305 {
return lhs.d_ptr <= rhs.d_ptr; }
309 {
return lhs.d_ptr >= rhs.d_ptr; }
318 #if defined(_MSC_VER) && ((_MSC_VER <= 1200) || ((_MSC_VER <= 1300) && defined(_STLPORT_VERSION)))
319 typedef std::reverse_iterator<const_iterator, const_pointer, const_reference, difference_type>
const_reverse_iterator;
328 #if defined(_MSC_VER) && ((_MSC_VER <= 1200) || ((_MSC_VER <= 1300) && defined(_STLPORT_VERSION)))
329 typedef std::reverse_iterator<iterator, pointer, reference, difference_type>
reverse_iterator;
392 assign(str, str_idx, str_num);
445 assign(std_str, str_idx, str_num);
505 assign(utf8_str, chars_len);
529 assign(num, code_point);
552 append(iter_beg, iter_end);
595 assign(chars, chars_len);
633 bool empty(
void)
const
635 return (d_cplength == 0);
649 return (((
size_type)-1) /
sizeof(utf32));
667 return d_reserve - 1;
713 return compare(0, d_cplength, str);
747 if ((d_cplength < idx) || (str.d_cplength < str_idx))
748 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
750 if ((len == npos) || (idx + len > d_cplength))
751 len = d_cplength - idx;
753 if ((str_len == npos) || (str_idx + str_len > str.d_cplength))
754 str_len = str.d_cplength - str_idx;
756 int val = (len == 0) ? 0 : utf32_comp_utf32(&ptr()[idx], &str.
ptr()[str_idx], (len < str_len) ? len : str_len);
758 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_len) ? -1 : (len == str_len) ? 0 : 1;
781 int compare(
const std::string& std_str)
const
783 return compare(0, d_cplength, std_str);
822 if (d_cplength < idx)
823 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
825 if (std_str.size() < str_idx)
826 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
828 if ((len == npos) || (idx + len > d_cplength))
829 len = d_cplength - idx;
831 if ((str_len == npos) || (str_idx + str_len > std_str.size()))
832 str_len = (
size_type)std_str.size() - str_idx;
834 int val = (len == 0) ? 0 : utf32_comp_char(&ptr()[idx], &std_str.c_str()[str_idx], (len < str_len) ? len : str_len);
836 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_len) ? -1 : (len == str_len) ? 0 : 1;
861 int compare(
const utf8* utf8_str)
const
863 return compare(0, d_cplength, utf8_str, encoded_size(utf8_str));
898 return compare(idx, len, utf8_str, encoded_size(utf8_str));
936 if (d_cplength < idx)
937 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
939 if (str_cplen == npos)
940 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
942 if ((len == npos) || (idx + len > d_cplength))
943 len = d_cplength - idx;
945 int val = (len == 0) ? 0 : utf32_comp_utf8(&ptr()[idx], utf8_str, (len < str_cplen) ? len : str_cplen);
947 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_cplen) ? -1 : (len == str_cplen) ? 0 : 1;
966 int compare(
const char* cstr)
const
968 return compare(0, d_cplength, cstr, strlen(cstr));
997 return compare(idx, len, cstr, strlen(cstr));
1030 if (d_cplength < idx)
1031 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1033 if (chars_len == npos)
1034 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
1036 if ((len == npos) || (idx + len > d_cplength))
1037 len = d_cplength - idx;
1039 int val = (len == 0) ? 0 : utf32_comp_char(&ptr()[idx], chars, (len < chars_len) ? len : chars_len);
1041 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < chars_len) ? -1 : (len == chars_len) ? 0 : 1;
1064 return (ptr()[idx]);
1100 if (d_cplength <= idx)
1101 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1120 if (d_cplength <= idx)
1121 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1143 const char* c_str(
void)
const
1145 return (
const char*)build_utf8_buff();
1161 const utf8* data(
void)
const
1163 return build_utf8_buff();
1172 return (d_reserve > CEGUI_STR_QUICKBUFF_SIZE) ? d_buffer : d_quickbuff;
1179 const utf32* ptr(
void)
const
1181 return (d_reserve > CEGUI_STR_QUICKBUFF_SIZE) ? d_buffer : d_quickbuff;
1208 if (d_cplength < idx)
1209 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1214 return encode(&ptr()[idx], buf, npos, len);
1238 using namespace std;
1240 if (d_cplength < idx)
1241 CEGUI_THROW(out_of_range(
"Index was out of range for CEGUI::String object"));
1245 return encoded_size(&ptr()[idx], ceguimin(num, maxlen));
1286 if (str.d_cplength < str_idx)
1287 CEGUI_THROW(std::out_of_range(
"Index was out of range for CEGUI::String object"));
1289 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
1290 str_num = str.d_cplength - str_idx;
1294 memcpy(ptr(), &str.
ptr()[str_idx], str_num *
sizeof(utf32));
1315 String& operator=(
const std::string& std_str)
1317 return assign(std_str);
1345 if (std_str.size() < str_idx)
1346 CEGUI_THROW(std::out_of_range(
"Index was out of range for std::string object"));
1348 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
1349 str_num = (
size_type)std_str.size() - str_idx;
1356 ((*this)[str_num]) = static_cast<utf32>(static_cast<unsigned char>(std_str[str_num + str_idx]));
1382 return assign(utf8_str, utf_length(utf8_str));
1405 return assign(utf8_str, utf_length(utf8_str));
1431 if (str_num == npos)
1432 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
1434 size_type enc_sze = encoded_size(utf8_str, str_num);
1437 encode(utf8_str, ptr(), d_reserve, str_num);
1454 return assign(1, code_point);
1475 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
1502 return assign(cstr, strlen(cstr));
1520 return assign(cstr, strlen(cstr));
1544 for (
size_type i = 0; i < chars_len; ++i)
1546 *pt++ =
static_cast<utf32
>(
static_cast<unsigned char>(*chars++));
1567 d_cplength = str.d_cplength;
1568 str.d_cplength = temp_len;
1571 d_reserve = str.d_reserve;
1572 str.d_reserve = temp_res;
1574 utf32* temp_buf = d_buffer;
1575 d_buffer = str.d_buffer;
1576 str.d_buffer = temp_buf;
1579 if (temp_res <= CEGUI_STR_QUICKBUFF_SIZE)
1581 utf32 temp_qbf[CEGUI_STR_QUICKBUFF_SIZE];
1583 memcpy(temp_qbf, d_quickbuff, CEGUI_STR_QUICKBUFF_SIZE *
sizeof(utf32));
1584 memcpy(d_quickbuff, str.d_quickbuff, CEGUI_STR_QUICKBUFF_SIZE *
sizeof(utf32));
1585 memcpy(str.d_quickbuff, temp_qbf, CEGUI_STR_QUICKBUFF_SIZE *
sizeof(utf32));
1631 if (str.d_cplength < str_idx)
1632 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1634 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
1635 str_num = str.d_cplength - str_idx;
1637 grow(d_cplength + str_num);
1638 memcpy(&ptr()[d_cplength], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
1639 setlen(d_cplength + str_num);
1660 String& operator+=(
const std::string& std_str)
1662 return append(std_str);
1690 if (std_str.size() < str_idx)
1691 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
1693 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
1694 str_num = (
size_type)std_str.size() - str_idx;
1696 size_type newsze = d_cplength + str_num;
1699 utf32* pt = &ptr()[newsze-1];
1702 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_num]));
1729 return append(utf8_str, utf_length(utf8_str));
1752 return append(utf8_str, utf_length(utf8_str));
1780 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
1782 size_type encsz = encoded_size(utf8_str, len);
1786 encode(utf8_str, &ptr()[d_cplength], encsz, len);
1807 return append(1, code_point);
1828 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
1833 utf32* p = &ptr()[d_cplength];
1855 void push_back(utf32 code_point)
1857 append(1, code_point);
1877 return replace(end(), end(), iter_beg, iter_end);
1895 return append(cstr, strlen(cstr));
1913 return append(cstr, strlen(cstr));
1934 if (chars_len == npos)
1935 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
1937 size_type newsz = d_cplength + chars_len;
1941 utf32* pt = &ptr()[newsz-1];
1944 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
1973 return insert(idx, str, 0, npos);
2000 if ((d_cplength < idx) || (str.d_cplength < str_idx))
2001 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2003 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
2004 str_num = str.d_cplength - str_idx;
2008 memmove(&ptr()[idx + str_num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2009 memcpy(&ptr()[idx], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
2037 return insert(idx, std_str, 0, npos);
2068 if (d_cplength < idx)
2069 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2071 if (std_str.size() < str_idx)
2072 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
2074 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
2075 str_num = (
size_type)std_str.size() - str_idx;
2080 memmove(&ptr()[idx + str_num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2082 utf32* pt = &ptr()[idx + str_num - 1];
2085 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_idx + str_num]));
2116 return insert(idx, utf8_str, utf_length(utf8_str));
2146 if (d_cplength < idx)
2147 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2150 CEGUI_THROW(std::length_error(
"Length of utf8 encoded string can not be 'npos'"));
2152 size_type encsz = encoded_size(utf8_str, len);
2156 memmove(&ptr()[idx + encsz], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2157 encode(utf8_str, &ptr()[idx], encsz, len);
2184 if (d_cplength < idx)
2185 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2188 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
2193 memmove(&ptr()[idx + num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2195 utf32* pt = &ptr()[idx + num - 1];
2225 insert(safe_iter_dif(pos, begin()), num, code_point);
2245 insert(pos, 1, code_point);
2269 replace(iter_pos, iter_pos, iter_beg, iter_end);
2291 return insert(idx, cstr, strlen(cstr));
2316 if (d_cplength < idx)
2317 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2319 if (chars_len == npos)
2320 CEGUI_THROW(std::length_error(
"Length of char array can not be 'npos'"));
2322 size_type newsz = d_cplength + chars_len;
2325 memmove(&ptr()[idx + chars_len], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2327 utf32* pt = &ptr()[idx + chars_len - 1];
2330 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
2381 return erase(idx, 1);
2405 if (d_cplength <= idx)
2406 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2409 len = d_cplength - idx;
2413 memmove(&ptr()[idx], &ptr()[idx + len], (d_cplength - idx - len) *
sizeof(utf32));
2430 return erase(safe_iter_dif(pos, begin()), 1);
2448 return erase(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg));
2468 resize(num, utf32());
2488 if (num < d_cplength)
2494 append(num - d_cplength, code_point);
2523 return replace(idx, len, str, 0, npos);
2549 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), str, 0, npos);
2579 if ((d_cplength < idx) || (str.d_cplength < str_idx))
2580 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2582 if (((str_idx + str_num) > str.d_cplength) || (str_num == npos))
2583 str_num = str.d_cplength - str_idx;
2585 if (((len + idx) > d_cplength) || (len == npos))
2586 len = d_cplength - idx;
2588 size_type newsz = d_cplength + str_num - len;
2592 if ((idx + len) < d_cplength)
2593 memmove(&ptr()[idx + str_num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2595 memcpy(&ptr()[idx], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
2627 return replace(idx, len, std_str, 0, npos);
2657 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), std_str, 0, npos);
2691 if (d_cplength < idx)
2692 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2694 if (std_str.size() < str_idx)
2695 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
2697 if (((str_idx + str_num) > std_str.size()) || (str_num == npos))
2698 str_num = (
size_type)std_str.size() - str_idx;
2700 if (((len + idx) > d_cplength) || (len == npos))
2701 len = d_cplength - idx;
2703 size_type newsz = d_cplength + str_num - len;
2707 if ((idx + len) < d_cplength)
2708 memmove(&ptr()[idx + str_num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2710 utf32* pt = &ptr()[idx + str_num - 1];
2713 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_idx + str_num]));
2748 return replace(idx, len, utf8_str, utf_length(utf8_str));
2780 return replace(iter_beg, iter_end, utf8_str, utf_length(utf8_str));
2813 if (d_cplength < idx)
2814 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2816 if (str_len == npos)
2817 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
2819 if (((len + idx) > d_cplength) || (len == npos))
2820 len = d_cplength - idx;
2822 size_type encsz = encoded_size(utf8_str, str_len);
2823 size_type newsz = d_cplength + encsz - len;
2827 if ((idx + len) < d_cplength)
2828 memmove(&ptr()[idx + encsz], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2830 encode(utf8_str, &ptr()[idx], encsz, str_len);
2868 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), utf8_str, str_len);
2895 if (d_cplength < idx)
2896 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2899 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
2901 if (((len + idx) > d_cplength) || (len == npos))
2902 len = d_cplength - idx;
2904 size_type newsz = d_cplength + num - len;
2908 if ((idx + len) < d_cplength)
2909 memmove(&ptr()[idx + num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2911 utf32* pt = &ptr()[idx + num - 1];
2947 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), num, code_point);
2977 if (iter_newBeg == iter_newEnd)
2979 erase(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg));
2983 size_type str_len = safe_iter_dif(iter_newEnd, iter_newBeg);
2984 size_type idx = safe_iter_dif(iter_beg, begin());
2985 size_type len = safe_iter_dif(iter_end, iter_beg);
2987 if ((len + idx) > d_cplength)
2988 len = d_cplength - idx;
2990 size_type newsz = d_cplength + str_len - len;
2994 if ((idx + len) < d_cplength)
2995 memmove(&ptr()[idx + str_len], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2997 memcpy(&ptr()[idx], iter_newBeg.d_ptr, str_len *
sizeof(utf32));
3026 return replace(idx, len, cstr, strlen(cstr));
3053 return replace(iter_beg, iter_end, cstr, strlen(cstr));
3081 if (d_cplength < idx)
3082 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
3084 if (chars_len == npos)
3085 CEGUI_THROW(std::length_error(
"Length for the char array can not be 'npos'"));
3087 if (((len + idx) > d_cplength) || (len == npos))
3088 len = d_cplength - idx;
3090 size_type newsz = d_cplength + chars_len - len;
3094 if ((idx + len) < d_cplength)
3095 memmove(&ptr()[idx + chars_len], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
3097 utf32* pt = &ptr()[idx + chars_len - 1];
3100 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
3133 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), chars, chars_len);
3156 if (idx < d_cplength)
3158 const utf32* pt = &ptr()[idx];
3160 while (idx < d_cplength)
3162 if (*pt++ == code_point)
3189 if (idx >= d_cplength)
3190 idx = d_cplength - 1;
3194 const utf32* pt = &ptr()[idx];
3198 if (*pt-- == code_point)
3201 }
while (idx-- != 0);
3227 if ((str.d_cplength == 0) && (idx < d_cplength))
3230 if (idx < d_cplength)
3233 while (d_cplength - idx >= str.d_cplength)
3235 if (0 == compare(idx, str.d_cplength, str))
3262 if (str.d_cplength == 0)
3263 return (idx < d_cplength) ? idx : d_cplength;
3265 if (str.d_cplength <= d_cplength)
3267 if (idx > (d_cplength - str.d_cplength))
3268 idx = d_cplength - str.d_cplength;
3272 if (0 == compare(idx, str.d_cplength, str))
3275 }
while (idx-- != 0);
3302 std::string::size_type sze = std_str.size();
3304 if ((sze == 0) && (idx < d_cplength))
3307 if (idx < d_cplength)
3310 while (d_cplength - idx >= sze)
3312 if (0 == compare(idx, (
size_type)sze, std_str))
3343 std::string::size_type sze = std_str.size();
3346 return (idx < d_cplength) ? idx : d_cplength;
3348 if (sze <= d_cplength)
3350 if (idx > (d_cplength - sze))
3351 idx = d_cplength - sze;
3355 if (0 == compare(idx, (
size_type)sze, std_str))
3358 }
while (idx-- != 0);
3389 return find(utf8_str, idx, utf_length(utf8_str));
3416 return rfind(utf8_str, idx, utf_length(utf8_str));
3446 if (str_len == npos)
3447 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3449 size_type sze = encoded_size(utf8_str, str_len);
3451 if ((sze == 0) && (idx < d_cplength))
3454 if (idx < d_cplength)
3457 while (d_cplength - idx >= sze)
3459 if (0 == compare(idx, sze, utf8_str, sze))
3497 if (str_len == npos)
3498 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3500 size_type sze = encoded_size(utf8_str, str_len);
3503 return (idx < d_cplength) ? idx : d_cplength;
3505 if (sze <= d_cplength)
3507 if (idx > (d_cplength - sze))
3508 idx = d_cplength - sze;
3512 if (0 == compare(idx, sze, utf8_str, sze))
3515 }
while (idx-- != 0);
3541 return find(cstr, idx, strlen(cstr));
3563 return rfind(cstr, idx, strlen(cstr));
3588 if (chars_len == npos)
3589 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
3591 if ((chars_len == 0) && (idx < d_cplength))
3594 if (idx < d_cplength)
3597 while (d_cplength - idx >= chars_len)
3599 if (0 == compare(idx, chars_len, chars, chars_len))
3632 if (chars_len == npos)
3633 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
3636 return (idx < d_cplength) ? idx : d_cplength;
3638 if (chars_len <= d_cplength)
3640 if (idx > (d_cplength - chars_len))
3641 idx = d_cplength - chars_len;
3645 if (0 == compare(idx, chars_len, chars, chars_len))
3648 }
while (idx-- != 0);
3675 if (idx < d_cplength)
3677 const utf32* pt = &ptr()[idx];
3681 if (npos != str.
find(*pt++))
3684 }
while (++idx != d_cplength);
3707 if (idx < d_cplength)
3709 const utf32* pt = &ptr()[idx];
3713 if (npos == str.
find(*pt++))
3716 }
while (++idx != d_cplength);
3744 if (idx < d_cplength)
3746 const utf32* pt = &ptr()[idx];
3750 if (npos != find_codepoint(std_str, *pt++))
3753 }
while (++idx != d_cplength);
3780 if (idx < d_cplength)
3782 const utf32* pt = &ptr()[idx];
3786 if (npos == find_codepoint(std_str, *pt++))
3789 }
while (++idx != d_cplength);
3821 return find_first_of(utf8_str, idx, utf_length(utf8_str));
3848 return find_first_not_of(utf8_str, idx, utf_length(utf8_str));
3878 if (str_len == npos)
3879 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3881 if (idx < d_cplength)
3883 size_type encsze = encoded_size(utf8_str, str_len);
3885 const utf32* pt = &ptr()[idx];
3889 if (npos != find_codepoint(utf8_str, encsze, *pt++))
3892 }
while (++idx != d_cplength);
3926 if (str_len == npos)
3927 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3929 if (idx < d_cplength)
3931 size_type encsze = encoded_size(utf8_str, str_len);
3933 const utf32* pt = &ptr()[idx];
3937 if (npos == find_codepoint(utf8_str, encsze, *pt++))
3940 }
while (++idx != d_cplength);
3964 return find(code_point, idx);
3985 if (idx < d_cplength)
3989 if ((*
this)[idx] != code_point)
3992 }
while(idx++ < d_cplength);
4018 return find_first_of(cstr, idx, strlen(cstr));
4040 return find_first_not_of(cstr, idx, strlen(cstr));
4065 if (chars_len == npos)
4066 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4068 if (idx < d_cplength)
4070 const utf32* pt = &ptr()[idx];
4074 if (npos != find_codepoint(chars, chars_len, *pt++))
4077 }
while (++idx != d_cplength);
4106 if (chars_len == npos)
4107 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4109 if (idx < d_cplength)
4111 const utf32* pt = &ptr()[idx];
4115 if (npos == find_codepoint(chars, chars_len, *pt++))
4118 }
while (++idx != d_cplength);
4147 if (idx >= d_cplength)
4148 idx = d_cplength - 1;
4150 const utf32* pt = &ptr()[idx];
4154 if (npos != str.
find(*pt--))
4157 }
while (idx-- != 0);
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);
4222 if (idx >= d_cplength)
4223 idx = d_cplength - 1;
4225 const utf32* pt = &ptr()[idx];
4229 if (npos != find_codepoint(std_str, *pt--))
4232 }
while (idx-- != 0);
4261 if (idx >= d_cplength)
4262 idx = d_cplength - 1;
4264 const utf32* pt = &ptr()[idx];
4268 if (npos == find_codepoint(std_str, *pt--))
4271 }
while (idx-- != 0);
4303 return find_last_of(utf8_str, idx, utf_length(utf8_str));
4330 return find_last_not_of(utf8_str, idx, utf_length(utf8_str));
4360 if (str_len == npos)
4361 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
4365 if (idx >= d_cplength)
4366 idx = d_cplength - 1;
4368 size_type encsze = encoded_size(utf8_str, str_len);
4370 const utf32* pt = &ptr()[idx];
4374 if (npos != find_codepoint(utf8_str, encsze, *pt--))
4377 }
while (idx-- != 0);
4411 if (str_len == npos)
4412 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
4416 if (idx >= d_cplength)
4417 idx = d_cplength - 1;
4419 size_type encsze = encoded_size(utf8_str, str_len);
4421 const utf32* pt = &ptr()[idx];
4425 if (npos == find_codepoint(utf8_str, encsze, *pt--))
4428 }
while (idx-- != 0);
4452 return rfind(code_point, idx);
4473 if (idx >= d_cplength)
4474 idx = d_cplength - 1;
4478 if ((*
this)[idx] != code_point)
4481 }
while(idx-- != 0);
4507 return find_last_of(cstr, idx, strlen(cstr));
4529 return find_last_not_of(cstr, idx, strlen(cstr));
4554 if (chars_len == npos)
4555 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4559 if (idx >= d_cplength)
4560 idx = d_cplength - 1;
4562 const utf32* pt = &ptr()[idx];
4566 if (npos != find_codepoint(chars, chars_len, *pt--))
4569 }
while (idx-- != 0);
4598 if (chars_len == npos)
4599 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4603 if (idx >= d_cplength)
4604 idx = d_cplength - 1;
4606 const utf32* pt = &ptr()[idx];
4610 if (npos == find_codepoint(chars, chars_len, *pt--))
4613 }
while (idx-- != 0);
4641 if (d_cplength < idx)
4642 CEGUI_THROW(std::out_of_range(
"Index is out of range for this CEGUI::String"));
4644 return String(*
this, idx, len);
4683 return iterator(&ptr()[d_cplength]);
4755 bool grow(size_type new_size);
4761 void setlen(size_type len)
4764 ptr()[len] = (utf32)(0);
4770 d_reserve = CEGUI_STR_QUICKBUFF_SIZE;
4772 d_encodedbufflen = 0;
4773 d_encodeddatlen = 0;
4779 bool inside(utf32* inptr)
4781 if (inptr < ptr() || ptr() + d_cplength <= inptr)
4788 size_type safe_iter_dif(
const const_iterator& iter1,
const const_iterator& iter2)
const
4790 return (iter1.d_ptr == 0) ? 0 : (iter1 - iter2);
4798 size_type encode(
const utf32* src, utf8* dest, size_type dest_len, size_type src_len = 0)
const
4803 src_len = utf_length(src);
4806 size_type destCapacity = dest_len;
4809 for (uint idx = 0; idx < src_len; ++idx)
4811 utf32 cp = src[idx];
4814 if (destCapacity < encoded_size(cp))
4824 else if (cp < 0x0800)
4826 *dest++ = (utf8)((cp >> 6) | 0xC0);
4827 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4830 else if (cp < 0x10000)
4832 *dest++ = (utf8)((cp >> 12) | 0xE0);
4833 *dest++ = (utf8)(((cp >> 6) & 0x3F) | 0x80);
4834 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4839 *dest++ = (utf8)((cp >> 18) | 0xF0);
4840 *dest++ = (utf8)(((cp >> 12) & 0x3F) | 0x80);
4841 *dest++ = (utf8)(((cp >> 6) & 0x3F) | 0x80);
4842 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4848 return dest_len - destCapacity;
4851 size_type encode(
const utf8* src, utf32* dest, size_type dest_len, size_type src_len = 0)
const
4856 src_len = utf_length(src);
4859 size_type destCapacity = dest_len;
4862 for (uint idx = 0; ((idx < src_len) && (destCapacity > 0));)
4865 utf8 cu = src[idx++];
4873 cp = ((cu & 0x1F) << 6);
4874 cp |= (src[idx++] & 0x3F);
4878 cp = ((cu & 0x0F) << 12);
4879 cp |= ((src[idx++] & 0x3F) << 6);
4880 cp |= (src[idx++] & 0x3F);
4884 cp = ((cu & 0x07) << 18);
4885 cp |= ((src[idx++] & 0x3F) << 12);
4886 cp |= ((src[idx++] & 0x3F) << 6);
4887 cp |= (src[idx++] & 0x3F);
4894 return dest_len - destCapacity;
4898 size_type encoded_size(utf32 code_point)
const
4900 if (code_point < 0x80)
4902 else if (code_point < 0x0800)
4904 else if (code_point < 0x10000)
4911 size_type encoded_size(
const utf32* buf)
const
4913 return encoded_size(buf, utf_length(buf));
4917 size_type encoded_size(
const utf32* buf, size_type len)
const
4919 size_type count = 0;
4923 count += encoded_size(*buf++);
4930 size_type encoded_size(
const utf8* buf)
const
4932 return encoded_size(buf, utf_length(buf));
4936 size_type encoded_size(
const utf8* buf, size_type len)
const
4939 size_type count = 0;
4950 else if (tcp < 0xE0)
4955 else if (tcp < 0xF0)
4976 size_type utf_length(
const utf8* utf8_str)
const
4986 size_type utf_length(
const utf32* utf32_str)
const
4989 while (*utf32_str++)
4996 utf8* build_utf8_buff(
void)
const;
4999 int utf32_comp_utf32(
const utf32* buf1,
const utf32* buf2, size_type cp_count)
const
5004 while ((--cp_count) && (*buf1 == *buf2))
5007 return *buf1 - *buf2;
5011 int utf32_comp_char(
const utf32* buf1,
const char* buf2, size_type cp_count)
const
5016 while ((--cp_count) && (*buf1 == static_cast<utf32>(static_cast<unsigned char>(*buf2))))
5019 return *buf1 -
static_cast<utf32
>(
static_cast<unsigned char>(*buf2));
5023 int utf32_comp_utf8(
const utf32* buf1,
const utf8* buf2, size_type cp_count)
const
5041 cp = ((cu & 0x1F) << 6);
5042 cp |= (*buf2++ & 0x3F);
5046 cp = ((cu & 0x0F) << 12);
5047 cp |= ((*buf2++ & 0x3F) << 6);
5048 cp |= (*buf2++ & 0x3F);
5052 cp = ((cu & 0x07) << 18);
5053 cp |= ((*buf2++ & 0x3F) << 12);
5054 cp |= ((*buf2++ & 0x3F) << 6);
5055 cp |= (*buf2++ & 0x3F);
5058 }
while ((*buf1++ == cp) && (--cp_count));
5060 return (*--buf1) - cp;
5064 size_type find_codepoint(
const std::string& str, utf32 code_point)
const
5066 size_type idx = 0, sze = (size_type)str.size();
5070 if (code_point == static_cast<utf32>(static_cast<unsigned char>(str[idx])))
5080 size_type find_codepoint(
const utf8* str, size_type len, utf32 code_point)
const
5087 while (idx != len) {
5096 cp = ((cu & 0x1F) << 6);
5097 cp |= (*str++ & 0x3F);
5101 cp = ((cu & 0x0F) << 12);
5102 cp |= ((*str++ & 0x3F) << 6);
5103 cp |= (*str++ & 0x3F);
5107 cp = ((cu & 0x07) << 18);
5108 cp |= ((*str++ & 0x3F) << 12);
5109 cp |= ((*str++ & 0x3F) << 6);
5110 cp |= (*str++ & 0x3F);
5113 if (code_point == cp)
5124 size_type find_codepoint(
const char* chars, size_type chars_len, utf32 code_point)
const
5126 for (size_type idx = 0; idx != chars_len; ++idx)
5128 if (code_point == static_cast<utf32>(static_cast<unsigned char>(chars[idx])))
5145 bool CEGUIEXPORT
operator==(
const String& str1,
const String& str2);
5151 bool CEGUIEXPORT
operator==(
const String& str,
const std::string& std_str);
5157 bool CEGUIEXPORT
operator==(
const std::string& std_str,
const String& str);
5163 bool CEGUIEXPORT
operator==(
const String& str,
const utf8* utf8_str);
5169 bool CEGUIEXPORT
operator==(
const utf8* utf8_str,
const String& str);
5175 bool CEGUIEXPORT
operator!=(
const String& str1,
const String& str2);
5181 bool CEGUIEXPORT
operator!=(
const String& str,
const std::string& std_str);
5187 bool CEGUIEXPORT
operator!=(
const std::string& std_str,
const String& str);
5193 bool CEGUIEXPORT
operator!=(
const String& str,
const utf8* utf8_str);
5199 bool CEGUIEXPORT
operator!=(
const utf8* utf8_str,
const String& str);
5205 bool CEGUIEXPORT
operator<(
const String& str1,
const String& str2);
5211 bool CEGUIEXPORT
operator<(
const String& str,
const std::string& std_str);
5217 bool CEGUIEXPORT
operator<(
const std::string& std_str,
const String& str);
5223 bool CEGUIEXPORT
operator<(
const String& str,
const utf8* utf8_str);
5229 bool CEGUIEXPORT
operator<(
const utf8* utf8_str,
const String& str);
5235 bool CEGUIEXPORT
operator>(
const String& str1,
const String& str2);
5241 bool CEGUIEXPORT
operator>(
const String& str,
const std::string& std_str);
5247 bool CEGUIEXPORT
operator>(
const std::string& std_str,
const String& str);
5253 bool CEGUIEXPORT
operator>(
const String& str,
const utf8* utf8_str);
5259 bool CEGUIEXPORT
operator>(
const utf8* utf8_str,
const String& str);
5265 bool CEGUIEXPORT
operator<=(
const String& str1,
const String& str2);
5271 bool CEGUIEXPORT
operator<=(
const String& str,
const std::string& std_str);
5277 bool CEGUIEXPORT
operator<=(
const std::string& std_str,
const String& str);
5283 bool CEGUIEXPORT
operator<=(
const String& str,
const utf8* utf8_str);
5289 bool CEGUIEXPORT
operator<=(
const utf8* utf8_str,
const String& str);
5295 bool CEGUIEXPORT
operator>=(
const String& str1,
const String& str2);
5301 bool CEGUIEXPORT
operator>=(
const String& str,
const std::string& std_str);
5307 bool CEGUIEXPORT
operator>=(
const std::string& std_str,
const String& str);
5313 bool CEGUIEXPORT
operator>=(
const String& str,
const utf8* utf8_str);
5319 bool CEGUIEXPORT
operator>=(
const utf8* utf8_str,
const String& str);
5325 bool CEGUIEXPORT
operator==(
const String& str,
const char* c_str);
5331 bool CEGUIEXPORT
operator==(
const char* c_str,
const String& str);
5337 bool CEGUIEXPORT
operator!=(
const String& str,
const char* c_str);
5343 bool CEGUIEXPORT
operator!=(
const char* c_str,
const String& str);
5349 bool CEGUIEXPORT
operator<(
const String& str,
const char* c_str);
5355 bool CEGUIEXPORT
operator<(
const char* c_str,
const String& str);
5361 bool CEGUIEXPORT
operator>(
const String& str,
const char* c_str);
5367 bool CEGUIEXPORT
operator>(
const char* c_str,
const String& str);
5373 bool CEGUIEXPORT
operator<=(
const String& str,
const char* c_str);
5379 bool CEGUIEXPORT
operator<=(
const char* c_str,
const String& str);
5385 bool CEGUIEXPORT
operator>=(
const String& str,
const char* c_str);
5391 bool CEGUIEXPORT
operator>=(
const char* c_str,
const String& str);
5411 String CEGUIEXPORT
operator+(
const String& str1,
const String& str2);
5428 String CEGUIEXPORT
operator+(
const String& str,
const std::string& std_str);
5445 String CEGUIEXPORT
operator+(
const std::string& std_str,
const String& str);
5462 String CEGUIEXPORT
operator+(
const String& str,
const utf8* utf8_str);
5479 String CEGUIEXPORT
operator+(
const utf8* utf8_str,
const String& str);
5496 String CEGUIEXPORT
operator+(
const String& str, utf32 code_point);
5513 String CEGUIEXPORT
operator+(utf32 code_point,
const String& str);
5530 String CEGUIEXPORT
operator+(
const String& str,
const char* c_str);
5547 String CEGUIEXPORT
operator+(
const char* c_str,
const String& str);
5553 CEGUIEXPORT std::ostream& operator<<(std::ostream& s,
const String& str);
5572 void CEGUIEXPORT
swap(String& str1, String& str2);
5581 bool operator() (
const String& a,
const String& b)
const
5583 const size_t la = a.
length();
5584 const size_t lb = b.
length();
5586 return (memcmp(a.
ptr(), b.
ptr(), la *
sizeof(utf32)) < 0);
5597 #if CEGUI_STRING_CLASS == CEGUI_STRING_CLASS_STD
5599 typedef std::string
String;
5601 #else // CEGUI_STRING_CLASS_STD_AO
5603 typedef std::basic_string<char, std::char_traits<char>, STLAllocatorWrapper<char, AllocatorConfig<STLAllocator>::Allocator> >
String;
5614 bool operator() (
const String& a,
const String& b)
const
5616 const size_t la = a.
length();
5617 const size_t lb = b.
length();
5625 #if defined(_MSC_VER)
5626 # pragma warning(disable : 4251)
5634 #endif // end of guard _CEGUIString_h_