|
a/src/utils/utf8iter.h |
|
b/src/utils/utf8iter.h |
1 |
#ifndef _UTF8ITER_H_INCLUDED_
|
1 |
#ifndef _UTF8ITER_H_INCLUDED_
|
2 |
#define _UTF8ITER_H_INCLUDED_
|
2 |
#define _UTF8ITER_H_INCLUDED_
|
3 |
/* @(#$Id: utf8iter.h,v 1.4 2005-12-07 15:41:50 dockes Exp $ (C) 2004 J.F.Dockes */
|
3 |
/* @(#$Id: utf8iter.h,v 1.5 2006-01-28 10:23:55 dockes Exp $ (C) 2004 J.F.Dockes */
|
4 |
|
4 |
|
5 |
/**
|
5 |
/**
|
6 |
* A small helper class to iterate over utf8 strings. This is not an
|
6 |
* A small helper class to iterate over utf8 strings. This is not an
|
7 |
* STL iterator and this is not well designed, just convenient for
|
7 |
* STL iterator and this is not well designed, just convenient for
|
8 |
some specific uses
|
8 |
some specific uses
|
|
... |
|
... |
42 |
if (bad)
|
42 |
if (bad)
|
43 |
return -1;
|
43 |
return -1;
|
44 |
cl = get_cl(pos);
|
44 |
cl = get_cl(pos);
|
45 |
if (!poslok(pos, cl)) {
|
45 |
if (!poslok(pos, cl)) {
|
46 |
bad = true;
|
46 |
bad = true;
|
|
|
47 |
pos = s.length();
|
47 |
cl = 0;
|
48 |
cl = 0;
|
48 |
return -1;
|
49 |
return -1;
|
49 |
}
|
50 |
}
|
50 |
return 0;
|
51 |
return 0;
|
51 |
}
|
52 |
}
|
|
... |
|
... |
89 |
if (!cl && compute_cl() < 0)
|
90 |
if (!cl && compute_cl() < 0)
|
90 |
return (unsigned int)-1;
|
91 |
return (unsigned int)-1;
|
91 |
unsigned int val = getvalueat(pos, cl);
|
92 |
unsigned int val = getvalueat(pos, cl);
|
92 |
if (val == (unsigned int)-1) {
|
93 |
if (val == (unsigned int)-1) {
|
93 |
bad = true;
|
94 |
bad = true;
|
|
|
95 |
pos = s.length();
|
94 |
cl = 0;
|
96 |
cl = 0;
|
95 |
}
|
97 |
}
|
96 |
return val;
|
98 |
return val;
|
97 |
}
|
99 |
}
|
98 |
/** "Direct" access. Awfully inefficient as we skip from start or current
|
100 |
/** "Direct" access. Awfully inefficient as we skip from start or current
|
|
... |
|
... |
140 |
return std::string("");
|
142 |
return std::string("");
|
141 |
}
|
143 |
}
|
142 |
return s.substr(pos, cl);
|
144 |
return s.substr(pos, cl);
|
143 |
}
|
145 |
}
|
144 |
bool eof() {
|
146 |
bool eof() {
|
|
|
147 |
// Note: we always ensure that pos == s.length() when setting bad to
|
|
|
148 |
// true
|
145 |
return bad || pos == s.length();
|
149 |
return pos == s.length();
|
146 |
}
|
150 |
}
|
147 |
bool error() {
|
151 |
bool error() {
|
148 |
return bad;
|
152 |
return bad;
|
149 |
}
|
153 |
}
|
150 |
string::size_type getBpos() const {
|
154 |
string::size_type getBpos() const {
|