20 #include <strings/StringPiece.h> 47 LETTER_DIGIT_DASH_UNDERSCORE,
48 LETTER_DIGIT_DASH_DOT_SLASH,
49 LETTER_DIGIT_DASH_DOT_SLASH_UNDERSCORE,
51 LETTER_DIGIT_DOT_PLUS_MINUS,
52 LETTER_DIGIT_DOT_UNDERSCORE,
53 LETTER_DIGIT_UNDERSCORE,
54 LETTER_DIGIT_UNDERSCORE_COLON,
57 LOWERLETTER_DIGIT_UNDERSCORE,
68 if (cur_.empty() || !Matches(clz, cur_[0])) {
71 cur_.remove_prefix(1);
85 if (!cur_.Consume(s)) {
95 while (!cur_.empty() && Matches(clz, cur_[0])) {
96 cur_.remove_prefix(1);
102 Scanner& Many(CharClass clz) {
return One(clz).Any(clz); }
109 capture_start_ = cur_.data();
110 capture_end_ =
nullptr;
119 capture_end_ = cur_.data();
125 if (!cur_.empty()) error_ =
true;
130 Scanner& AnySpace() {
return Any(SPACE); }
133 Scanner& ScanUntil(
char end_ch) {
134 ScanUntilImpl(end_ch,
false);
141 Scanner& ScanEscapedUntil(
char end_ch) {
142 ScanUntilImpl(end_ch,
true);
151 char Peek(
char default_value =
'\0')
const {
152 return cur_.empty() ? default_value : cur_[0];
156 int empty()
const {
return cur_.empty(); }
165 void ScanUntilImpl(
char end_ch,
bool escaped);
172 static bool IsLetter(
char ch) {
173 return (ch >=
'a' && ch <=
'z') || (ch >=
'A' && ch <=
'Z');
176 static bool IsLowerLetter(
char ch) {
return ch >=
'a' && ch <=
'z'; }
178 static bool IsDigit(
char ch) {
return ch >=
'0' && ch <=
'9'; }
180 static bool IsSpace(
char ch) {
181 return (ch ==
' ' || ch ==
'\t' || ch ==
'\n' || ch ==
'\v' || ch ==
'\f' ||
186 static bool Matches(CharClass clz,
char ch) {
195 return IsLetter(ch) || IsDigit(ch);
196 case LETTER_DIGIT_DASH_UNDERSCORE:
197 return (IsLetter(ch) || IsDigit(ch) || ch ==
'-' || ch ==
'_');
198 case LETTER_DIGIT_DASH_DOT_SLASH:
199 return IsLetter(ch) || IsDigit(ch) || ch ==
'-' || ch ==
'.' ||
201 case LETTER_DIGIT_DASH_DOT_SLASH_UNDERSCORE:
202 return (IsLetter(ch) || IsDigit(ch) || ch ==
'-' || ch ==
'.' ||
203 ch ==
'/' || ch ==
'_');
204 case LETTER_DIGIT_DOT:
205 return IsLetter(ch) || IsDigit(ch) || ch ==
'.';
206 case LETTER_DIGIT_DOT_PLUS_MINUS:
207 return IsLetter(ch) || IsDigit(ch) || ch ==
'+' || ch ==
'-' ||
209 case LETTER_DIGIT_DOT_UNDERSCORE:
210 return IsLetter(ch) || IsDigit(ch) || ch ==
'.' || ch ==
'_';
211 case LETTER_DIGIT_UNDERSCORE:
212 return IsLetter(ch) || IsDigit(ch) || ch ==
'_';
213 case LETTER_DIGIT_UNDERSCORE_COLON:
214 return IsLetter(ch) || IsDigit(ch) || ch ==
'_' || ch ==
':';
216 return ch >=
'a' && ch <=
'z';
217 case LOWERLETTER_DIGIT:
218 return IsLowerLetter(ch) || IsDigit(ch);
219 case LOWERLETTER_DIGIT_UNDERSCORE:
220 return IsLowerLetter(ch) || IsDigit(ch) || ch ==
'_';
222 return IsDigit(ch) && ch !=
'0';
226 return ch >=
'A' && ch <=
'Z';
234 const char* capture_start_ =
nullptr;
235 const char* capture_end_ =
nullptr;
239 void operator=(
const Scanner&) =
delete;