30 #ifndef _CEGUIString_h_
31 #define _CEGUIString_h_
33 #include "CEGUI/Base.h"
48 #if CEGUI_STRING_CLASS == CEGUI_STRING_CLASS_UNICODE
53 #define CEGUI_STR_QUICKBUFF_SIZE 32
87 mutable utf8* d_encodedbuff;
91 utf32 d_quickbuff[CEGUI_STR_QUICKBUFF_SIZE];
99 class iterator :
public std::iterator<std::random_access_iterator_tag, utf32>
103 explicit iterator(utf32*
const ptr) : d_ptr(ptr) {}
105 utf32& operator*()
const
110 utf32* operator->()
const
150 return temp += offset;
155 return *
this += -offset;
161 return temp -= offset;
166 return *(*
this + offset);
171 {
return lhs.d_ptr - rhs.d_ptr; }
174 {
return iter + offset; }
178 {
return lhs.d_ptr == rhs.d_ptr; }
182 {
return lhs.d_ptr != rhs.d_ptr; }
186 {
return lhs.d_ptr < rhs.d_ptr; }
190 {
return lhs.d_ptr > rhs.d_ptr; }
194 {
return lhs.d_ptr <= rhs.d_ptr; }
198 {
return lhs.d_ptr >= rhs.d_ptr; }
204 class const_iterator :
public std::iterator<std::random_access_iterator_tag, const utf32>
211 const utf32& operator*()
const
216 const utf32* operator->()
const
256 return temp += offset;
261 return *
this += -offset;
267 return temp -= offset;
272 return *(*
this + offset);
282 {
return iter + offset; }
286 {
return lhs.d_ptr - rhs.d_ptr; }
290 {
return lhs.d_ptr == rhs.d_ptr; }
294 {
return lhs.d_ptr != rhs.d_ptr; }
298 {
return lhs.d_ptr < rhs.d_ptr; }
302 {
return lhs.d_ptr > rhs.d_ptr; }
306 {
return lhs.d_ptr <= rhs.d_ptr; }
310 {
return lhs.d_ptr >= rhs.d_ptr; }
319 #if defined(_MSC_VER) && ((_MSC_VER <= 1200) || ((_MSC_VER <= 1300) && defined(_STLPORT_VERSION)))
320 typedef std::reverse_iterator<const_iterator, const_pointer, const_reference, difference_type>
const_reverse_iterator;
329 #if defined(_MSC_VER) && ((_MSC_VER <= 1200) || ((_MSC_VER <= 1300) && defined(_STLPORT_VERSION)))
330 typedef std::reverse_iterator<iterator, pointer, reference, difference_type>
reverse_iterator;
393 assign(str, str_idx, str_num);
446 assign(std_str, str_idx, str_num);
506 assign(utf8_str, chars_len);
530 assign(num, code_point);
553 append(iter_beg, iter_end);
596 assign(chars, chars_len);
634 bool empty(
void)
const
636 return (d_cplength == 0);
650 return (((
size_type)-1) /
sizeof(utf32));
668 return d_reserve - 1;
714 return compare(0, d_cplength, str);
748 if ((d_cplength < idx) || (str.d_cplength < str_idx))
749 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
751 if ((len == npos) || (idx + len > d_cplength))
752 len = d_cplength - idx;
754 if ((str_len == npos) || (str_idx + str_len > str.d_cplength))
755 str_len = str.d_cplength - str_idx;
757 int val = (len == 0) ? 0 : utf32_comp_utf32(&ptr()[idx], &str.
ptr()[str_idx], (len < str_len) ? len : str_len);
759 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_len) ? -1 : (len == str_len) ? 0 : 1;
782 int compare(
const std::string& std_str)
const
784 return compare(0, d_cplength, std_str);
823 if (d_cplength < idx)
824 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
826 if (std_str.size() < str_idx)
827 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
829 if ((len == npos) || (idx + len > d_cplength))
830 len = d_cplength - idx;
832 if ((str_len == npos) || (str_idx + str_len > std_str.size()))
833 str_len = (
size_type)std_str.size() - str_idx;
835 int val = (len == 0) ? 0 : utf32_comp_char(&ptr()[idx], &std_str.c_str()[str_idx], (len < str_len) ? len : str_len);
837 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_len) ? -1 : (len == str_len) ? 0 : 1;
862 int compare(
const utf8* utf8_str)
const
864 return compare(0, d_cplength, utf8_str, encoded_size(utf8_str));
899 return compare(idx, len, utf8_str, encoded_size(utf8_str));
937 if (d_cplength < idx)
938 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
940 if (str_cplen == npos)
941 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
943 if ((len == npos) || (idx + len > d_cplength))
944 len = d_cplength - idx;
946 int val = (len == 0) ? 0 : utf32_comp_utf8(&ptr()[idx], utf8_str, (len < str_cplen) ? len : str_cplen);
948 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < str_cplen) ? -1 : (len == str_cplen) ? 0 : 1;
967 int compare(
const char* cstr)
const
969 return compare(0, d_cplength, cstr, strlen(cstr));
998 return compare(idx, len, cstr, strlen(cstr));
1031 if (d_cplength < idx)
1032 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1034 if (chars_len == npos)
1035 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
1037 if ((len == npos) || (idx + len > d_cplength))
1038 len = d_cplength - idx;
1040 int val = (len == 0) ? 0 : utf32_comp_char(&ptr()[idx], chars, (len < chars_len) ? len : chars_len);
1042 return (val != 0) ? ((val < 0) ? -1 : 1) : (len < chars_len) ? -1 : (len == chars_len) ? 0 : 1;
1065 return (ptr()[idx]);
1101 if (d_cplength <= idx)
1102 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1121 if (d_cplength <= idx)
1122 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1144 const char* c_str(
void)
const
1146 return (
const char*)build_utf8_buff();
1162 const utf8* data(
void)
const
1164 return build_utf8_buff();
1173 return (d_reserve > CEGUI_STR_QUICKBUFF_SIZE) ? d_buffer : d_quickbuff;
1180 const utf32* ptr(
void)
const
1182 return (d_reserve > CEGUI_STR_QUICKBUFF_SIZE) ? d_buffer : d_quickbuff;
1209 if (d_cplength < idx)
1210 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1215 return encode(&ptr()[idx], buf, npos, len);
1239 using namespace std;
1241 if (d_cplength < idx)
1242 CEGUI_THROW(out_of_range(
"Index was out of range for CEGUI::String object"));
1246 return encoded_size(&ptr()[idx], ceguimin(num, maxlen));
1287 if (str.d_cplength < str_idx)
1288 CEGUI_THROW(std::out_of_range(
"Index was out of range for CEGUI::String object"));
1290 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
1291 str_num = str.d_cplength - str_idx;
1295 memcpy(ptr(), &str.
ptr()[str_idx], str_num *
sizeof(utf32));
1316 String& operator=(
const std::string& std_str)
1318 return assign(std_str);
1346 if (std_str.size() < str_idx)
1347 CEGUI_THROW(std::out_of_range(
"Index was out of range for std::string object"));
1349 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
1350 str_num = (
size_type)std_str.size() - str_idx;
1357 ((*this)[str_num]) = static_cast<utf32>(static_cast<unsigned char>(std_str[str_num + str_idx]));
1383 return assign(utf8_str, utf_length(utf8_str));
1406 return assign(utf8_str, utf_length(utf8_str));
1432 if (str_num == npos)
1433 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
1435 size_type enc_sze = encoded_size(utf8_str, str_num);
1438 encode(utf8_str, ptr(), d_reserve, str_num);
1455 return assign(1, code_point);
1476 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
1503 return assign(cstr, strlen(cstr));
1521 return assign(cstr, strlen(cstr));
1545 for (
size_type i = 0; i < chars_len; ++i)
1547 *pt++ =
static_cast<utf32
>(
static_cast<unsigned char>(*chars++));
1568 d_cplength = str.d_cplength;
1569 str.d_cplength = temp_len;
1572 d_reserve = str.d_reserve;
1573 str.d_reserve = temp_res;
1575 utf32* temp_buf = d_buffer;
1576 d_buffer = str.d_buffer;
1577 str.d_buffer = temp_buf;
1580 if (temp_res <= CEGUI_STR_QUICKBUFF_SIZE)
1582 utf32 temp_qbf[CEGUI_STR_QUICKBUFF_SIZE];
1584 memcpy(temp_qbf, d_quickbuff, CEGUI_STR_QUICKBUFF_SIZE *
sizeof(utf32));
1585 memcpy(d_quickbuff, str.d_quickbuff, CEGUI_STR_QUICKBUFF_SIZE *
sizeof(utf32));
1586 memcpy(str.d_quickbuff, temp_qbf, CEGUI_STR_QUICKBUFF_SIZE *
sizeof(utf32));
1632 if (str.d_cplength < str_idx)
1633 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
1635 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
1636 str_num = str.d_cplength - str_idx;
1638 grow(d_cplength + str_num);
1639 memcpy(&ptr()[d_cplength], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
1640 setlen(d_cplength + str_num);
1661 String& operator+=(
const std::string& std_str)
1663 return append(std_str);
1691 if (std_str.size() < str_idx)
1692 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
1694 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
1695 str_num = (
size_type)std_str.size() - str_idx;
1697 size_type newsze = d_cplength + str_num;
1700 utf32* pt = &ptr()[newsze-1];
1703 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_num]));
1730 return append(utf8_str, utf_length(utf8_str));
1753 return append(utf8_str, utf_length(utf8_str));
1781 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
1783 size_type encsz = encoded_size(utf8_str, len);
1787 encode(utf8_str, &ptr()[d_cplength], encsz, len);
1808 return append(1, code_point);
1829 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
1834 utf32* p = &ptr()[d_cplength];
1856 void push_back(utf32 code_point)
1858 append(1, code_point);
1878 return replace(end(), end(), iter_beg, iter_end);
1896 return append(cstr, strlen(cstr));
1914 return append(cstr, strlen(cstr));
1935 if (chars_len == npos)
1936 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
1938 size_type newsz = d_cplength + chars_len;
1942 utf32* pt = &ptr()[newsz-1];
1945 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
1974 return insert(idx, str, 0, npos);
2001 if ((d_cplength < idx) || (str.d_cplength < str_idx))
2002 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2004 if ((str_num == npos) || (str_num > str.d_cplength - str_idx))
2005 str_num = str.d_cplength - str_idx;
2009 memmove(&ptr()[idx + str_num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2010 memcpy(&ptr()[idx], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
2038 return insert(idx, std_str, 0, npos);
2069 if (d_cplength < idx)
2070 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2072 if (std_str.size() < str_idx)
2073 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
2075 if ((str_num == npos) || (str_num > (
size_type)std_str.size() - str_idx))
2076 str_num = (
size_type)std_str.size() - str_idx;
2081 memmove(&ptr()[idx + str_num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2083 utf32* pt = &ptr()[idx + str_num - 1];
2086 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_idx + str_num]));
2117 return insert(idx, utf8_str, utf_length(utf8_str));
2147 if (d_cplength < idx)
2148 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2151 CEGUI_THROW(std::length_error(
"Length of utf8 encoded string can not be 'npos'"));
2153 size_type encsz = encoded_size(utf8_str, len);
2157 memmove(&ptr()[idx + encsz], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2158 encode(utf8_str, &ptr()[idx], encsz, len);
2185 if (d_cplength < idx)
2186 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2189 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
2194 memmove(&ptr()[idx + num], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2196 utf32* pt = &ptr()[idx + num - 1];
2226 insert(safe_iter_dif(pos, begin()), num, code_point);
2246 insert(pos, 1, code_point);
2270 replace(iter_pos, iter_pos, iter_beg, iter_end);
2292 return insert(idx, cstr, strlen(cstr));
2317 if (d_cplength < idx)
2318 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2320 if (chars_len == npos)
2321 CEGUI_THROW(std::length_error(
"Length of char array can not be 'npos'"));
2323 size_type newsz = d_cplength + chars_len;
2326 memmove(&ptr()[idx + chars_len], &ptr()[idx], (d_cplength - idx) *
sizeof(utf32));
2328 utf32* pt = &ptr()[idx + chars_len - 1];
2331 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
2382 return erase(idx, 1);
2406 if (d_cplength <= idx)
2407 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2410 len = d_cplength - idx;
2414 memmove(&ptr()[idx], &ptr()[idx + len], (d_cplength - idx - len) *
sizeof(utf32));
2431 return erase(safe_iter_dif(pos, begin()), 1);
2449 return erase(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg));
2469 resize(num, utf32());
2489 if (num < d_cplength)
2495 append(num - d_cplength, code_point);
2524 return replace(idx, len, str, 0, npos);
2550 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), str, 0, npos);
2580 if ((d_cplength < idx) || (str.d_cplength < str_idx))
2581 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2583 if (((str_idx + str_num) > str.d_cplength) || (str_num == npos))
2584 str_num = str.d_cplength - str_idx;
2586 if (((len + idx) > d_cplength) || (len == npos))
2587 len = d_cplength - idx;
2589 size_type newsz = d_cplength + str_num - len;
2593 if ((idx + len) < d_cplength)
2594 memmove(&ptr()[idx + str_num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2596 memcpy(&ptr()[idx], &str.
ptr()[str_idx], str_num *
sizeof(utf32));
2628 return replace(idx, len, std_str, 0, npos);
2658 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), std_str, 0, npos);
2692 if (d_cplength < idx)
2693 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2695 if (std_str.size() < str_idx)
2696 CEGUI_THROW(std::out_of_range(
"Index is out of range for std::string"));
2698 if (((str_idx + str_num) > std_str.size()) || (str_num == npos))
2699 str_num = (
size_type)std_str.size() - str_idx;
2701 if (((len + idx) > d_cplength) || (len == npos))
2702 len = d_cplength - idx;
2704 size_type newsz = d_cplength + str_num - len;
2708 if ((idx + len) < d_cplength)
2709 memmove(&ptr()[idx + str_num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2711 utf32* pt = &ptr()[idx + str_num - 1];
2714 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(std_str[str_idx + str_num]));
2749 return replace(idx, len, utf8_str, utf_length(utf8_str));
2781 return replace(iter_beg, iter_end, utf8_str, utf_length(utf8_str));
2814 if (d_cplength < idx)
2815 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2817 if (str_len == npos)
2818 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
2820 if (((len + idx) > d_cplength) || (len == npos))
2821 len = d_cplength - idx;
2823 size_type encsz = encoded_size(utf8_str, str_len);
2824 size_type newsz = d_cplength + encsz - len;
2828 if ((idx + len) < d_cplength)
2829 memmove(&ptr()[idx + encsz], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2831 encode(utf8_str, &ptr()[idx], encsz, str_len);
2869 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), utf8_str, str_len);
2896 if (d_cplength < idx)
2897 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
2900 CEGUI_THROW(std::length_error(
"Code point count can not be 'npos'"));
2902 if (((len + idx) > d_cplength) || (len == npos))
2903 len = d_cplength - idx;
2905 size_type newsz = d_cplength + num - len;
2909 if ((idx + len) < d_cplength)
2910 memmove(&ptr()[idx + num], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2912 utf32* pt = &ptr()[idx + num - 1];
2948 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), num, code_point);
2978 if (iter_newBeg == iter_newEnd)
2980 erase(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg));
2984 size_type str_len = safe_iter_dif(iter_newEnd, iter_newBeg);
2985 size_type idx = safe_iter_dif(iter_beg, begin());
2986 size_type len = safe_iter_dif(iter_end, iter_beg);
2988 if ((len + idx) > d_cplength)
2989 len = d_cplength - idx;
2991 size_type newsz = d_cplength + str_len - len;
2995 if ((idx + len) < d_cplength)
2996 memmove(&ptr()[idx + str_len], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
2998 memcpy(&ptr()[idx], iter_newBeg.d_ptr, str_len *
sizeof(utf32));
3027 return replace(idx, len, cstr, strlen(cstr));
3054 return replace(iter_beg, iter_end, cstr, strlen(cstr));
3082 if (d_cplength < idx)
3083 CEGUI_THROW(std::out_of_range(
"Index is out of range for CEGUI::String"));
3085 if (chars_len == npos)
3086 CEGUI_THROW(std::length_error(
"Length for the char array can not be 'npos'"));
3088 if (((len + idx) > d_cplength) || (len == npos))
3089 len = d_cplength - idx;
3091 size_type newsz = d_cplength + chars_len - len;
3095 if ((idx + len) < d_cplength)
3096 memmove(&ptr()[idx + chars_len], &ptr()[len + idx], (d_cplength - idx - len) *
sizeof(utf32));
3098 utf32* pt = &ptr()[idx + chars_len - 1];
3101 *pt-- =
static_cast<utf32
>(
static_cast<unsigned char>(chars[chars_len]));
3134 return replace(safe_iter_dif(iter_beg, begin()), safe_iter_dif(iter_end, iter_beg), chars, chars_len);
3157 if (idx < d_cplength)
3159 const utf32* pt = &ptr()[idx];
3161 while (idx < d_cplength)
3163 if (*pt++ == code_point)
3190 if (idx >= d_cplength)
3191 idx = d_cplength - 1;
3195 const utf32* pt = &ptr()[idx];
3199 if (*pt-- == code_point)
3202 }
while (idx-- != 0);
3228 if ((str.d_cplength == 0) && (idx < d_cplength))
3231 if (idx < d_cplength)
3234 while (d_cplength - idx >= str.d_cplength)
3236 if (0 == compare(idx, str.d_cplength, str))
3263 if (str.d_cplength == 0)
3264 return (idx < d_cplength) ? idx : d_cplength;
3266 if (str.d_cplength <= d_cplength)
3268 if (idx > (d_cplength - str.d_cplength))
3269 idx = d_cplength - str.d_cplength;
3273 if (0 == compare(idx, str.d_cplength, str))
3276 }
while (idx-- != 0);
3303 std::string::size_type sze = std_str.size();
3305 if ((sze == 0) && (idx < d_cplength))
3308 if (idx < d_cplength)
3311 while (d_cplength - idx >= sze)
3313 if (0 == compare(idx, (
size_type)sze, std_str))
3344 std::string::size_type sze = std_str.size();
3347 return (idx < d_cplength) ? idx : d_cplength;
3349 if (sze <= d_cplength)
3351 if (idx > (d_cplength - sze))
3352 idx = d_cplength - sze;
3356 if (0 == compare(idx, (
size_type)sze, std_str))
3359 }
while (idx-- != 0);
3390 return find(utf8_str, idx, utf_length(utf8_str));
3417 return rfind(utf8_str, idx, utf_length(utf8_str));
3447 if (str_len == npos)
3448 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3450 size_type sze = encoded_size(utf8_str, str_len);
3452 if ((sze == 0) && (idx < d_cplength))
3455 if (idx < d_cplength)
3458 while (d_cplength - idx >= sze)
3460 if (0 == compare(idx, sze, utf8_str, sze))
3498 if (str_len == npos)
3499 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3501 size_type sze = encoded_size(utf8_str, str_len);
3504 return (idx < d_cplength) ? idx : d_cplength;
3506 if (sze <= d_cplength)
3508 if (idx > (d_cplength - sze))
3509 idx = d_cplength - sze;
3513 if (0 == compare(idx, sze, utf8_str, sze))
3516 }
while (idx-- != 0);
3542 return find(cstr, idx, strlen(cstr));
3564 return rfind(cstr, idx, strlen(cstr));
3589 if (chars_len == npos)
3590 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
3592 if ((chars_len == 0) && (idx < d_cplength))
3595 if (idx < d_cplength)
3598 while (d_cplength - idx >= chars_len)
3600 if (0 == compare(idx, chars_len, chars, chars_len))
3633 if (chars_len == npos)
3634 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
3637 return (idx < d_cplength) ? idx : d_cplength;
3639 if (chars_len <= d_cplength)
3641 if (idx > (d_cplength - chars_len))
3642 idx = d_cplength - chars_len;
3646 if (0 == compare(idx, chars_len, chars, chars_len))
3649 }
while (idx-- != 0);
3676 if (idx < d_cplength)
3678 const utf32* pt = &ptr()[idx];
3682 if (npos != str.
find(*pt++))
3685 }
while (++idx != d_cplength);
3708 if (idx < d_cplength)
3710 const utf32* pt = &ptr()[idx];
3714 if (npos == str.
find(*pt++))
3717 }
while (++idx != d_cplength);
3745 if (idx < d_cplength)
3747 const utf32* pt = &ptr()[idx];
3751 if (npos != find_codepoint(std_str, *pt++))
3754 }
while (++idx != d_cplength);
3781 if (idx < d_cplength)
3783 const utf32* pt = &ptr()[idx];
3787 if (npos == find_codepoint(std_str, *pt++))
3790 }
while (++idx != d_cplength);
3822 return find_first_of(utf8_str, idx, utf_length(utf8_str));
3849 return find_first_not_of(utf8_str, idx, utf_length(utf8_str));
3879 if (str_len == npos)
3880 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3882 if (idx < d_cplength)
3884 size_type encsze = encoded_size(utf8_str, str_len);
3886 const utf32* pt = &ptr()[idx];
3890 if (npos != find_codepoint(utf8_str, encsze, *pt++))
3893 }
while (++idx != d_cplength);
3927 if (str_len == npos)
3928 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
3930 if (idx < d_cplength)
3932 size_type encsze = encoded_size(utf8_str, str_len);
3934 const utf32* pt = &ptr()[idx];
3938 if (npos == find_codepoint(utf8_str, encsze, *pt++))
3941 }
while (++idx != d_cplength);
3965 return find(code_point, idx);
3986 if (idx < d_cplength)
3990 if ((*
this)[idx] != code_point)
3993 }
while(idx++ < d_cplength);
4019 return find_first_of(cstr, idx, strlen(cstr));
4041 return find_first_not_of(cstr, idx, strlen(cstr));
4066 if (chars_len == npos)
4067 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4069 if (idx < d_cplength)
4071 const utf32* pt = &ptr()[idx];
4075 if (npos != find_codepoint(chars, chars_len, *pt++))
4078 }
while (++idx != d_cplength);
4107 if (chars_len == npos)
4108 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4110 if (idx < d_cplength)
4112 const utf32* pt = &ptr()[idx];
4116 if (npos == find_codepoint(chars, chars_len, *pt++))
4119 }
while (++idx != d_cplength);
4148 if (idx >= d_cplength)
4149 idx = d_cplength - 1;
4151 const utf32* pt = &ptr()[idx];
4155 if (npos != str.
find(*pt--))
4158 }
while (idx-- != 0);
4183 if (idx >= d_cplength)
4184 idx = d_cplength - 1;
4186 const utf32* pt = &ptr()[idx];
4190 if (npos == str.
find(*pt--))
4193 }
while (idx-- != 0);
4223 if (idx >= d_cplength)
4224 idx = d_cplength - 1;
4226 const utf32* pt = &ptr()[idx];
4230 if (npos != find_codepoint(std_str, *pt--))
4233 }
while (idx-- != 0);
4262 if (idx >= d_cplength)
4263 idx = d_cplength - 1;
4265 const utf32* pt = &ptr()[idx];
4269 if (npos == find_codepoint(std_str, *pt--))
4272 }
while (idx-- != 0);
4304 return find_last_of(utf8_str, idx, utf_length(utf8_str));
4331 return find_last_not_of(utf8_str, idx, utf_length(utf8_str));
4361 if (str_len == npos)
4362 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
4366 if (idx >= d_cplength)
4367 idx = d_cplength - 1;
4369 size_type encsze = encoded_size(utf8_str, str_len);
4371 const utf32* pt = &ptr()[idx];
4375 if (npos != find_codepoint(utf8_str, encsze, *pt--))
4378 }
while (idx-- != 0);
4412 if (str_len == npos)
4413 CEGUI_THROW(std::length_error(
"Length for utf8 encoded string can not be 'npos'"));
4417 if (idx >= d_cplength)
4418 idx = d_cplength - 1;
4420 size_type encsze = encoded_size(utf8_str, str_len);
4422 const utf32* pt = &ptr()[idx];
4426 if (npos == find_codepoint(utf8_str, encsze, *pt--))
4429 }
while (idx-- != 0);
4453 return rfind(code_point, idx);
4474 if (idx >= d_cplength)
4475 idx = d_cplength - 1;
4479 if ((*
this)[idx] != code_point)
4482 }
while(idx-- != 0);
4508 return find_last_of(cstr, idx, strlen(cstr));
4530 return find_last_not_of(cstr, idx, strlen(cstr));
4555 if (chars_len == npos)
4556 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4560 if (idx >= d_cplength)
4561 idx = d_cplength - 1;
4563 const utf32* pt = &ptr()[idx];
4567 if (npos != find_codepoint(chars, chars_len, *pt--))
4570 }
while (idx-- != 0);
4599 if (chars_len == npos)
4600 CEGUI_THROW(std::length_error(
"Length for char array can not be 'npos'"));
4604 if (idx >= d_cplength)
4605 idx = d_cplength - 1;
4607 const utf32* pt = &ptr()[idx];
4611 if (npos == find_codepoint(chars, chars_len, *pt--))
4614 }
while (idx-- != 0);
4642 if (d_cplength < idx)
4643 CEGUI_THROW(std::out_of_range(
"Index is out of range for this CEGUI::String"));
4645 return String(*
this, idx, len);
4684 return iterator(&ptr()[d_cplength]);
4756 bool grow(size_type new_size);
4762 void setlen(size_type len)
4765 ptr()[len] = (utf32)(0);
4771 d_reserve = CEGUI_STR_QUICKBUFF_SIZE;
4773 d_encodedbufflen = 0;
4774 d_encodeddatlen = 0;
4780 bool inside(utf32* inptr)
4782 if (inptr < ptr() || ptr() + d_cplength <= inptr)
4789 size_type safe_iter_dif(
const const_iterator& iter1,
const const_iterator& iter2)
const
4791 return (iter1.d_ptr == 0) ? 0 : (iter1 - iter2);
4799 size_type encode(
const utf32* src, utf8* dest, size_type dest_len, size_type src_len = 0)
const
4804 src_len = utf_length(src);
4807 size_type destCapacity = dest_len;
4810 for (uint idx = 0; idx < src_len; ++idx)
4812 utf32 cp = src[idx];
4815 if (destCapacity < encoded_size(cp))
4825 else if (cp < 0x0800)
4827 *dest++ = (utf8)((cp >> 6) | 0xC0);
4828 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4831 else if (cp < 0x10000)
4833 *dest++ = (utf8)((cp >> 12) | 0xE0);
4834 *dest++ = (utf8)(((cp >> 6) & 0x3F) | 0x80);
4835 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4840 *dest++ = (utf8)((cp >> 18) | 0xF0);
4841 *dest++ = (utf8)(((cp >> 12) & 0x3F) | 0x80);
4842 *dest++ = (utf8)(((cp >> 6) & 0x3F) | 0x80);
4843 *dest++ = (utf8)((cp & 0x3F) | 0x80);
4849 return dest_len - destCapacity;
4852 size_type encode(
const utf8* src, utf32* dest, size_type dest_len, size_type src_len = 0)
const
4857 src_len = utf_length(src);
4860 size_type destCapacity = dest_len;
4863 for (uint idx = 0; ((idx < src_len) && (destCapacity > 0));)
4866 utf8 cu = src[idx++];
4874 cp = ((cu & 0x1F) << 6);
4875 cp |= (src[idx++] & 0x3F);
4879 cp = ((cu & 0x0F) << 12);
4880 cp |= ((src[idx++] & 0x3F) << 6);
4881 cp |= (src[idx++] & 0x3F);
4885 cp = ((cu & 0x07) << 18);
4886 cp |= ((src[idx++] & 0x3F) << 12);
4887 cp |= ((src[idx++] & 0x3F) << 6);
4888 cp |= (src[idx++] & 0x3F);
4895 return dest_len - destCapacity;
4899 size_type encoded_size(utf32 code_point)
const
4901 if (code_point < 0x80)
4903 else if (code_point < 0x0800)
4905 else if (code_point < 0x10000)
4912 size_type encoded_size(
const utf32* buf)
const
4914 return encoded_size(buf, utf_length(buf));
4918 size_type encoded_size(
const utf32* buf, size_type len)
const
4920 size_type count = 0;
4924 count += encoded_size(*buf++);
4931 size_type encoded_size(
const utf8* buf)
const
4933 return encoded_size(buf, utf_length(buf));
4937 size_type encoded_size(
const utf8* buf, size_type len)
const
4940 size_type count = 0;
4951 else if (tcp < 0xE0)
4956 else if (tcp < 0xF0)
4977 size_type utf_length(
const utf8* utf8_str)
const
4987 size_type utf_length(
const utf32* utf32_str)
const
4990 while (*utf32_str++)
4997 utf8* build_utf8_buff(
void)
const;
5000 int utf32_comp_utf32(
const utf32* buf1,
const utf32* buf2, size_type cp_count)
const
5005 while ((--cp_count) && (*buf1 == *buf2))
5008 return *buf1 - *buf2;
5012 int utf32_comp_char(
const utf32* buf1,
const char* buf2, size_type cp_count)
const
5017 while ((--cp_count) && (*buf1 == static_cast<utf32>(static_cast<unsigned char>(*buf2))))
5020 return *buf1 -
static_cast<utf32
>(
static_cast<unsigned char>(*buf2));
5024 int utf32_comp_utf8(
const utf32* buf1,
const utf8* buf2, size_type cp_count)
const
5042 cp = ((cu & 0x1F) << 6);
5043 cp |= (*buf2++ & 0x3F);
5047 cp = ((cu & 0x0F) << 12);
5048 cp |= ((*buf2++ & 0x3F) << 6);
5049 cp |= (*buf2++ & 0x3F);
5053 cp = ((cu & 0x07) << 18);
5054 cp |= ((*buf2++ & 0x3F) << 12);
5055 cp |= ((*buf2++ & 0x3F) << 6);
5056 cp |= (*buf2++ & 0x3F);
5059 }
while ((*buf1++ == cp) && (--cp_count));
5061 return (*--buf1) - cp;
5065 size_type find_codepoint(
const std::string& str, utf32 code_point)
const
5067 size_type idx = 0, sze = (size_type)str.size();
5071 if (code_point == static_cast<utf32>(static_cast<unsigned char>(str[idx])))
5081 size_type find_codepoint(
const utf8* str, size_type len, utf32 code_point)
const
5088 while (idx != len) {
5097 cp = ((cu & 0x1F) << 6);
5098 cp |= (*str++ & 0x3F);
5102 cp = ((cu & 0x0F) << 12);
5103 cp |= ((*str++ & 0x3F) << 6);
5104 cp |= (*str++ & 0x3F);
5108 cp = ((cu & 0x07) << 18);
5109 cp |= ((*str++ & 0x3F) << 12);
5110 cp |= ((*str++ & 0x3F) << 6);
5111 cp |= (*str++ & 0x3F);
5114 if (code_point == cp)
5125 size_type find_codepoint(
const char* chars, size_type chars_len, utf32 code_point)
const
5127 for (size_type idx = 0; idx != chars_len; ++idx)
5129 if (code_point == static_cast<utf32>(static_cast<unsigned char>(chars[idx])))
5146 bool CEGUIEXPORT
operator==(
const String& str1,
const String& str2);
5152 bool CEGUIEXPORT
operator==(
const String& str,
const std::string& std_str);
5158 bool CEGUIEXPORT
operator==(
const std::string& std_str,
const String& str);
5164 bool CEGUIEXPORT
operator==(
const String& str,
const utf8* utf8_str);
5170 bool CEGUIEXPORT
operator==(
const utf8* utf8_str,
const String& str);
5176 bool CEGUIEXPORT
operator!=(
const String& str1,
const String& str2);
5182 bool CEGUIEXPORT
operator!=(
const String& str,
const std::string& std_str);
5188 bool CEGUIEXPORT
operator!=(
const std::string& std_str,
const String& str);
5194 bool CEGUIEXPORT
operator!=(
const String& str,
const utf8* utf8_str);
5200 bool CEGUIEXPORT
operator!=(
const utf8* utf8_str,
const String& str);
5206 bool CEGUIEXPORT
operator<(
const String& str1,
const String& str2);
5212 bool CEGUIEXPORT
operator<(
const String& str,
const std::string& std_str);
5218 bool CEGUIEXPORT
operator<(
const std::string& std_str,
const String& str);
5224 bool CEGUIEXPORT
operator<(
const String& str,
const utf8* utf8_str);
5230 bool CEGUIEXPORT
operator<(
const utf8* utf8_str,
const String& str);
5236 bool CEGUIEXPORT
operator>(
const String& str1,
const String& str2);
5242 bool CEGUIEXPORT
operator>(
const String& str,
const std::string& std_str);
5248 bool CEGUIEXPORT
operator>(
const std::string& std_str,
const String& str);
5254 bool CEGUIEXPORT
operator>(
const String& str,
const utf8* utf8_str);
5260 bool CEGUIEXPORT
operator>(
const utf8* utf8_str,
const String& str);
5266 bool CEGUIEXPORT
operator<=(
const String& str1,
const String& str2);
5272 bool CEGUIEXPORT
operator<=(
const String& str,
const std::string& std_str);
5278 bool CEGUIEXPORT
operator<=(
const std::string& std_str,
const String& str);
5284 bool CEGUIEXPORT
operator<=(
const String& str,
const utf8* utf8_str);
5290 bool CEGUIEXPORT
operator<=(
const utf8* utf8_str,
const String& str);
5296 bool CEGUIEXPORT
operator>=(
const String& str1,
const String& str2);
5302 bool CEGUIEXPORT
operator>=(
const String& str,
const std::string& std_str);
5308 bool CEGUIEXPORT
operator>=(
const std::string& std_str,
const String& str);
5314 bool CEGUIEXPORT
operator>=(
const String& str,
const utf8* utf8_str);
5320 bool CEGUIEXPORT
operator>=(
const utf8* utf8_str,
const String& str);
5326 bool CEGUIEXPORT
operator==(
const String& str,
const char* c_str);
5332 bool CEGUIEXPORT
operator==(
const char* c_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);
5412 String CEGUIEXPORT
operator+(
const String& str1,
const String& str2);
5429 String CEGUIEXPORT
operator+(
const String& str,
const std::string& std_str);
5446 String CEGUIEXPORT
operator+(
const std::string& std_str,
const String& str);
5463 String CEGUIEXPORT
operator+(
const String& str,
const utf8* utf8_str);
5480 String CEGUIEXPORT
operator+(
const utf8* utf8_str,
const String& str);
5497 String CEGUIEXPORT
operator+(
const String& str, utf32 code_point);
5514 String CEGUIEXPORT
operator+(utf32 code_point,
const String& str);
5531 String CEGUIEXPORT
operator+(
const String& str,
const char* c_str);
5548 String CEGUIEXPORT
operator+(
const char* c_str,
const String& str);
5554 CEGUIEXPORT std::ostream& operator<<(std::ostream& s,
const String& str);
5573 void CEGUIEXPORT
swap(String& str1, String& str2);
5582 bool operator() (
const String& a,
const String& b)
const
5584 const size_t la = a.
length();
5585 const size_t lb = b.
length();
5587 return (memcmp(a.
ptr(), b.
ptr(), la *
sizeof(utf32)) < 0);
5598 #if CEGUI_STRING_CLASS == CEGUI_STRING_CLASS_STD
5600 typedef std::string
String;
5602 #else // CEGUI_STRING_CLASS_STD_AO
5604 typedef std::basic_string<char, std::char_traits<char>, STLAllocatorWrapper<char, AllocatorConfig<STLAllocator>::Allocator> >
String;
5615 bool operator() (
const String& a,
const String& b)
const
5617 const size_t la = a.
length();
5618 const size_t lb = b.
length();
5626 #if defined(_MSC_VER)
5627 # pragma warning(disable : 4251)
5635 #endif // end of guard _CEGUIString_h_