From: Francesco Chemolli Date: Fri, 13 Dec 2013 07:16:18 +0000 (+0100) Subject: Fixed initialization problem in testCharacterSet X-Git-Tag: merge-candidate-3-v1~506^2~101 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=bba8cb0cea77672044e2394277b35eaeef462f32;p=thirdparty%2Fsquid.git Fixed initialization problem in testCharacterSet Removed debug code in testTokenizer Completed testTokenizerPrefix --- diff --git a/src/parser/CharacterSet.h b/src/parser/CharacterSet.h index 6b7f17ab70..2cfa1e7ff3 100644 --- a/src/parser/CharacterSet.h +++ b/src/parser/CharacterSet.h @@ -9,8 +9,7 @@ class CharacterSet { public: //XXX: use unsigned chars? - CharacterSet(const char *label, const char * const c) : name(label) { - chars_.reserve(256); + CharacterSet(const char *label, const char * const c) : name(label), chars_(std::vector(256,false)) { size_t clen = strlen(c); for (size_t i = 0; i < clen; ++i) chars_[static_cast(c[i])] = true; @@ -24,10 +23,7 @@ public: /// add all characters from the given CharacterSet to this one const CharacterSet &operator +=(const CharacterSet &src) { -#if 1 - if (src.chars_.size() > chars_.size()) - chars_.reserve(src.chars_.size()); - //notworking + //precondition: src.chars_.size() == chars_.size() std::vector::const_iterator s = src.chars_.begin(); const std::vector::const_iterator e = src.chars_.end(); std::vector::iterator d = chars_.begin(); @@ -37,12 +33,6 @@ public: ++s; ++d; } -#else - for (int i = 0; i < 256; ++i) { - if (src[i]) - add(i); - } -#endif return *this; } diff --git a/src/parser/Tokenizer.cc b/src/parser/Tokenizer.cc index a0ade50b2e..e0805621db 100644 --- a/src/parser/Tokenizer.cc +++ b/src/parser/Tokenizer.cc @@ -46,22 +46,4 @@ Tokenizer::skip(const char tokenChar) //TODO return false; } - -SBuf::size_type -Tokenizer::find_first_in (const CharacterSet &set) -{ - SBuf::size_type rv; - const SBuf::size_type len=buf_.length(); - for (rv = 0; rv < len; ++rv) - if (set[buf_[rv]]) - return rv; - return SBuf::npos; -} - -SBuf::size_type -Tokenizer::find_first_not_in (const CharacterSet &set) -{ - return 0; -} - } /* namespace Parser */ diff --git a/src/parser/Tokenizer.h b/src/parser/Tokenizer.h index 955878b414..3f01ed9a86 100644 --- a/src/parser/Tokenizer.h +++ b/src/parser/Tokenizer.h @@ -40,10 +40,6 @@ public: private: SBuf buf_; ///< yet unparsed input - - /// find the position of the first character in the set. Return npos if not found - SBuf::size_type find_first_in (const CharacterSet &set); - SBuf::size_type find_first_not_in (const CharacterSet &set); }; diff --git a/src/parser/testTokenizer.cc b/src/parser/testTokenizer.cc index e3e43abf92..2efd183115 100644 --- a/src/parser/testTokenizer.cc +++ b/src/parser/testTokenizer.cc @@ -14,18 +14,8 @@ const Parser::CharacterSet alpha("alpha","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKL const Parser::CharacterSet whitespace("whitespace"," "); const Parser::CharacterSet crlf("crlf","\r\n"); const Parser::CharacterSet tab("tab","\t"); +const Parser::CharacterSet numbers("numbers","0123456789"); -#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() { @@ -51,16 +41,11 @@ testTokenizer::testTokenizerPrefix() CPPUNIT_ASSERT_EQUAL(SBuf("http"),s); //output SBuf left untouched // match until the end of the sample - dumpCharSet(std::cout,alpha); - dumpCharSet(std::cout,whitespace); - Parser::CharacterSet all("all"," "); - dumpCharSet(std::cout,all); + Parser::CharacterSet all(whitespace); all += alpha; - dumpCharSet(std::cout,all); all += crlf; - dumpCharSet(std::cout,all); + all += numbers; all.add(':').add('.').add('/'); - dumpCharSet(std::cout,all); CPPUNIT_ASSERT(t.prefix(s,all)); CPPUNIT_ASSERT_EQUAL(SBuf(),t.remaining()); }