34SBuf text(
"GET http://resource.com/path HTTP/1.1\r\n"
35 "Host: resource.com\r\n"
36 "Cookie: laijkpk3422r j1noin \r\n"
47 const SBuf canary(
"This text should not be changed.");
61 CPPUNIT_ASSERT(!t.
prefix(s, all, 0));
63 CPPUNIT_ASSERT_EQUAL(canary, s);
65 CPPUNIT_ASSERT_EQUAL(before, t.
remaining());
69 CPPUNIT_ASSERT_EQUAL(
SBuf(
"GET"),s);
71 CPPUNIT_ASSERT_EQUAL(
SBuf(
" "),s);
75 CPPUNIT_ASSERT_EQUAL(
SBuf(
" "),s);
79 CPPUNIT_ASSERT_EQUAL(
SBuf(
"http"),s);
83 CPPUNIT_ASSERT_EQUAL(
SBuf(
"http"),s);
86 CPPUNIT_ASSERT(t.
prefix(s,all));
91 CPPUNIT_ASSERT(!t.
prefix(s, all));
93 CPPUNIT_ASSERT_EQUAL(canary, s);
105 CPPUNIT_ASSERT_EQUAL(
SBuf(
"GET"),s);
111 CPPUNIT_ASSERT_EQUAL(
SBuf(
"http"),s);
114 CPPUNIT_ASSERT(t.
skip(
SBuf(
"://")));
117 CPPUNIT_ASSERT_EQUAL(
SBuf(
"resource"),s);
121 CPPUNIT_ASSERT(!t.
skip(
SBuf(
"://")));
122 CPPUNIT_ASSERT(!t.
skip(
'a'));
125 CPPUNIT_ASSERT(t.
skip(
'.'));
138 CPPUNIT_ASSERT_EQUAL(
SBuf(
"GET"),s);
140 CPPUNIT_ASSERT_EQUAL(
SBuf(
"http://resource.com/path"),s);
142 CPPUNIT_ASSERT_EQUAL(
SBuf(
"HTTP/1.1"),s);
144 CPPUNIT_ASSERT_EQUAL(
SBuf(
"Host:"),s);
151 const SBuf canary(
"This text should not be changed.");
165 CPPUNIT_ASSERT(!t.
suffix(s, all, 0));
167 CPPUNIT_ASSERT_EQUAL(canary, s);
169 CPPUNIT_ASSERT_EQUAL(before, t.
remaining());
187 CPPUNIT_ASSERT_EQUAL(
SBuf(
"1"), s);
191 CPPUNIT_ASSERT_EQUAL(
SBuf(
"HTTP"), s);
193 CPPUNIT_ASSERT_EQUAL(
SBuf(
" "), s);
196 CPPUNIT_ASSERT(t.
suffix(s, all));
201 CPPUNIT_ASSERT(!t.
suffix(s, all));
202 CPPUNIT_ASSERT_EQUAL(canary, s);
215 const int64_t benchmark = 1234;
216 CPPUNIT_ASSERT(t.
int64(rv, 10));
217 CPPUNIT_ASSERT_EQUAL(benchmark,rv);
225 const int64_t benchmark = 1234;
226 CPPUNIT_ASSERT(t.
int64(rv));
227 CPPUNIT_ASSERT_EQUAL(benchmark,rv);
235 const int64_t benchmark = 01234;
236 CPPUNIT_ASSERT(t.
int64(rv));
237 CPPUNIT_ASSERT_EQUAL(benchmark,rv);
245 const int64_t benchmark = 0x12f4;
246 CPPUNIT_ASSERT(t.
int64(rv));
247 CPPUNIT_ASSERT_EQUAL(benchmark,rv);
255 CPPUNIT_ASSERT(!t.
int64(rv));
256 CPPUNIT_ASSERT_EQUAL(
SBuf(
" 1234"), t.
buf());
263 CPPUNIT_ASSERT(!t.
int64(rv));
264 CPPUNIT_ASSERT_EQUAL(
SBuf(
" 1234"), t.
buf());
271 const int64_t benchmark = 1234;
272 CPPUNIT_ASSERT(t.
int64(rv));
273 CPPUNIT_ASSERT_EQUAL(benchmark,rv);
274 CPPUNIT_ASSERT_EQUAL(
SBuf(
" foo"), t.
buf());
281 const int64_t benchmark = 1234;
282 CPPUNIT_ASSERT(t.
int64(rv));
283 CPPUNIT_ASSERT_EQUAL(benchmark,rv);
284 CPPUNIT_ASSERT_EQUAL(
SBuf(
"foo"), t.
buf());
291 const int64_t benchmark = 0x1234f;
292 CPPUNIT_ASSERT(t.
int64(rv));
293 CPPUNIT_ASSERT_EQUAL(benchmark,rv);
294 CPPUNIT_ASSERT_EQUAL(
SBuf(
"oo"), t.
buf());
301 CPPUNIT_ASSERT(!t.
int64(rv));
302 CPPUNIT_ASSERT_EQUAL(
SBuf(
"1029397752385698678762234"), t.
buf());
308 SBuf base(
"1029397752385698678762234");
309 const int64_t benchmark = 22;
311 CPPUNIT_ASSERT_EQUAL(
SBuf(
"22"),t.
buf());
312 CPPUNIT_ASSERT(t.
int64(rv));
313 CPPUNIT_ASSERT_EQUAL(benchmark,rv);
320 SBuf base(
"deadbeefrow");
321 const int64_t benchmark=0xdeadbeef;
323 CPPUNIT_ASSERT(t.
int64(rv,16));
324 CPPUNIT_ASSERT_EQUAL(benchmark,rv);
325 CPPUNIT_ASSERT_EQUAL(
SBuf(
"row"),t.
buf());
optimized set of C chars, with quick membership test and merge support
CharacterSet & add(const unsigned char c)
add a given character to the character set
bool prefix(SBuf &returnedToken, const CharacterSet &tokenChars, SBuf::size_type limit=SBuf::npos)
bool suffix(SBuf &returnedToken, const CharacterSet &tokenChars, SBuf::size_type limit=SBuf::npos)
bool skipOne(const CharacterSet &discardables)
bool token(SBuf &returnedToken, const CharacterSet &delimiters)
bool skipSuffix(const SBuf &tokenToSkip)
SBuf::size_type skipAll(const CharacterSet &discardables)
bool int64(int64_t &result, int base=0, bool allowSign=true, SBuf::size_type limit=SBuf::npos)
SBuf buf() const
yet unparsed data
const SBuf & remaining() const
the remaining unprocessed section of buffer
bool skipOneTrailing(const CharacterSet &discardables)
bool skip(const SBuf &tokenToSkip)
static const size_type npos
size_type length() const
Returns the number of bytes stored in SBuf.
size_type findLastOf(const CharacterSet &set, size_type endPos=npos) const
bool startsWith(const SBuf &S, const SBufCaseSensitive isCaseSensitive=caseSensitive) const
SBuf substr(size_type pos, size_type n=npos) const
MemBlob::size_type size_type
implements test program's main() function while enabling customization
int run(int argc, char *argv[])
CPPUNIT_TEST(testTokenizerPrefix)
CPPUNIT_TEST(testTokenizerSuffix)
void testTokenizerPrefix()
void testTokenizerToken()
CPPUNIT_TEST(testTokenizerToken)
CPPUNIT_TEST(testTokenizerSkip)
void testTokenizerInt64()
void testTokenizerSuffix()
CPPUNIT_TEST(testTokenizerInt64)
CPPUNIT_TEST_SUITE(TestTokenizer)
int main(int argc, char *argv[])
const CharacterSet tab("tab","\t")
SBuf text("GET http://resource.com/path HTTP/1.1\r\n" "Host: resource.com\r\n" "Cookie: laijkpk3422r j1noin \r\n" "\r\n")
CPPUNIT_TEST_SUITE_REGISTRATION(TestTokenizer)
const CharacterSet alpha("alpha","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
const CharacterSet crlf("crlf","\r\n")
const CharacterSet whitespace("whitespace"," \r\n")
const CharacterSet numbers("numbers","0123456789")