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];
92 class iterator :
public std::iterator<std::random_access_iterator_tag, utf32>
96 explicit iterator(utf32*
const ptr) : d_ptr(ptr) {}
98 utf32& operator*()
const
103 utf32* operator->()
const
143 return temp += offset;
148 return *
this += -offset;
154 return temp -= offset;
159 return *(*
this + offset);
164 {
return lhs.d_ptr - rhs.d_ptr; }
167 {
return iter + offset; }
171 {
return lhs.d_ptr == rhs.d_ptr; }
175 {
return lhs.d_ptr != rhs.d_ptr; }
179 {
return lhs.d_ptr < rhs.d_ptr; }
183 {
return lhs.d_ptr > rhs.d_ptr; }
187 {
return lhs.d_ptr <= rhs.d_ptr; }
191 {
return lhs.d_ptr >= rhs.d_ptr; }
197 class const_iterator :
public std::iterator<std::random_access_iterator_tag, const utf32>
204 const utf32& operator*()
const
209 const utf32* operator->()
const
249 return temp += offset;
254 return *
this += -offset;
260 return temp -= offset;
265 return *(*
this + offset);
275 {
return iter + offset; }
279 {
return lhs.d_ptr - rhs.d_ptr; }
283 {
return lhs.d_ptr == rhs.d_ptr; }
287 {
return lhs.d_ptr != rhs.d_ptr; }
291 {
return lhs.d_ptr < rhs.d_ptr; }
295 {
return lhs.d_ptr > rhs.d_ptr; }
299 {
return lhs.d_ptr <= rhs.d_ptr; }
303 {
return lhs.d_ptr >= rhs.d_ptr; }
312 #if defined(_MSC_VER) && ((_MSC_VER <= 1200) || ((_MSC_VER <= 1300) && defined(_STLPORT_VERSION)))
313 typedef std::reverse_iterator<const_iterator, const_pointer, const_reference, difference_type>
const_reverse_iterator;
322 #if defined(_MSC_VER) && ((_MSC_VER <= 1200) || ((_MSC_VER <= 1300) && defined(_STLPORT_VERSION)))
323 typedef std::reverse_iterator<iterator, pointer, reference, difference_type>
reverse_iterator;
336 bool operator() (
const String& a,
const String& b)
const
338 const size_t la = a.
length();
339 const size_t lb = b.
length();
341 return (memcmp(a.
ptr(), b.
ptr(), la*
sizeof(utf32)) < 0);
404 assign(str, str_idx, str_num);
457 assign(std_str, str_idx, str_num);
517 assign(utf8_str, chars_len);
541 assign(num, code_point);
564 append(iter_beg, iter_end);
607 assign(chars, chars_len);
645 bool empty(
void)
const
647 return (d_cplength == 0);
661 return (((
size_type)-1) /
sizeof(utf32));
679 return d_reserve - 1;
725 return compare(0, d_cplength, str);
759 if ((d_cplength < idx) || (str.d_cplength < str_idx))
760 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
762 if ((len == npos) || (idx + len > d_cplength))
763 len = d_cplength - idx;
765 if ((str_len == npos) || (str_idx + str_len > str.d_cplength))
766 str_len = str.d_cplength - str_idx;
768 int val = (len == 0) ? 0 : utf32_comp_utf32(&ptr()[idx], &str.
ptr()[str_idx], (len < str_len) ? len : str_len);
770 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_len) ? -1 : (len == str_len) ? 0 : 1;
793 int compare(
const std::string& std_str)
const
795 return compare(0, d_cplength, std_str);
834 if (d_cplength < idx)
835 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
837 if (std_str.size() < str_idx)
838 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
840 if ((len == npos) || (idx + len > d_cplength))
841 len = d_cplength - idx;
843 if ((str_len == npos) || (str_idx + str_len > std_str.size()))
844 str_len = (
size_type)std_str.size() - str_idx;
846 int val = (len == 0) ? 0 : utf32_comp_char(&ptr()[idx], &std_str.c_str()[str_idx], (len < str_len) ? len : str_len);
848 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_len) ? -1 : (len == str_len) ? 0 : 1;
873 int compare(
const utf8* utf8_str)
const
875 return compare(0, d_cplength, utf8_str, encoded_size(utf8_str));
910 return compare(idx, len, utf8_str, encoded_size(utf8_str));
948 if (d_cplength < idx)
949 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
951 if (str_cplen == npos)
952 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
954 if ((len == npos) || (idx + len > d_cplength))
955 len = d_cplength - idx;
957 int val = (len == 0) ? 0 : utf32_comp_utf8(&ptr()[idx], utf8_str, (len < str_cplen) ? len : str_cplen);
959 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_cplen) ? -1 : (len == str_cplen) ? 0 : 1;
978 int compare(
const char* cstr)
const
980 return compare(0, d_cplength, cstr, strlen(cstr));
1009 return compare(idx, len, cstr, strlen(cstr));
1042 if (d_cplength < idx)
1043 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1045 if (chars_len == npos)
1046 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
1048 if ((len == npos) || (idx + len > d_cplength))
1049 len = d_cplength - idx;
1051 int val = (len == 0) ? 0 : utf32_comp_char(&ptr()[idx], chars, (len < chars_len) ? len : chars_len);
1053 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < chars_len) ? -1 : (len == chars_len) ? 0 : 1;
1076 return (ptr()[idx]);
1112 if (d_cplength <= idx)
1113 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1132 if (d_cplength <= idx)
1133 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1155 const char* c_str(
void)
const
1157 return (
const char*)build_utf8_buff();
1173 const utf8* data(
void)
const
1175 return build_utf8_buff();
1184 return (d_reserve > STR_QUICKBUFF_SIZE) ? d_buffer : d_quickbuff;
1191 const utf32* ptr(
void)
const
1193 return (d_reserve > STR_QUICKBUFF_SIZE) ? d_buffer : d_quickbuff;
1220 if (d_cplength < idx)
1221 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1226 return encode(&ptr()[idx], buf, npos, len);
1250 using namespace std;
1252 if (d_cplength < idx)
1253 CEGUI_THROW(out_of_range(
"Index was out of range for CEGUI::String object"));
1257 return encoded_size(&ptr()[idx], ceguimin(num, maxlen));
1298 if (str.d_cplength < str_idx)
1299 CEGUI_THROW(std::out_of_range(
"Index was out of range for CEGUI::String object"));
1301 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
1302 str_num = str.d_cplength - str_idx;
1306 memcpy(ptr(), &str.
ptr()[str_idx], str_num *
sizeof(utf32));
1327 String& operator=(
const std::string& std_str)
1329 return assign(std_str);
1357 if (std_str.size() < str_idx)
1358 CEGUI_THROW(std::out_of_range(
"Index was out of range for std::string object"));
1360 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
1361 str_num = (
size_type)std_str.size() - str_idx;
1368 ((*this)[str_num]) = static_cast<utf32>(static_cast<unsigned char>(std_str[str_num + str_idx]));
1394 return assign(utf8_str, utf_length(utf8_str));
1417 return assign(utf8_str, utf_length(utf8_str));
1443 if (str_num == npos)
1444 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
1446 size_type enc_sze = encoded_size(utf8_str, str_num);
1449 encode(utf8_str, ptr(), d_reserve, str_num);
1466 return assign(1, code_point);
1487 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
1514 return assign(cstr, strlen(cstr));
1532 return assign(cstr, strlen(cstr));
1556 for (
size_type i = 0; i < chars_len; ++i)
1558 *pt++ =
static_cast<utf32
>(
static_cast<unsigned char>(*chars++));
1579 d_cplength = str.d_cplength;
1580 str.d_cplength = temp_len;
1583 d_reserve = str.d_reserve;
1584 str.d_reserve = temp_res;
1586 utf32* temp_buf = d_buffer;
1587 d_buffer = str.d_buffer;
1588 str.d_buffer = temp_buf;
1591 if (temp_res <= STR_QUICKBUFF_SIZE)
1593 utf32 temp_qbf[STR_QUICKBUFF_SIZE];
1595 memcpy(temp_qbf, d_quickbuff, STR_QUICKBUFF_SIZE *
sizeof(utf32));
1596 memcpy(d_quickbuff, str.d_quickbuff, STR_QUICKBUFF_SIZE *
sizeof(utf32));
1597 memcpy(str.d_quickbuff, temp_qbf, STR_QUICKBUFF_SIZE *
sizeof(utf32));
1643 if (str.d_cplength < str_idx)
1644 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1646 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
1647 str_num = str.d_cplength - str_idx;
1649 grow(d_cplength + str_num);
1650 memcpy(&ptr()[d_cplength], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
1651 setlen(d_cplength + str_num);
1672 String& operator+=(
const std::string& std_str)
1674 return append(std_str);
1702 if (std_str.size() < str_idx)
1703 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
1705 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
1706 str_num = (
size_type)std_str.size() - str_idx;
1708 size_type newsze = d_cplength + str_num;
1711 utf32* pt = &ptr()[newsze-1];
1714 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_num]));
1741 return append(utf8_str, utf_length(utf8_str));
1764 return append(utf8_str, utf_length(utf8_str));
1792 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
1794 size_type encsz = encoded_size(utf8_str, len);
1798 encode(utf8_str, &ptr()[d_cplength], encsz, len);
1819 return append(1, code_point);
1840 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
1845 utf32* p = &ptr()[d_cplength];
1867 void push_back(utf32 code_point)
1869 append(1, code_point);
1889 return replace(end(), end(), iter_beg, iter_end);
1907 return append(cstr, strlen(cstr));
1925 return append(cstr, strlen(cstr));
1946 if (chars_len == npos)
1947 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
1949 size_type newsz = d_cplength + chars_len;
1953 utf32* pt = &ptr()[newsz-1];
1956 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
1985 return insert(idx, str, 0, npos);
2012 if ((d_cplength < idx) || (str.d_cplength < str_idx))
2013 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2015 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
2016 str_num = str.d_cplength - str_idx;
2020 memmove(&ptr()[idx + str_num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2021 memcpy(&ptr()[idx], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
2049 return insert(idx, std_str, 0, npos);
2080 if (d_cplength < idx)
2081 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2083 if (std_str.size() < str_idx)
2084 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
2086 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
2087 str_num = (
size_type)std_str.size() - str_idx;
2092 memmove(&ptr()[idx + str_num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2094 utf32* pt = &ptr()[idx + str_num - 1];
2097 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_idx + str_num]));
2128 return insert(idx, utf8_str, utf_length(utf8_str));
2158 if (d_cplength < idx)
2159 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2162 CEGUI_THROW(std::length_error(
"Length of utf8 encoded string can not be 'npos'"));
2164 size_type encsz = encoded_size(utf8_str, len);
2168 memmove(&ptr()[idx + encsz], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2169 encode(utf8_str, &ptr()[idx], encsz, len);
2196 if (d_cplength < idx)
2197 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2200 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
2205 memmove(&ptr()[idx + num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2207 utf32* pt = &ptr()[idx + num - 1];
2237 insert(safe_iter_dif(pos, begin()), num, code_point);
2257 insert(pos, 1, code_point);
2281 replace(iter_pos, iter_pos, iter_beg, iter_end);
2303 return insert(idx, cstr, strlen(cstr));
2328 if (d_cplength < idx)
2329 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2331 if (chars_len == npos)
2332 CEGUI_THROW(std::length_error(
"Length of char array can not be 'npos'"));
2334 size_type newsz = d_cplength + chars_len;
2337 memmove(&ptr()[idx + chars_len], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2339 utf32* pt = &ptr()[idx + chars_len - 1];
2342 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
2393 return erase(idx, 1);
2417 if (d_cplength <= idx)
2418 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2421 len = d_cplength - idx;
2425 memmove(&ptr()[idx], &ptr()[idx + len], (d_cplength - idx - len) *
sizeof(utf32));
2442 return erase(safe_iter_dif(pos, begin()), 1);
2460 return erase(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg));
2480 resize(num, utf32());
2500 if (num < d_cplength)
2506 append(num - d_cplength, code_point);
2535 return replace(idx, len, str, 0, npos);
2561 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), str, 0, npos);
2591 if ((d_cplength < idx) || (str.d_cplength < str_idx))
2592 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2594 if (((str_idx + str_num) > str.d_cplength) || (str_num == npos))
2595 str_num = str.d_cplength - str_idx;
2597 if (((len + idx) > d_cplength) || (len == npos))
2598 len = d_cplength - idx;
2600 size_type newsz = d_cplength + str_num - len;
2604 if ((idx + len) < d_cplength)
2605 memmove(&ptr()[idx + str_num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2607 memcpy(&ptr()[idx], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
2639 return replace(idx, len, std_str, 0, npos);
2669 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), std_str, 0, npos);
2703 if (d_cplength < idx)
2704 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2706 if (std_str.size() < str_idx)
2707 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
2709 if (((str_idx + str_num) > std_str.size()) || (str_num == npos))
2710 str_num = (
size_type)std_str.size() - str_idx;
2712 if (((len + idx) > d_cplength) || (len == npos))
2713 len = d_cplength - idx;
2715 size_type newsz = d_cplength + str_num - len;
2719 if ((idx + len) < d_cplength)
2720 memmove(&ptr()[idx + str_num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2722 utf32* pt = &ptr()[idx + str_num - 1];
2725 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_idx + str_num]));
2760 return replace(idx, len, utf8_str, utf_length(utf8_str));
2792 return replace(iter_beg, iter_end, utf8_str, utf_length(utf8_str));
2825 if (d_cplength < idx)
2826 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2828 if (str_len == npos)
2829 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
2831 if (((len + idx) > d_cplength) || (len == npos))
2832 len = d_cplength - idx;
2834 size_type encsz = encoded_size(utf8_str, str_len);
2835 size_type newsz = d_cplength + encsz - len;
2839 if ((idx + len) < d_cplength)
2840 memmove(&ptr()[idx + encsz], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2842 encode(utf8_str, &ptr()[idx], encsz, str_len);
2880 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), utf8_str, str_len);
2907 if (d_cplength < idx)
2908 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2911 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
2913 if (((len + idx) > d_cplength) || (len == npos))
2914 len = d_cplength - idx;
2916 size_type newsz = d_cplength + num - len;
2920 if ((idx + len) < d_cplength)
2921 memmove(&ptr()[idx + num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2923 utf32* pt = &ptr()[idx + num - 1];
2959 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), num, code_point);
2989 if (iter_newBeg == iter_newEnd)
2991 erase(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg));
2995 size_type str_len = safe_iter_dif(iter_newEnd, iter_newBeg);
2996 size_type idx = safe_iter_dif(iter_beg, begin());
2997 size_type len = safe_iter_dif(iter_end, iter_beg);
2999 if ((len + idx) > d_cplength)
3000 len = d_cplength - idx;
3002 size_type newsz = d_cplength + str_len - len;
3006 if ((idx + len) < d_cplength)
3007 memmove(&ptr()[idx + str_len], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
3009 memcpy(&ptr()[idx], iter_newBeg.d_ptr, str_len *
sizeof(utf32));
3038 return replace(idx, len, cstr, strlen(cstr));
3065 return replace(iter_beg, iter_end, cstr, strlen(cstr));
3093 if (d_cplength < idx)
3094 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
3096 if (chars_len == npos)
3097 CEGUI_THROW(std::length_error(
"Length for the char array can not be 'npos'"));
3099 if (((len + idx) > d_cplength) || (len == npos))
3100 len = d_cplength - idx;
3102 size_type newsz = d_cplength + chars_len - len;
3106 if ((idx + len) < d_cplength)
3107 memmove(&ptr()[idx + chars_len], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
3109 utf32* pt = &ptr()[idx + chars_len - 1];
3112 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
3145 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), chars, chars_len);
3168 if (idx < d_cplength)
3170 const utf32* pt = &ptr()[idx];
3172 while (idx < d_cplength)
3174 if (*pt++ == code_point)
3201 if (idx >= d_cplength)
3202 idx = d_cplength - 1;
3206 const utf32* pt = &ptr()[idx];
3210 if (*pt-- == code_point)
3213 }
while (idx-- != 0);
3239 if ((str.d_cplength == 0) && (idx < d_cplength))
3242 if (idx < d_cplength)
3245 while (d_cplength - idx >= str.d_cplength)
3247 if (0 == compare(idx, str.d_cplength, str))
3274 if (str.d_cplength == 0)
3275 return (idx < d_cplength) ? idx : d_cplength;
3277 if (str.d_cplength <= d_cplength)
3279 if (idx > (d_cplength - str.d_cplength))
3280 idx = d_cplength - str.d_cplength;
3284 if (0 == compare(idx, str.d_cplength, str))
3287 }
while (idx-- != 0);
3314 std::string::size_type sze = std_str.size();
3316 if ((sze == 0) && (idx < d_cplength))
3319 if (idx < d_cplength)
3322 while (d_cplength - idx >= sze)
3324 if (0 == compare(idx, (
size_type)sze, std_str))
3355 std::string::size_type sze = std_str.size();
3358 return (idx < d_cplength) ? idx : d_cplength;
3360 if (sze <= d_cplength)
3362 if (idx > (d_cplength - sze))
3363 idx = d_cplength - sze;
3367 if (0 == compare(idx, (
size_type)sze, std_str))
3370 }
while (idx-- != 0);
3401 return find(utf8_str, idx, utf_length(utf8_str));
3428 return rfind(utf8_str, idx, utf_length(utf8_str));
3458 if (str_len == npos)
3459 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3461 size_type sze = encoded_size(utf8_str, str_len);
3463 if ((sze == 0) && (idx < d_cplength))
3466 if (idx < d_cplength)
3469 while (d_cplength - idx >= sze)
3471 if (0 == compare(idx, sze, utf8_str, sze))
3509 if (str_len == npos)
3510 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3512 size_type sze = encoded_size(utf8_str, str_len);
3515 return (idx < d_cplength) ? idx : d_cplength;
3517 if (sze <= d_cplength)
3519 if (idx > (d_cplength - sze))
3520 idx = d_cplength - sze;
3524 if (0 == compare(idx, sze, utf8_str, sze))
3527 }
while (idx-- != 0);
3553 return find(cstr, idx, strlen(cstr));
3575 return rfind(cstr, idx, strlen(cstr));
3600 if (chars_len == npos)
3601 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
3603 if ((chars_len == 0) && (idx < d_cplength))
3606 if (idx < d_cplength)
3609 while (d_cplength - idx >= chars_len)
3611 if (0 == compare(idx, chars_len, chars, chars_len))
3644 if (chars_len == npos)
3645 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
3648 return (idx < d_cplength) ? idx : d_cplength;
3650 if (chars_len <= d_cplength)
3652 if (idx > (d_cplength - chars_len))
3653 idx = d_cplength - chars_len;
3657 if (0 == compare(idx, chars_len, chars, chars_len))
3660 }
while (idx-- != 0);
3687 if (idx < d_cplength)
3689 const utf32* pt = &ptr()[idx];
3693 if (npos != str.
find(*pt++))
3696 }
while (++idx != d_cplength);
3719 if (idx < d_cplength)
3721 const utf32* pt = &ptr()[idx];
3725 if (npos == str.
find(*pt++))
3728 }
while (++idx != d_cplength);
3756 if (idx < d_cplength)
3758 const utf32* pt = &ptr()[idx];
3762 if (npos != find_codepoint(std_str, *pt++))
3765 }
while (++idx != d_cplength);
3792 if (idx < d_cplength)
3794 const utf32* pt = &ptr()[idx];
3798 if (npos == find_codepoint(std_str, *pt++))
3801 }
while (++idx != d_cplength);
3833 return find_first_of(utf8_str, idx, utf_length(utf8_str));
3860 return find_first_not_of(utf8_str, idx, utf_length(utf8_str));
3890 if (str_len == npos)
3891 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3893 if (idx < d_cplength)
3895 size_type encsze = encoded_size(utf8_str, str_len);
3897 const utf32* pt = &ptr()[idx];
3901 if (npos != find_codepoint(utf8_str, encsze, *pt++))
3904 }
while (++idx != d_cplength);
3938 if (str_len == npos)
3939 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3941 if (idx < d_cplength)
3943 size_type encsze = encoded_size(utf8_str, str_len);
3945 const utf32* pt = &ptr()[idx];
3949 if (npos == find_codepoint(utf8_str, encsze, *pt++))
3952 }
while (++idx != d_cplength);
3976 return find(code_point, idx);
3997 if (idx < d_cplength)
4001 if ((*
this)[idx] != code_point)
4004 }
while(idx++ < d_cplength);
4030 return find_first_of(cstr, idx, strlen(cstr));
4052 return find_first_not_of(cstr, idx, strlen(cstr));
4077 if (chars_len == npos)
4078 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4080 if (idx < d_cplength)
4082 const utf32* pt = &ptr()[idx];
4086 if (npos != find_codepoint(chars, chars_len, *pt++))
4089 }
while (++idx != d_cplength);
4118 if (chars_len == npos)
4119 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4121 if (idx < d_cplength)
4123 const utf32* pt = &ptr()[idx];
4127 if (npos == find_codepoint(chars, chars_len, *pt++))
4130 }
while (++idx != d_cplength);
4159 if (idx >= d_cplength)
4160 idx = d_cplength - 1;
4162 const utf32* pt = &ptr()[idx];
4166 if (npos != str.
find(*pt--))
4169 }
while (idx-- != 0);
4194 if (idx >= d_cplength)
4195 idx = d_cplength - 1;
4197 const utf32* pt = &ptr()[idx];
4201 if (npos == str.
find(*pt--))
4204 }
while (idx-- != 0);
4234 if (idx >= d_cplength)
4235 idx = d_cplength - 1;
4237 const utf32* pt = &ptr()[idx];
4241 if (npos != find_codepoint(std_str, *pt--))
4244 }
while (idx-- != 0);
4273 if (idx >= d_cplength)
4274 idx = d_cplength - 1;
4276 const utf32* pt = &ptr()[idx];
4280 if (npos == find_codepoint(std_str, *pt--))
4283 }
while (idx-- != 0);
4315 return find_last_of(utf8_str, idx, utf_length(utf8_str));
4342 return find_last_not_of(utf8_str, idx, utf_length(utf8_str));
4372 if (str_len == npos)
4373 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
4377 if (idx >= d_cplength)
4378 idx = d_cplength - 1;
4380 size_type encsze = encoded_size(utf8_str, str_len);
4382 const utf32* pt = &ptr()[idx];
4386 if (npos != find_codepoint(utf8_str, encsze, *pt--))
4389 }
while (idx-- != 0);
4423 if (str_len == npos)
4424 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
4428 if (idx >= d_cplength)
4429 idx = d_cplength - 1;
4431 size_type encsze = encoded_size(utf8_str, str_len);
4433 const utf32* pt = &ptr()[idx];
4437 if (npos == find_codepoint(utf8_str, encsze, *pt--))
4440 }
while (idx-- != 0);
4464 return rfind(code_point, idx);
4485 if (idx >= d_cplength)
4486 idx = d_cplength - 1;
4490 if ((*
this)[idx] != code_point)
4493 }
while(idx-- != 0);
4519 return find_last_of(cstr, idx, strlen(cstr));
4541 return find_last_not_of(cstr, idx, strlen(cstr));
4566 if (chars_len == npos)
4567 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4571 if (idx >= d_cplength)
4572 idx = d_cplength - 1;
4574 const utf32* pt = &ptr()[idx];
4578 if (npos != find_codepoint(chars, chars_len, *pt--))
4581 }
while (idx-- != 0);
4610 if (chars_len == npos)
4611 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4615 if (idx >= d_cplength)
4616 idx = d_cplength - 1;
4618 const utf32* pt = &ptr()[idx];
4622 if (npos == find_codepoint(chars, chars_len, *pt--))
4625 }
while (idx-- != 0);
4653 if (d_cplength < idx)
4654 CEGUI_THROW(std::out_of_range(
"Index is out of range for this CEGUI::String"));
4656 return String(*
this, idx, len);
4695 return iterator(&ptr()[d_cplength]);
4767 bool grow(size_type new_size);
4773 void setlen(size_type len)
4776 ptr()[len] = (utf32)(0);
4782 d_reserve = STR_QUICKBUFF_SIZE;
4784 d_encodedbufflen = 0;
4785 d_encodeddatlen = 0;
4791 bool inside(utf32* inptr)
4793 if (inptr < ptr() || ptr() + d_cplength <= inptr)
4800 size_type safe_iter_dif(
const const_iterator& iter1,
const const_iterator& iter2)
const
4802 return (iter1.d_ptr == 0) ? 0 : (iter1 - iter2);
4810 size_type encode(
const utf32* src, utf8* dest, size_type dest_len, size_type src_len = 0)
const
4815 src_len = utf_length(src);
4818 size_type destCapacity = dest_len;
4821 for (uint idx = 0; idx < src_len; ++idx)
4823 utf32 cp = src[idx];
4826 if (destCapacity < encoded_size(cp))
4836 else if (cp < 0x0800)
4838 *dest++ = (utf8)((cp >> 6) | 0xC0);
4839 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4842 else if (cp < 0x10000)
4844 *dest++ = (utf8)((cp >> 12) | 0xE0);
4845 *dest++ = (utf8)(((cp >> 6) & 0x3F) | 0x80);
4846 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4851 *dest++ = (utf8)((cp >> 18) | 0xF0);
4852 *dest++ = (utf8)(((cp >> 12) & 0x3F) | 0x80);
4853 *dest++ = (utf8)(((cp >> 6) & 0x3F) | 0x80);
4854 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4860 return dest_len - destCapacity;
4863 size_type encode(
const utf8* src, utf32* dest, size_type dest_len, size_type src_len = 0)
const
4868 src_len = utf_length(src);
4871 size_type destCapacity = dest_len;
4874 for (uint idx = 0; ((idx < src_len) && (destCapacity > 0));)
4877 utf8 cu = src[idx++];
4885 cp = ((cu & 0x1F) << 6);
4886 cp |= (src[idx++] & 0x3F);
4890 cp = ((cu & 0x0F) << 12);
4891 cp |= ((src[idx++] & 0x3F) << 6);
4892 cp |= (src[idx++] & 0x3F);
4896 cp = ((cu & 0x07) << 18);
4897 cp |= ((src[idx++] & 0x3F) << 12);
4898 cp |= ((src[idx++] & 0x3F) << 6);
4899 cp |= (src[idx++] & 0x3F);
4906 return dest_len - destCapacity;
4910 size_type encoded_size(utf32 code_point)
const
4912 if (code_point < 0x80)
4914 else if (code_point < 0x0800)
4916 else if (code_point < 0x10000)
4923 size_type encoded_size(
const utf32* buf)
const
4925 return encoded_size(buf, utf_length(buf));
4929 size_type encoded_size(
const utf32* buf, size_type len)
const
4931 size_type count = 0;
4935 count += encoded_size(*buf++);
4942 size_type encoded_size(
const utf8* buf)
const
4944 return encoded_size(buf, utf_length(buf));
4948 size_type encoded_size(
const utf8* buf, size_type len)
const
4951 size_type count = 0;
4962 else if (tcp < 0xE0)
4967 else if (tcp < 0xF0)
4988 size_type utf_length(
const utf8* utf8_str)
const
4998 size_type utf_length(
const utf32* utf32_str)
const
5001 while (*utf32_str++)
5008 utf8* build_utf8_buff(
void)
const;
5011 int utf32_comp_utf32(
const utf32* buf1,
const utf32* buf2, size_type cp_count)
const
5016 while ((--cp_count) && (*buf1 == *buf2))
5019 return *buf1 - *buf2;
5023 int utf32_comp_char(
const utf32* buf1,
const char* buf2, size_type cp_count)
const
5028 while ((--cp_count) && (*buf1 == static_cast<utf32>(static_cast<unsigned char>(*buf2))))
5031 return *buf1 -
static_cast<utf32
>(
static_cast<unsigned char>(*buf2));
5035 int utf32_comp_utf8(
const utf32* buf1,
const utf8* buf2, size_type cp_count)
const
5053 cp = ((cu & 0x1F) << 6);
5054 cp |= (*buf2++ & 0x3F);
5058 cp = ((cu & 0x0F) << 12);
5059 cp |= ((*buf2++ & 0x3F) << 6);
5060 cp |= (*buf2++ & 0x3F);
5064 cp = ((cu & 0x07) << 18);
5065 cp |= ((*buf2++ & 0x3F) << 12);
5066 cp |= ((*buf2++ & 0x3F) << 6);
5067 cp |= (*buf2++ & 0x3F);
5070 }
while ((*buf1++ == cp) && (--cp_count));
5072 return (*--buf1) - cp;
5076 size_type find_codepoint(
const std::string& str, utf32 code_point)
const
5078 size_type idx = 0, sze = (size_type)str.size();
5082 if (code_point == static_cast<utf32>(static_cast<unsigned char>(str[idx])))
5092 size_type find_codepoint(
const utf8* str, size_type len, utf32 code_point)
const
5099 while (idx != len) {
5108 cp = ((cu & 0x1F) << 6);
5109 cp |= (*str++ & 0x3F);
5113 cp = ((cu & 0x0F) << 12);
5114 cp |= ((*str++ & 0x3F) << 6);
5115 cp |= (*str++ & 0x3F);
5119 cp = ((cu & 0x07) << 18);
5120 cp |= ((*str++ & 0x3F) << 12);
5121 cp |= ((*str++ & 0x3F) << 6);
5122 cp |= (*str++ & 0x3F);
5125 if (code_point == cp)
5136 size_type find_codepoint(
const char* chars, size_type chars_len, utf32 code_point)
const
5138 for (size_type idx = 0; idx != chars_len; ++idx)
5140 if (code_point == static_cast<utf32>(static_cast<unsigned char>(chars[idx])))
5157 bool CEGUIEXPORT
operator==(
const String& str1,
const String& str2);
5163 bool CEGUIEXPORT
operator==(
const String& str,
const std::string& std_str);
5169 bool CEGUIEXPORT
operator==(
const std::string& std_str,
const String& str);
5175 bool CEGUIEXPORT
operator==(
const String& str,
const utf8* utf8_str);
5181 bool CEGUIEXPORT
operator==(
const utf8* utf8_str,
const String& str);
5187 bool CEGUIEXPORT
operator!=(
const String& str1,
const String& str2);
5193 bool CEGUIEXPORT
operator!=(
const String& str,
const std::string& std_str);
5199 bool CEGUIEXPORT
operator!=(
const std::string& std_str,
const String& str);
5205 bool CEGUIEXPORT
operator!=(
const String& str,
const utf8* utf8_str);
5211 bool CEGUIEXPORT
operator!=(
const utf8* utf8_str,
const String& str);
5217 bool CEGUIEXPORT
operator<(
const String& str1,
const String& str2);
5223 bool CEGUIEXPORT
operator<(
const String& str,
const std::string& std_str);
5229 bool CEGUIEXPORT
operator<(
const std::string& std_str,
const String& str);
5235 bool CEGUIEXPORT
operator<(
const String& str,
const utf8* utf8_str);
5241 bool CEGUIEXPORT
operator<(
const utf8* utf8_str,
const String& str);
5247 bool CEGUIEXPORT
operator>(
const String& str1,
const String& str2);
5253 bool CEGUIEXPORT
operator>(
const String& str,
const std::string& std_str);
5259 bool CEGUIEXPORT
operator>(
const std::string& std_str,
const String& str);
5265 bool CEGUIEXPORT
operator>(
const String& str,
const utf8* utf8_str);
5271 bool CEGUIEXPORT
operator>(
const utf8* utf8_str,
const String& str);
5277 bool CEGUIEXPORT
operator<=(
const String& str1,
const String& str2);
5283 bool CEGUIEXPORT
operator<=(
const String& str,
const std::string& std_str);
5289 bool CEGUIEXPORT
operator<=(
const std::string& std_str,
const String& str);
5295 bool CEGUIEXPORT
operator<=(
const String& str,
const utf8* utf8_str);
5301 bool CEGUIEXPORT
operator<=(
const utf8* utf8_str,
const String& str);
5307 bool CEGUIEXPORT
operator>=(
const String& str1,
const String& str2);
5313 bool CEGUIEXPORT
operator>=(
const String& str,
const std::string& std_str);
5319 bool CEGUIEXPORT
operator>=(
const std::string& std_str,
const String& str);
5325 bool CEGUIEXPORT
operator>=(
const String& str,
const utf8* utf8_str);
5331 bool CEGUIEXPORT
operator>=(
const utf8* utf8_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);
5397 bool CEGUIEXPORT
operator>=(
const String& str,
const char* c_str);
5403 bool CEGUIEXPORT
operator>=(
const char* c_str,
const String& str);
5423 String CEGUIEXPORT
operator+(
const String& str1,
const String& str2);
5440 String CEGUIEXPORT
operator+(
const String& str,
const std::string& std_str);
5457 String CEGUIEXPORT
operator+(
const std::string& std_str,
const String& str);
5474 String CEGUIEXPORT
operator+(
const String& str,
const utf8* utf8_str);
5491 String CEGUIEXPORT
operator+(
const utf8* utf8_str,
const String& str);
5508 String CEGUIEXPORT
operator+(
const String& str, utf32 code_point);
5525 String CEGUIEXPORT
operator+(utf32 code_point,
const String& str);
5542 String CEGUIEXPORT
operator+(
const String& str,
const char* c_str);
5559 String CEGUIEXPORT
operator+(
const char* c_str,
const String& str);
5565 CEGUIEXPORT std::ostream& operator<<(std::ostream& s,
const String& str);
5584 void CEGUIEXPORT
swap(String& str1, String& str2);
5590 #endif // end of guard _CEGUIString_h_