27 int Ustring::getchar(std::istream *ifs) {
55 if (0 == (i & 0x80)) {
57 }
else if (0xC0 == (i & 0xE0)) {
62 if (0x80 != (i & 0xC0)) {
68 }
else if (0xE0 == (i & 0xF0)) {
73 if (0x80 != (i & 0xC0)) {
81 if (0x80 != (i & 0xC0)) {
87 }
else if (0xF0 == (i & 0xF8)) {
92 if (0x80 != (i & 0xC0)) {
100 if (0x80 != (i & 0xC0)) {
108 if (0x80 != (i & 0xC0)) {
128 std::cerr <<
"Ustring::Ustring(std::istream): "
129 "Stream is not valid utf8" << std::endl;
131 }
catch (
const Eof &e) {
140 for (std::vector<Uchar>::const_iterator it = orig.s.begin();
141 it != orig.s.end(); ++it) {
176 const bool Ustring::operator==(
const char *right)
const {
178 for (i = 0; right[i]; ++i) {
182 if (s[i] != right[i]) {
192 Ustring* Ustring::operator+=(
const Uchar &right) {
193 if (right < 0x1FFFFFu) {
201 Ustring* Ustring::operator+=(
const char *right) {
202 for (
const char *pos = right; *pos; ++pos) {
203 if (*pos >= 0 && *pos <= 127) {
204 s.push_back((Uchar) * pos);
212 std::string* Ustring::operator>>(std::string &str) {
213 for (
int i = 0; i < s.size(); ++i) {
220 }
else if (u < 0x800) {
221 c[1] = 0x80 | (u & 0x3F);
223 c[0] = 0xC0 | (u & 0x1F);
226 }
else if (u < 0x10000) {
227 c[2] = 0x80 | (u & 0x3F);
229 c[1] = 0x80 | (u & 0x3F);
231 c[0] = 0xE0 | (u & 0x0F);
234 }
else if (u < 0x200000) {
235 c[3] = 0x80 | (u & 0x3F);
237 c[2] = 0x80 | (u & 0x3F);
239 c[1] = 0x80 | (u & 0x3F);
241 c[0] = 0xF0 | (u & 0x07);
251 const bool Ustring::operator<(
const Ustring &right)
const {
257 }
catch (
const Invalid &e) {
279 if (pos < 0 || pos >= s.size()) {