From: Francesco Chemolli Date: Fri, 13 Dec 2013 05:47:07 +0000 (+0100) Subject: Broken: try and figure out CharacterSet::operator +=; more Tokenizer::prefix unit... X-Git-Tag: merge-candidate-3-v1~506^2~102 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c0c9c30093ea32d49a1dff7989bbd0e9536ab9fe;p=thirdparty%2Fsquid.git Broken: try and figure out CharacterSet::operator +=; more Tokenizer::prefix unit tests --- diff --git a/src/parser/CharacterSet.h b/src/parser/CharacterSet.h index ef99075da1..6b7f17ab70 100644 --- a/src/parser/CharacterSet.h +++ b/src/parser/CharacterSet.h @@ -3,7 +3,6 @@ #include -//#include namespace Parser { class CharacterSet @@ -21,15 +20,29 @@ public: bool operator[](char c) const {return chars_[static_cast(c)];} /// add a given char to the character set - void add(const char c) {chars_[static_cast(c)] = true;} + CharacterSet & add(const char c) {chars_[static_cast(c)] = true; return *this; } /// add all characters from the given CharacterSet to this one const CharacterSet &operator +=(const CharacterSet &src) { - // TODO: iterate src.chars_ vector instead of walking the entire 8-bit space - for (size_t i = 0; i < 256; ++i) { - if (src.chars_[static_cast(i)]) - chars_[static_cast(i)] = true; +#if 1 + if (src.chars_.size() > chars_.size()) + chars_.reserve(src.chars_.size()); + //notworking + std::vector::const_iterator s = src.chars_.begin(); + const std::vector::const_iterator e = src.chars_.end(); + std::vector::iterator d = chars_.begin(); + while (s != e) { + if (*s) + *d = true; + ++s; + ++d; } +#else + for (int i = 0; i < 256; ++i) { + if (src[i]) + add(i); + } +#endif return *this; } diff --git a/src/parser/testTokenizer.cc b/src/parser/testTokenizer.cc index 011dcec620..e3e43abf92 100644 --- a/src/parser/testTokenizer.cc +++ b/src/parser/testTokenizer.cc @@ -10,11 +10,22 @@ SBuf text("GET http://resource.com/path HTTP/1.1\r\n" "Host: resource.com\r\n" "Cookie: laijkpk3422r j1noin \r\n" "\r\n"); -const Parser::CharacterSet alpha("alpha","abcdefghijklmnopqrstuvwxzABCDEFGHIJKLMNOPQRSTUVWXYZ"); +const Parser::CharacterSet alpha("alpha","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); const Parser::CharacterSet whitespace("whitespace"," "); const Parser::CharacterSet crlf("crlf","\r\n"); const Parser::CharacterSet tab("tab","\t"); +#include +std::ostream &dumpCharSet(std::ostream &os, const Parser::CharacterSet &cs) { + for (int i = 0; i < 256; ++i) { + if (cs[i]) + os << static_cast(i); + else + os << '.'; + } + os << std::endl; + return os; +} void testTokenizer::testTokenizerPrefix() { @@ -40,11 +51,18 @@ testTokenizer::testTokenizerPrefix() CPPUNIT_ASSERT_EQUAL(SBuf("http"),s); //output SBuf left untouched // match until the end of the sample - Parser::CharacterSet all(alpha); - // TODO: finish from here. But += is buggy -// all += whitespace; -// all += crlf; - + dumpCharSet(std::cout,alpha); + dumpCharSet(std::cout,whitespace); + Parser::CharacterSet all("all"," "); + dumpCharSet(std::cout,all); + all += alpha; + dumpCharSet(std::cout,all); + all += crlf; + dumpCharSet(std::cout,all); + all.add(':').add('.').add('/'); + dumpCharSet(std::cout,all); + CPPUNIT_ASSERT(t.prefix(s,all)); + CPPUNIT_ASSERT_EQUAL(SBuf(),t.remaining()); } void