30 #ifndef _CEGUIString_h_
31 #define _CEGUIString_h_
33 #include "CEGUIBase.h"
42 #define STR_QUICKBUFF_SIZE 32
81 mutable utf8* d_encodedbuff;
85 utf32 d_quickbuff[STR_QUICKBUFF_SIZE];
93 class iterator :
public std::iterator<std::random_access_iterator_tag, utf32>
97 explicit iterator(utf32*
const ptr) : d_ptr(ptr) {}
99 utf32& operator*()
const
104 utf32* operator->()
const
144 return temp += offset;
149 return *
this += -offset;
155 return temp -= offset;
160 return *(*
this + offset);
165 {
return lhs.d_ptr - rhs.d_ptr; }
168 {
return iter + offset; }
172 {
return lhs.d_ptr == rhs.d_ptr; }
176 {
return lhs.d_ptr != rhs.d_ptr; }
180 {
return lhs.d_ptr < rhs.d_ptr; }
184 {
return lhs.d_ptr > rhs.d_ptr; }
188 {
return lhs.d_ptr <= rhs.d_ptr; }
192 {
return lhs.d_ptr >= rhs.d_ptr; }
198 class const_iterator :
public std::iterator<std::random_access_iterator_tag, const utf32>
205 const utf32& operator*()
const
210 const utf32* operator->()
const
250 return temp += offset;
255 return *
this += -offset;
261 return temp -= offset;
266 return *(*
this + offset);
276 {
return iter + offset; }
280 {
return lhs.d_ptr - rhs.d_ptr; }
284 {
return lhs.d_ptr == rhs.d_ptr; }
288 {
return lhs.d_ptr != rhs.d_ptr; }
292 {
return lhs.d_ptr < rhs.d_ptr; }
296 {
return lhs.d_ptr > rhs.d_ptr; }
300 {
return lhs.d_ptr <= rhs.d_ptr; }
304 {
return lhs.d_ptr >= rhs.d_ptr; }
313 #if defined(_MSC_VER) && ((_MSC_VER <= 1200) || ((_MSC_VER <= 1300) && defined(_STLPORT_VERSION)))
314 typedef std::reverse_iterator<const_iterator, const_pointer, const_reference, difference_type>
const_reverse_iterator;
323 #if defined(_MSC_VER) && ((_MSC_VER <= 1200) || ((_MSC_VER <= 1300) && defined(_STLPORT_VERSION)))
324 typedef std::reverse_iterator<iterator, pointer, reference, difference_type>
reverse_iterator;
337 bool operator() (
const String& a,
const String& b)
const
339 const size_t la = a.
length();
340 const size_t lb = b.
length();
342 return (memcmp(a.
ptr(), b.
ptr(), la*
sizeof(utf32)) < 0);
405 assign(str, str_idx, str_num);
458 assign(std_str, str_idx, str_num);
518 assign(utf8_str, chars_len);
542 assign(num, code_point);
565 append(iter_beg, iter_end);
608 assign(chars, chars_len);
646 bool empty(
void)
const
648 return (d_cplength == 0);
662 return (((
size_type)-1) /
sizeof(utf32));
680 return d_reserve - 1;
726 return compare(0, d_cplength, str);
760 if ((d_cplength < idx) || (str.d_cplength < str_idx))
761 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
763 if ((len == npos) || (idx + len > d_cplength))
764 len = d_cplength - idx;
766 if ((str_len == npos) || (str_idx + str_len > str.d_cplength))
767 str_len = str.d_cplength - str_idx;
769 int val = (len == 0) ? 0 : utf32_comp_utf32(&ptr()[idx], &str.
ptr()[str_idx], (len < str_len) ? len : str_len);
771 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_len) ? -1 : (len == str_len) ? 0 : 1;
794 int compare(
const std::string& std_str)
const
796 return compare(0, d_cplength, std_str);
835 if (d_cplength < idx)
836 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
838 if (std_str.size() < str_idx)
839 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
841 if ((len == npos) || (idx + len > d_cplength))
842 len = d_cplength - idx;
844 if ((str_len == npos) || (str_idx + str_len > std_str.size()))
845 str_len = (
size_type)std_str.size() - str_idx;
847 int val = (len == 0) ? 0 : utf32_comp_char(&ptr()[idx], &std_str.c_str()[str_idx], (len < str_len) ? len : str_len);
849 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_len) ? -1 : (len == str_len) ? 0 : 1;
874 int compare(
const utf8* utf8_str)
const
876 return compare(0, d_cplength, utf8_str, encoded_size(utf8_str));
911 return compare(idx, len, utf8_str, encoded_size(utf8_str));
949 if (d_cplength < idx)
950 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
952 if (str_cplen == npos)
953 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
955 if ((len == npos) || (idx + len > d_cplength))
956 len = d_cplength - idx;
958 int val = (len == 0) ? 0 : utf32_comp_utf8(&ptr()[idx], utf8_str, (len < str_cplen) ? len : str_cplen);
960 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_cplen) ? -1 : (len == str_cplen) ? 0 : 1;
979 int compare(
const char* cstr)
const
981 return compare(0, d_cplength, cstr, strlen(cstr));
1010 return compare(idx, len, cstr, strlen(cstr));
1043 if (d_cplength < idx)
1044 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1046 if (chars_len == npos)
1047 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
1049 if ((len == npos) || (idx + len > d_cplength))
1050 len = d_cplength - idx;
1052 int val = (len == 0) ? 0 : utf32_comp_char(&ptr()[idx], chars, (len < chars_len) ? len : chars_len);
1054 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < chars_len) ? -1 : (len == chars_len) ? 0 : 1;
1077 return (ptr()[idx]);
1113 if (d_cplength <= idx)
1114 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1133 if (d_cplength <= idx)
1134 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1156 const char* c_str(
void)
const
1158 return (
const char*)build_utf8_buff();
1174 const utf8* data(
void)
const
1176 return build_utf8_buff();
1185 return (d_reserve > STR_QUICKBUFF_SIZE) ? d_buffer : d_quickbuff;
1192 const utf32* ptr(
void)
const
1194 return (d_reserve > STR_QUICKBUFF_SIZE) ? d_buffer : d_quickbuff;
1221 if (d_cplength < idx)
1222 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1227 return encode(&ptr()[idx], buf, npos, len);
1251 using namespace std;
1253 if (d_cplength < idx)
1254 CEGUI_THROW(out_of_range(
"Index was out of range for CEGUI::String object"));
1258 return encoded_size(&ptr()[idx], ceguimin(num, maxlen));
1299 if (str.d_cplength < str_idx)
1300 CEGUI_THROW(std::out_of_range(
"Index was out of range for CEGUI::String object"));
1302 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
1303 str_num = str.d_cplength - str_idx;
1307 memcpy(ptr(), &str.
ptr()[str_idx], str_num *
sizeof(utf32));
1328 String& operator=(
const std::string& std_str)
1330 return assign(std_str);
1358 if (std_str.size() < str_idx)
1359 CEGUI_THROW(std::out_of_range(
"Index was out of range for std::string object"));
1361 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
1362 str_num = (
size_type)std_str.size() - str_idx;
1369 ((*this)[str_num]) = static_cast<utf32>(static_cast<unsigned char>(std_str[str_num + str_idx]));
1395 return assign(utf8_str, utf_length(utf8_str));
1418 return assign(utf8_str, utf_length(utf8_str));
1444 if (str_num == npos)
1445 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
1447 size_type enc_sze = encoded_size(utf8_str, str_num);
1450 encode(utf8_str, ptr(), d_reserve, str_num);
1467 return assign(1, code_point);
1488 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
1515 return assign(cstr, strlen(cstr));
1533 return assign(cstr, strlen(cstr));
1557 for (
size_type i = 0; i < chars_len; ++i)
1559 *pt++ =
static_cast<utf32
>(
static_cast<unsigned char>(*chars++));
1580 d_cplength = str.d_cplength;
1581 str.d_cplength = temp_len;
1584 d_reserve = str.d_reserve;
1585 str.d_reserve = temp_res;
1587 utf32* temp_buf = d_buffer;
1588 d_buffer = str.d_buffer;
1589 str.d_buffer = temp_buf;
1592 if (temp_res <= STR_QUICKBUFF_SIZE)
1594 utf32 temp_qbf[STR_QUICKBUFF_SIZE];
1596 memcpy(temp_qbf, d_quickbuff, STR_QUICKBUFF_SIZE *
sizeof(utf32));
1597 memcpy(d_quickbuff, str.d_quickbuff, STR_QUICKBUFF_SIZE *
sizeof(utf32));
1598 memcpy(str.d_quickbuff, temp_qbf, STR_QUICKBUFF_SIZE *
sizeof(utf32));
1644 if (str.d_cplength < str_idx)
1645 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1647 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
1648 str_num = str.d_cplength - str_idx;
1650 grow(d_cplength + str_num);
1651 memcpy(&ptr()[d_cplength], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
1652 setlen(d_cplength + str_num);
1673 String& operator+=(
const std::string& std_str)
1675 return append(std_str);
1703 if (std_str.size() < str_idx)
1704 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
1706 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
1707 str_num = (
size_type)std_str.size() - str_idx;
1709 size_type newsze = d_cplength + str_num;
1712 utf32* pt = &ptr()[newsze-1];
1715 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_num]));
1742 return append(utf8_str, utf_length(utf8_str));
1765 return append(utf8_str, utf_length(utf8_str));
1793 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
1795 size_type encsz = encoded_size(utf8_str, len);
1799 encode(utf8_str, &ptr()[d_cplength], encsz, len);
1820 return append(1, code_point);
1841 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
1846 utf32* p = &ptr()[d_cplength];
1868 void push_back(utf32 code_point)
1870 append(1, code_point);
1890 return replace(end(), end(), iter_beg, iter_end);
1908 return append(cstr, strlen(cstr));
1926 return append(cstr, strlen(cstr));
1947 if (chars_len == npos)
1948 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
1950 size_type newsz = d_cplength + chars_len;
1954 utf32* pt = &ptr()[newsz-1];
1957 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
1986 return insert(idx, str, 0, npos);
2013 if ((d_cplength < idx) || (str.d_cplength < str_idx))
2014 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2016 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
2017 str_num = str.d_cplength - str_idx;
2021 memmove(&ptr()[idx + str_num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2022 memcpy(&ptr()[idx], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
2050 return insert(idx, std_str, 0, npos);
2081 if (d_cplength < idx)
2082 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2084 if (std_str.size() < str_idx)
2085 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
2087 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
2088 str_num = (
size_type)std_str.size() - str_idx;
2093 memmove(&ptr()[idx + str_num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2095 utf32* pt = &ptr()[idx + str_num - 1];
2098 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_idx + str_num]));
2129 return insert(idx, utf8_str, utf_length(utf8_str));
2159 if (d_cplength < idx)
2160 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2163 CEGUI_THROW(std::length_error(
"Length of utf8 encoded string can not be 'npos'"));
2165 size_type encsz = encoded_size(utf8_str, len);
2169 memmove(&ptr()[idx + encsz], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2170 encode(utf8_str, &ptr()[idx], encsz, len);
2197 if (d_cplength < idx)
2198 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2201 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
2206 memmove(&ptr()[idx + num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2208 utf32* pt = &ptr()[idx + num - 1];
2238 insert(safe_iter_dif(pos, begin()), num, code_point);
2258 insert(pos, 1, code_point);
2282 replace(iter_pos, iter_pos, iter_beg, iter_end);
2304 return insert(idx, cstr, strlen(cstr));
2329 if (d_cplength < idx)
2330 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2332 if (chars_len == npos)
2333 CEGUI_THROW(std::length_error(
"Length of char array can not be 'npos'"));
2335 size_type newsz = d_cplength + chars_len;
2338 memmove(&ptr()[idx + chars_len], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2340 utf32* pt = &ptr()[idx + chars_len - 1];
2343 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
2394 return erase(idx, 1);
2418 if (d_cplength <= idx)
2419 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2422 len = d_cplength - idx;
2426 memmove(&ptr()[idx], &ptr()[idx + len], (d_cplength - idx - len) *
sizeof(utf32));
2443 return erase(safe_iter_dif(pos, begin()), 1);
2461 return erase(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg));
2481 resize(num, utf32());
2501 if (num < d_cplength)
2507 append(num - d_cplength, code_point);
2536 return replace(idx, len, str, 0, npos);
2562 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), str, 0, npos);
2592 if ((d_cplength < idx) || (str.d_cplength < str_idx))
2593 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2595 if (((str_idx + str_num) > str.d_cplength) || (str_num == npos))
2596 str_num = str.d_cplength - str_idx;
2598 if (((len + idx) > d_cplength) || (len == npos))
2599 len = d_cplength - idx;
2601 size_type newsz = d_cplength + str_num - len;
2605 if ((idx + len) < d_cplength)
2606 memmove(&ptr()[idx + str_num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2608 memcpy(&ptr()[idx], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
2640 return replace(idx, len, std_str, 0, npos);
2670 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), std_str, 0, npos);
2704 if (d_cplength < idx)
2705 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2707 if (std_str.size() < str_idx)
2708 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
2710 if (((str_idx + str_num) > std_str.size()) || (str_num == npos))
2711 str_num = (
size_type)std_str.size() - str_idx;
2713 if (((len + idx) > d_cplength) || (len == npos))
2714 len = d_cplength - idx;
2716 size_type newsz = d_cplength + str_num - len;
2720 if ((idx + len) < d_cplength)
2721 memmove(&ptr()[idx + str_num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2723 utf32* pt = &ptr()[idx + str_num - 1];
2726 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_idx + str_num]));
2761 return replace(idx, len, utf8_str, utf_length(utf8_str));
2793 return replace(iter_beg, iter_end, utf8_str, utf_length(utf8_str));
2826 if (d_cplength < idx)
2827 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2829 if (str_len == npos)
2830 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
2832 if (((len + idx) > d_cplength) || (len == npos))
2833 len = d_cplength - idx;
2835 size_type encsz = encoded_size(utf8_str, str_len);
2836 size_type newsz = d_cplength + encsz - len;
2840 if ((idx + len) < d_cplength)
2841 memmove(&ptr()[idx + encsz], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2843 encode(utf8_str, &ptr()[idx], encsz, str_len);
2881 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), utf8_str, str_len);
2908 if (d_cplength < idx)
2909 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2912 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
2914 if (((len + idx) > d_cplength) || (len == npos))
2915 len = d_cplength - idx;
2917 size_type newsz = d_cplength + num - len;
2921 if ((idx + len) < d_cplength)
2922 memmove(&ptr()[idx + num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2924 utf32* pt = &ptr()[idx + num - 1];
2960 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), num, code_point);
2990 if (iter_newBeg == iter_newEnd)
2992 erase(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg));
2996 size_type str_len = safe_iter_dif(iter_newEnd, iter_newBeg);
2997 size_type idx = safe_iter_dif(iter_beg, begin());
2998 size_type len = safe_iter_dif(iter_end, iter_beg);
3000 if ((len + idx) > d_cplength)
3001 len = d_cplength - idx;
3003 size_type newsz = d_cplength + str_len - len;
3007 if ((idx + len) < d_cplength)
3008 memmove(&ptr()[idx + str_len], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
3010 memcpy(&ptr()[idx], iter_newBeg.d_ptr, str_len *
sizeof(utf32));
3039 return replace(idx, len, cstr, strlen(cstr));
3066 return replace(iter_beg, iter_end, cstr, strlen(cstr));
3094 if (d_cplength < idx)
3095 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
3097 if (chars_len == npos)
3098 CEGUI_THROW(std::length_error(
"Length for the char array can not be 'npos'"));
3100 if (((len + idx) > d_cplength) || (len == npos))
3101 len = d_cplength - idx;
3103 size_type newsz = d_cplength + chars_len - len;
3107 if ((idx + len) < d_cplength)
3108 memmove(&ptr()[idx + chars_len], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
3110 utf32* pt = &ptr()[idx + chars_len - 1];
3113 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
3146 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), chars, chars_len);
3169 if (idx < d_cplength)
3171 const utf32* pt = &ptr()[idx];
3173 while (idx < d_cplength)
3175 if (*pt++ == code_point)
3202 if (idx >= d_cplength)
3203 idx = d_cplength - 1;
3207 const utf32* pt = &ptr()[idx];
3211 if (*pt-- == code_point)
3214 }
while (idx-- != 0);
3240 if ((str.d_cplength == 0) && (idx < d_cplength))
3243 if (idx < d_cplength)
3246 while (d_cplength - idx >= str.d_cplength)
3248 if (0 == compare(idx, str.d_cplength, str))
3275 if (str.d_cplength == 0)
3276 return (idx < d_cplength) ? idx : d_cplength;
3278 if (str.d_cplength <= d_cplength)
3280 if (idx > (d_cplength - str.d_cplength))
3281 idx = d_cplength - str.d_cplength;
3285 if (0 == compare(idx, str.d_cplength, str))
3288 }
while (idx-- != 0);
3315 std::string::size_type sze = std_str.size();
3317 if ((sze == 0) && (idx < d_cplength))
3320 if (idx < d_cplength)
3323 while (d_cplength - idx >= sze)
3325 if (0 == compare(idx, (
size_type)sze, std_str))
3356 std::string::size_type sze = std_str.size();
3359 return (idx < d_cplength) ? idx : d_cplength;
3361 if (sze <= d_cplength)
3363 if (idx > (d_cplength - sze))
3364 idx = d_cplength - sze;
3368 if (0 == compare(idx, (
size_type)sze, std_str))
3371 }
while (idx-- != 0);
3402 return find(utf8_str, idx, utf_length(utf8_str));
3429 return rfind(utf8_str, idx, utf_length(utf8_str));
3459 if (str_len == npos)
3460 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3462 size_type sze = encoded_size(utf8_str, str_len);
3464 if ((sze == 0) && (idx < d_cplength))
3467 if (idx < d_cplength)
3470 while (d_cplength - idx >= sze)
3472 if (0 == compare(idx, sze, utf8_str, sze))
3510 if (str_len == npos)
3511 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3513 size_type sze = encoded_size(utf8_str, str_len);
3516 return (idx < d_cplength) ? idx : d_cplength;
3518 if (sze <= d_cplength)
3520 if (idx > (d_cplength - sze))
3521 idx = d_cplength - sze;
3525 if (0 == compare(idx, sze, utf8_str, sze))
3528 }
while (idx-- != 0);
3554 return find(cstr, idx, strlen(cstr));
3576 return rfind(cstr, idx, strlen(cstr));
3601 if (chars_len == npos)
3602 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
3604 if ((chars_len == 0) && (idx < d_cplength))
3607 if (idx < d_cplength)
3610 while (d_cplength - idx >= chars_len)
3612 if (0 == compare(idx, chars_len, chars, chars_len))
3645 if (chars_len == npos)
3646 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
3649 return (idx < d_cplength) ? idx : d_cplength;
3651 if (chars_len <= d_cplength)
3653 if (idx > (d_cplength - chars_len))
3654 idx = d_cplength - chars_len;
3658 if (0 == compare(idx, chars_len, chars, chars_len))
3661 }
while (idx-- != 0);
3688 if (idx < d_cplength)
3690 const utf32* pt = &ptr()[idx];
3694 if (npos != str.
find(*pt++))
3697 }
while (++idx != d_cplength);
3720 if (idx < d_cplength)
3722 const utf32* pt = &ptr()[idx];
3726 if (npos == str.
find(*pt++))
3729 }
while (++idx != d_cplength);
3757 if (idx < d_cplength)
3759 const utf32* pt = &ptr()[idx];
3763 if (npos != find_codepoint(std_str, *pt++))
3766 }
while (++idx != d_cplength);
3793 if (idx < d_cplength)
3795 const utf32* pt = &ptr()[idx];
3799 if (npos == find_codepoint(std_str, *pt++))
3802 }
while (++idx != d_cplength);
3834 return find_first_of(utf8_str, idx, utf_length(utf8_str));
3861 return find_first_not_of(utf8_str, idx, utf_length(utf8_str));
3891 if (str_len == npos)
3892 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3894 if (idx < d_cplength)
3896 size_type encsze = encoded_size(utf8_str, str_len);
3898 const utf32* pt = &ptr()[idx];
3902 if (npos != find_codepoint(utf8_str, encsze, *pt++))
3905 }
while (++idx != d_cplength);
3939 if (str_len == npos)
3940 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3942 if (idx < d_cplength)
3944 size_type encsze = encoded_size(utf8_str, str_len);
3946 const utf32* pt = &ptr()[idx];
3950 if (npos == find_codepoint(utf8_str, encsze, *pt++))
3953 }
while (++idx != d_cplength);
3977 return find(code_point, idx);
3998 if (idx < d_cplength)
4002 if ((*
this)[idx] != code_point)
4005 }
while(idx++ < d_cplength);
4031 return find_first_of(cstr, idx, strlen(cstr));
4053 return find_first_not_of(cstr, idx, strlen(cstr));
4078 if (chars_len == npos)
4079 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4081 if (idx < d_cplength)
4083 const utf32* pt = &ptr()[idx];
4087 if (npos != find_codepoint(chars, chars_len, *pt++))
4090 }
while (++idx != d_cplength);
4119 if (chars_len == npos)
4120 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4122 if (idx < d_cplength)
4124 const utf32* pt = &ptr()[idx];
4128 if (npos == find_codepoint(chars, chars_len, *pt++))
4131 }
while (++idx != d_cplength);
4160 if (idx >= d_cplength)
4161 idx = d_cplength - 1;
4163 const utf32* pt = &ptr()[idx];
4167 if (npos != str.
find(*pt--))
4170 }
while (idx-- != 0);
4195 if (idx >= d_cplength)
4196 idx = d_cplength - 1;
4198 const utf32* pt = &ptr()[idx];
4202 if (npos == str.
find(*pt--))
4205 }
while (idx-- != 0);
4235 if (idx >= d_cplength)
4236 idx = d_cplength - 1;
4238 const utf32* pt = &ptr()[idx];
4242 if (npos != find_codepoint(std_str, *pt--))
4245 }
while (idx-- != 0);
4274 if (idx >= d_cplength)
4275 idx = d_cplength - 1;
4277 const utf32* pt = &ptr()[idx];
4281 if (npos == find_codepoint(std_str, *pt--))
4284 }
while (idx-- != 0);
4316 return find_last_of(utf8_str, idx, utf_length(utf8_str));
4343 return find_last_not_of(utf8_str, idx, utf_length(utf8_str));
4373 if (str_len == npos)
4374 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
4378 if (idx >= d_cplength)
4379 idx = d_cplength - 1;
4381 size_type encsze = encoded_size(utf8_str, str_len);
4383 const utf32* pt = &ptr()[idx];
4387 if (npos != find_codepoint(utf8_str, encsze, *pt--))
4390 }
while (idx-- != 0);
4424 if (str_len == npos)
4425 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
4429 if (idx >= d_cplength)
4430 idx = d_cplength - 1;
4432 size_type encsze = encoded_size(utf8_str, str_len);
4434 const utf32* pt = &ptr()[idx];
4438 if (npos == find_codepoint(utf8_str, encsze, *pt--))
4441 }
while (idx-- != 0);
4465 return rfind(code_point, idx);
4486 if (idx >= d_cplength)
4487 idx = d_cplength - 1;
4491 if ((*
this)[idx] != code_point)
4494 }
while(idx-- != 0);
4520 return find_last_of(cstr, idx, strlen(cstr));
4542 return find_last_not_of(cstr, idx, strlen(cstr));
4567 if (chars_len == npos)
4568 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4572 if (idx >= d_cplength)
4573 idx = d_cplength - 1;
4575 const utf32* pt = &ptr()[idx];
4579 if (npos != find_codepoint(chars, chars_len, *pt--))
4582 }
while (idx-- != 0);
4611 if (chars_len == npos)
4612 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4616 if (idx >= d_cplength)
4617 idx = d_cplength - 1;
4619 const utf32* pt = &ptr()[idx];
4623 if (npos == find_codepoint(chars, chars_len, *pt--))
4626 }
while (idx-- != 0);
4654 if (d_cplength < idx)
4655 CEGUI_THROW(std::out_of_range(
"Index is out of range for this CEGUI::String"));
4657 return String(*
this, idx, len);
4696 return iterator(&ptr()[d_cplength]);
4768 bool grow(size_type new_size);
4774 void setlen(size_type len)
4777 ptr()[len] = (utf32)(0);
4783 d_reserve = STR_QUICKBUFF_SIZE;
4785 d_encodedbufflen = 0;
4786 d_encodeddatlen = 0;
4792 bool inside(utf32* inptr)
4794 if (inptr < ptr() || ptr() + d_cplength <= inptr)
4801 size_type safe_iter_dif(
const const_iterator& iter1,
const const_iterator& iter2)
const
4803 return (iter1.d_ptr == 0) ? 0 : (iter1 - iter2);
4811 size_type encode(
const utf32* src, utf8* dest, size_type dest_len, size_type src_len = 0)
const
4816 src_len = utf_length(src);
4819 size_type destCapacity = dest_len;
4822 for (uint idx = 0; idx < src_len; ++idx)
4824 utf32 cp = src[idx];
4827 if (destCapacity < encoded_size(cp))
4837 else if (cp < 0x0800)
4839 *dest++ = (utf8)((cp >> 6) | 0xC0);
4840 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4843 else if (cp < 0x10000)
4845 *dest++ = (utf8)((cp >> 12) | 0xE0);
4846 *dest++ = (utf8)(((cp >> 6) & 0x3F) | 0x80);
4847 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4852 *dest++ = (utf8)((cp >> 18) | 0xF0);
4853 *dest++ = (utf8)(((cp >> 12) & 0x3F) | 0x80);
4854 *dest++ = (utf8)(((cp >> 6) & 0x3F) | 0x80);
4855 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4861 return dest_len - destCapacity;
4864 size_type encode(
const utf8* src, utf32* dest, size_type dest_len, size_type src_len = 0)
const
4869 src_len = utf_length(src);
4872 size_type destCapacity = dest_len;
4875 for (uint idx = 0; ((idx < src_len) && (destCapacity > 0));)
4878 utf8 cu = src[idx++];
4886 cp = ((cu & 0x1F) << 6);
4887 cp |= (src[idx++] & 0x3F);
4891 cp = ((cu & 0x0F) << 12);
4892 cp |= ((src[idx++] & 0x3F) << 6);
4893 cp |= (src[idx++] & 0x3F);
4897 cp = ((cu & 0x07) << 18);
4898 cp |= ((src[idx++] & 0x3F) << 12);
4899 cp |= ((src[idx++] & 0x3F) << 6);
4900 cp |= (src[idx++] & 0x3F);
4907 return dest_len - destCapacity;
4911 size_type encoded_size(utf32 code_point)
const
4913 if (code_point < 0x80)
4915 else if (code_point < 0x0800)
4917 else if (code_point < 0x10000)
4924 size_type encoded_size(
const utf32* buf)
const
4926 return encoded_size(buf, utf_length(buf));
4930 size_type encoded_size(
const utf32* buf, size_type len)
const
4932 size_type count = 0;
4936 count += encoded_size(*buf++);
4943 size_type encoded_size(
const utf8* buf)
const
4945 return encoded_size(buf, utf_length(buf));
4949 size_type encoded_size(
const utf8* buf, size_type len)
const
4952 size_type count = 0;
4963 else if (tcp < 0xE0)
4968 else if (tcp < 0xF0)
4989 size_type utf_length(
const utf8* utf8_str)
const
4999 size_type utf_length(
const utf32* utf32_str)
const
5002 while (*utf32_str++)
5009 utf8* build_utf8_buff(
void)
const;
5012 int utf32_comp_utf32(
const utf32* buf1,
const utf32* buf2, size_type cp_count)
const
5017 while ((--cp_count) && (*buf1 == *buf2))
5020 return *buf1 - *buf2;
5024 int utf32_comp_char(
const utf32* buf1,
const char* buf2, size_type cp_count)
const
5029 while ((--cp_count) && (*buf1 == static_cast<utf32>(static_cast<unsigned char>(*buf2))))
5032 return *buf1 -
static_cast<utf32
>(
static_cast<unsigned char>(*buf2));
5036 int utf32_comp_utf8(
const utf32* buf1,
const utf8* buf2, size_type cp_count)
const
5054 cp = ((cu & 0x1F) << 6);
5055 cp |= (*buf2++ & 0x3F);
5059 cp = ((cu & 0x0F) << 12);
5060 cp |= ((*buf2++ & 0x3F) << 6);
5061 cp |= (*buf2++ & 0x3F);
5065 cp = ((cu & 0x07) << 18);
5066 cp |= ((*buf2++ & 0x3F) << 12);
5067 cp |= ((*buf2++ & 0x3F) << 6);
5068 cp |= (*buf2++ & 0x3F);
5071 }
while ((*buf1++ == cp) && (--cp_count));
5073 return (*--buf1) - cp;
5077 size_type find_codepoint(
const std::string& str, utf32 code_point)
const
5079 size_type idx = 0, sze = (size_type)str.size();
5083 if (code_point == static_cast<utf32>(static_cast<unsigned char>(str[idx])))
5093 size_type find_codepoint(
const utf8* str, size_type len, utf32 code_point)
const
5100 while (idx != len) {
5109 cp = ((cu & 0x1F) << 6);
5110 cp |= (*str++ & 0x3F);
5114 cp = ((cu & 0x0F) << 12);
5115 cp |= ((*str++ & 0x3F) << 6);
5116 cp |= (*str++ & 0x3F);
5120 cp = ((cu & 0x07) << 18);
5121 cp |= ((*str++ & 0x3F) << 12);
5122 cp |= ((*str++ & 0x3F) << 6);
5123 cp |= (*str++ & 0x3F);
5126 if (code_point == cp)
5137 size_type find_codepoint(
const char* chars, size_type chars_len, utf32 code_point)
const
5139 for (size_type idx = 0; idx != chars_len; ++idx)
5141 if (code_point == static_cast<utf32>(static_cast<unsigned char>(chars[idx])))
5158 bool CEGUIEXPORT
operator==(
const String& str1,
const String& str2);
5164 bool CEGUIEXPORT
operator==(
const String& str,
const std::string& std_str);
5170 bool CEGUIEXPORT
operator==(
const std::string& std_str,
const String& str);
5176 bool CEGUIEXPORT
operator==(
const String& str,
const utf8* utf8_str);
5182 bool CEGUIEXPORT
operator==(
const utf8* utf8_str,
const String& str);
5188 bool CEGUIEXPORT
operator!=(
const String& str1,
const String& str2);
5194 bool CEGUIEXPORT
operator!=(
const String& str,
const std::string& std_str);
5200 bool CEGUIEXPORT
operator!=(
const std::string& std_str,
const String& str);
5206 bool CEGUIEXPORT
operator!=(
const String& str,
const utf8* utf8_str);
5212 bool CEGUIEXPORT
operator!=(
const utf8* utf8_str,
const String& str);
5218 bool CEGUIEXPORT
operator<(
const String& str1,
const String& str2);
5224 bool CEGUIEXPORT
operator<(
const String& str,
const std::string& std_str);
5230 bool CEGUIEXPORT
operator<(
const std::string& std_str,
const String& str);
5236 bool CEGUIEXPORT
operator<(
const String& str,
const utf8* utf8_str);
5242 bool CEGUIEXPORT
operator<(
const utf8* utf8_str,
const String& str);
5248 bool CEGUIEXPORT
operator>(
const String& str1,
const String& str2);
5254 bool CEGUIEXPORT
operator>(
const String& str,
const std::string& std_str);
5260 bool CEGUIEXPORT
operator>(
const std::string& std_str,
const String& str);
5266 bool CEGUIEXPORT
operator>(
const String& str,
const utf8* utf8_str);
5272 bool CEGUIEXPORT
operator>(
const utf8* utf8_str,
const String& str);
5278 bool CEGUIEXPORT
operator<=(
const String& str1,
const String& str2);
5284 bool CEGUIEXPORT
operator<=(
const String& str,
const std::string& std_str);
5290 bool CEGUIEXPORT
operator<=(
const std::string& std_str,
const String& str);
5296 bool CEGUIEXPORT
operator<=(
const String& str,
const utf8* utf8_str);
5302 bool CEGUIEXPORT
operator<=(
const utf8* utf8_str,
const String& str);
5308 bool CEGUIEXPORT
operator>=(
const String& str1,
const String& str2);
5314 bool CEGUIEXPORT
operator>=(
const String& str,
const std::string& std_str);
5320 bool CEGUIEXPORT
operator>=(
const std::string& std_str,
const String& str);
5326 bool CEGUIEXPORT
operator>=(
const String& str,
const utf8* utf8_str);
5332 bool CEGUIEXPORT
operator>=(
const utf8* utf8_str,
const String& str);
5338 bool CEGUIEXPORT
operator==(
const String& str,
const char* c_str);
5344 bool CEGUIEXPORT
operator==(
const char* c_str,
const String& str);
5350 bool CEGUIEXPORT
operator!=(
const String& str,
const char* c_str);
5356 bool CEGUIEXPORT
operator!=(
const char* c_str,
const String& str);
5362 bool CEGUIEXPORT
operator<(
const String& str,
const char* c_str);
5368 bool CEGUIEXPORT
operator<(
const char* c_str,
const String& str);
5374 bool CEGUIEXPORT
operator>(
const String& str,
const char* c_str);
5380 bool CEGUIEXPORT
operator>(
const char* c_str,
const String& str);
5386 bool CEGUIEXPORT
operator<=(
const String& str,
const char* c_str);
5392 bool CEGUIEXPORT
operator<=(
const char* c_str,
const String& str);
5398 bool CEGUIEXPORT
operator>=(
const String& str,
const char* c_str);
5404 bool CEGUIEXPORT
operator>=(
const char* c_str,
const String& str);
5424 String CEGUIEXPORT
operator+(
const String& str1,
const String& str2);
5441 String CEGUIEXPORT
operator+(
const String& str,
const std::string& std_str);
5458 String CEGUIEXPORT
operator+(
const std::string& std_str,
const String& str);
5475 String CEGUIEXPORT
operator+(
const String& str,
const utf8* utf8_str);
5492 String CEGUIEXPORT
operator+(
const utf8* utf8_str,
const String& str);
5509 String CEGUIEXPORT
operator+(
const String& str, utf32 code_point);
5526 String CEGUIEXPORT
operator+(utf32 code_point,
const String& str);
5543 String CEGUIEXPORT
operator+(
const String& str,
const char* c_str);
5560 String CEGUIEXPORT
operator+(
const char* c_str,
const String& str);
5566 CEGUIEXPORT std::ostream& operator<<(std::ostream& s,
const String& str);
5585 void CEGUIEXPORT
swap(String& str1, String& str2);
5591 #endif // end of guard _CEGUIString_h_