]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/parser/Tokenizer.h
1 #ifndef SQUID_PARSER_TOKENIZER_H_
2 #define SQUID_PARSER_TOKENIZER_H_
4 #include "CharacterSet.h"
11 explicit Tokenizer(const SBuf
&inBuf
) : buf_(inBuf
) {}
13 bool atEnd() const { return !buf_
.length(); }
14 const SBuf
& remaining() const { return buf_
; }
15 void reset(const SBuf
&newBuf
) { buf_
= newBuf
; }
17 /* The following methods start from the beginning of the input buffer.
18 * They return true and consume parsed chars if a non-empty token is found.
19 * Otherwise, they return false without any side-effects. */
22 * Skips all leading delimiters (if any),
23 * accumulates all characters up to the first delimiter (a token), and
24 * skips all trailing delimiters (if any).
25 * Want to extract delimiters? Use three prefix() calls instead.
27 bool token(SBuf
&returnedToken
, const CharacterSet
&whitespace
);
29 /// Accumulates all sequential permitted characters (a token).
30 bool prefix(SBuf
&returnedToken
, const CharacterSet
&tokenChars
);
32 /// Skips all sequential permitted characters (a token).
33 bool skip(const CharacterSet
&tokenChars
);
35 /// Skips a given token.
36 bool skip(const SBuf
&tokenToSkip
);
38 /// Skips a given character (a token).
39 bool skip(const char tokenChar
);
42 //obtain the length of the longest prefix in buf_ only made of chars in tokenChars
43 SBuf::size_type
findFirstNotIn(const CharacterSet
& tokenChars
, SBuf::size_type startAtPos
= 0);
44 SBuf::size_type
findFirstIn(const CharacterSet
& tokenChars
, SBuf::size_type startAtPos
= 0);
47 SBuf buf_
; ///< yet unparsed input
51 } /* namespace Parser */
52 #endif /* SQUID_PARSER_TOKENIZER_H_ */