#include <ucstring.h>
Public Member Functions | |
| const ucchar * | c_str () const |
| void | fromUtf8 (const std::string &stringUtf8) |
| Convert the utf8 string into this ucstring (16 bits char). | |
| ucstring & | operator+= (const ucstringbase &str) |
| ucstring & | operator+= (const std::string &str) |
| ucstring & | operator+= (const char *str) |
| ucstring & | operator+= (ucchar c) |
| ucstring & | operator= (const ucstringbase &str) |
| ucstring & | operator= (const std::string &str) |
| ucstring & | operator= (const char *str) |
| ucstring & | operator= (ucchar c) |
| std::string | toString () const |
| Converts the controlled ucstring and returns the resulting string. | |
| void | toString (std::string &str) const |
| Converts the controlled ucstring to a string str. | |
| std::string | toUtf8 () const |
| Convert this ucstring (16bits char) into a utf8 string. | |
| ucstring (const std::string &str) | |
| ucstring (const ucstringbase &str) | |
| ucstring () | |
| ~ucstring () | |
|
|
Definition at line 46 of file ucstring.h.
00046 {}
|
|
|
Definition at line 48 of file ucstring.h. References ucstringbase.
00048 : ucstringbase (str) {} |
|
|
Definition at line 50 of file ucstring.h. References ucstringbase.
00050 : ucstringbase () 00051 { 00052 *this=str; 00053 } |
|
|
Definition at line 55 of file ucstring.h.
00055 {}
|
|
|
Definition at line 125 of file ucstring.h. Referenced by NLMISC::CI18N::readTextFile().
|
|
|
Convert the utf8 string into this ucstring (16 bits char).
Definition at line 191 of file ucstring.h. References nlwarning, sint, ucchar, and uint8. Referenced by NLMISC::CI18N::readTextBuffer().
00192 {
00193 // clear the string
00194 erase();
00195
00196 uint8 c;
00197 ucchar code;
00198 sint iterations = 0;
00199
00200 std::string::const_iterator first(stringUtf8.begin()), last(stringUtf8.end());
00201 for (; first != last; )
00202 {
00203 c = *first++;
00204 code = c;
00205
00206 if ((code & 0xFE) == 0xFC)
00207 {
00208 code &= 0x01;
00209 iterations = 5;
00210 }
00211 else if ((code & 0xFC) == 0xF8)
00212 {
00213 code &= 0x03;
00214 iterations = 4;
00215 }
00216 else if ((code & 0xF8) == 0xF0)
00217 {
00218 code &= 0x07;
00219 iterations = 3;
00220 }
00221 else if ((code & 0xF0) == 0xE0)
00222 {
00223 code &= 0x0F;
00224 iterations = 2;
00225 }
00226 else if ((code & 0xE0) == 0xC0)
00227 {
00228 code &= 0x1F;
00229 iterations = 1;
00230 }
00231 else if ((code & 0x80) == 0x80)
00232 {
00233 nlwarning ("UCS: Invalid UTF-8 character");
00234 }
00235 else
00236 {
00237 push_back(code);
00238 iterations = 0;
00239 }
00240
00241 if (iterations)
00242 {
00243 for (sint i = 0; i < iterations; i++)
00244 {
00245 if (first == last)
00246 {
00247 nlwarning ("UCS: Invalid UTF-8 character");
00248 return;
00249 }
00250
00251 uint8 ch;
00252 ch = *first ++;
00253
00254 if ((ch & 0xC0) != 0x80)
00255 {
00256 nlwarning ("UCS: Invalid UTF-8 character");
00257 code = '?';
00258 break;
00259 }
00260
00261 code <<= 6;
00262 code |= (ucchar)(ch & 0x3F);
00263 }
00264 push_back(code);
00265 }
00266 }
00267 }
|
|
|
Definition at line 119 of file ucstring.h.
00120 {
00121 ucstringbase::operator +=(str);
00122 return *this;
00123 }
|
|
|
Definition at line 108 of file ucstring.h.
|
|
|
Definition at line 97 of file ucstring.h.
|
|
|
Definition at line 90 of file ucstring.h.
|
|
|
Definition at line 84 of file ucstring.h.
00085 {
00086 ucstringbase::operator =(str);
00087 return *this;
00088 }
|
|
|
Definition at line 74 of file ucstring.h. References sint.
|
|
|
Definition at line 64 of file ucstring.h. References sint.
|
|
|
Definition at line 57 of file ucstring.h. References ucchar.
00058 {
00059 resize (1);
00060 operator[](0) = c;
00061 return *this;
00062 }
|
|
|
Converts the controlled ucstring and returns the resulting string.
Definition at line 143 of file ucstring.h.
00144 {
00145 std::string str;
00146 toString(str);
00147 return str;
00148 }
|
|
|
|
Convert this ucstring (16bits char) into a utf8 string.
Definition at line 151 of file ucstring.h. References res, ucchar, and uint. Referenced by NLMISC::CI18N::encodeUTF8().
00152 {
00153 std::string res;
00154 ucstring::const_iterator first(begin()), last(end());
00155 for (; first != last; ++first)
00156 {
00157 //ucchar c = *first;
00158 uint nbLoop = 0;
00159 if (*first < 0x80)
00160 res += char(*first);
00161 else if (*first < 0x800)
00162 {
00163 ucchar c = *first;
00164 c = c >> 6;
00165 c = c & 0x1F;
00166 res += c | 0xC0;
00167 nbLoop = 1;
00168 }
00169 else /*if (*first < 0x10000)*/
00170 {
00171 ucchar c = *first;
00172 c = c >> 12;
00173 c = c & 0x0F;
00174 res += c | 0xE0;
00175 nbLoop = 2;
00176 }
00177
00178 for (uint i=0; i<nbLoop; ++i)
00179 {
00180 ucchar c = *first;
00181 c = c >> ((nbLoop - i - 1) * 6);
00182 c = c & 0x3F;
00183 res += char(c) | 0x80;
00184 }
00185 }
00186 return res;
00187 }
|
1.3.6