From: Francesco Chemolli Date: Wed, 18 Dec 2013 18:24:18 +0000 (+0100) Subject: Merged from trunk X-Git-Tag: merge-candidate-3-v1~506^2~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bc6322f9cb47748a253974dbce3448f683ca8680;p=thirdparty%2Fsquid.git Merged from trunk --- diff --git a/src/parser/CharacterSet.h b/src/parser/CharacterSet.h deleted file mode 100644 index 2cfa1e7ff3..0000000000 --- a/src/parser/CharacterSet.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef _SQUID_SRC_PARSER_CHARACTERSET_H -#define _SQUID_SRC_PARSER_CHARACTERSET_H - -#include - -namespace Parser { - -class CharacterSet -{ -public: - //XXX: use unsigned chars? - 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; - } - - /// whether a given character exists in the set - bool operator[](char c) const {return chars_[static_cast(c)];} - - /// add a given char to the character set - 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) { - //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(); - while (s != e) { - if (*s) - *d = true; - ++s; - ++d; - } - return *this; - } - - /// name of this character set - const char * name; - -private: - /// characters defined in this set - std::vector chars_; //std::vector is optimized -}; - -} // namespace Parser - -#endif /* _SQUID_SRC_PARSER_CHARACTERSET_H */ diff --git a/src/parser/Makefile.am b/src/parser/Makefile.am index 82cc83f534..8a05b46a78 100644 --- a/src/parser/Makefile.am +++ b/src/parser/Makefile.am @@ -10,11 +10,11 @@ TESTS += testTokenizer noinst_LTLIBRARIES = libsquid-parser.la libsquid_parser_la_SOURCES = \ - CharacterSet.h \ Tokenizer.h \ Tokenizer.cc SBUF_SOURCE= \ + $(top_srcdir)/base/CharacterSet.h \ $(top_srcdir)/src/SBuf.h \ $(top_srcdir)/src/SBuf.cc \ $(top_srcdir)/src/MemBlob.h \ @@ -43,6 +43,7 @@ testTokenizer_LDFLAGS = $(LIBADD_DL) testTokenizer_LDADD = \ libsquid-parser.la \ $(top_builddir)/lib/libmiscutil.la \ + $(top_builddir)/src/base/libbase.la \ $(SQUID_CPPUNIT_LIBS) \ $(SQUID_CPPUNIT_LA) \ $(COMPAT_LIB) diff --git a/src/parser/Tokenizer.cc b/src/parser/Tokenizer.cc index 709ad31af7..b76aa1ec67 100644 --- a/src/parser/Tokenizer.cc +++ b/src/parser/Tokenizer.cc @@ -3,40 +3,11 @@ namespace Parser { -SBuf::size_type -Tokenizer::findFirstNotIn(const CharacterSet& tokenChars, SBuf::size_type startAtPos) -{ - SBuf::size_type prefixLen = startAtPos; - const SBuf::size_type len = buf_.length(); - while (prefixLen < len) { - if (!tokenChars[buf_[prefixLen]]) - break; - ++prefixLen; - } - return prefixLen; -} - -SBuf::size_type -Tokenizer::findFirstIn(const CharacterSet& tokenChars, SBuf::size_type startAtPos) -{ - SBuf::size_type i = startAtPos; - const SBuf::size_type len = buf_.length(); - bool found = false; - while (i < len) { - if (tokenChars[buf_[i]]) { - found = true; - break; - } - ++i; - } - return found ? i : SBuf::npos ; -} - bool Tokenizer::token(SBuf &returnedToken, const CharacterSet &whitespace) { - const SBuf::size_type endOfPreWhiteSpace = findFirstNotIn(whitespace); - const SBuf::size_type endOfToken = findFirstIn(whitespace, endOfPreWhiteSpace); + const SBuf::size_type endOfPreWhiteSpace = buf_.findFirstNotOf(whitespace); + const SBuf::size_type endOfToken = buf_.findFirstOf(whitespace, endOfPreWhiteSpace); if (endOfToken == SBuf::npos) return false; buf_.consume(endOfPreWhiteSpace); @@ -48,7 +19,7 @@ Tokenizer::token(SBuf &returnedToken, const CharacterSet &whitespace) bool Tokenizer::prefix(SBuf &returnedToken, const CharacterSet &tokenChars) { - SBuf::size_type prefixLen = findFirstNotIn(tokenChars); + SBuf::size_type prefixLen = buf_.findFirstNotOf(tokenChars); if (prefixLen == 0) return false; returnedToken = buf_.consume(prefixLen); @@ -58,7 +29,7 @@ Tokenizer::prefix(SBuf &returnedToken, const CharacterSet &tokenChars) bool Tokenizer::skip(const CharacterSet &tokenChars) { - SBuf::size_type prefixLen = findFirstNotIn(tokenChars); + SBuf::size_type prefixLen = buf_.findFirstNotOf(tokenChars); if (prefixLen == 0) return false; buf_.consume(prefixLen); diff --git a/src/parser/Tokenizer.h b/src/parser/Tokenizer.h index 9e73521d4e..d40869875d 100644 --- a/src/parser/Tokenizer.h +++ b/src/parser/Tokenizer.h @@ -1,7 +1,7 @@ #ifndef SQUID_PARSER_TOKENIZER_H_ #define SQUID_PARSER_TOKENIZER_H_ -#include "CharacterSet.h" +#include "base/CharacterSet.h" #include "SBuf.h" namespace Parser { @@ -38,11 +38,6 @@ public: /// Skips a given character (a token). bool skip(const char tokenChar); -protected: - //obtain the length of the longest prefix in buf_ only made of chars in tokenChars - SBuf::size_type findFirstNotIn(const CharacterSet& tokenChars, SBuf::size_type startAtPos = 0); - SBuf::size_type findFirstIn(const CharacterSet& tokenChars, SBuf::size_type startAtPos = 0); - private: SBuf buf_; ///< yet unparsed input }; diff --git a/src/parser/testTokenizer.cc b/src/parser/testTokenizer.cc index eac7415021..7334d743e5 100644 --- a/src/parser/testTokenizer.cc +++ b/src/parser/testTokenizer.cc @@ -1,7 +1,7 @@ #include "squid.h" #include "testTokenizer.h" -#include "CharacterSet.h" +#include "base/CharacterSet.h" #include "Tokenizer.h" CPPUNIT_TEST_SUITE_REGISTRATION( testTokenizer ); @@ -10,11 +10,11 @@ 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","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); -const Parser::CharacterSet whitespace("whitespace"," \r\n"); -const Parser::CharacterSet crlf("crlf","\r\n"); -const Parser::CharacterSet tab("tab","\t"); -const Parser::CharacterSet numbers("numbers","0123456789"); +const CharacterSet alpha("alpha","abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); +const CharacterSet whitespace("whitespace"," \r\n"); +const CharacterSet crlf("crlf","\r\n"); +const CharacterSet tab("tab","\t"); +const CharacterSet numbers("numbers","0123456789"); void testTokenizer::testTokenizerPrefix() @@ -41,7 +41,7 @@ testTokenizer::testTokenizerPrefix() CPPUNIT_ASSERT_EQUAL(SBuf("http"),s); //output SBuf left untouched // match until the end of the sample - Parser::CharacterSet all(whitespace); + CharacterSet all(whitespace); all += alpha; all += crlf; all += numbers; @@ -98,7 +98,6 @@ testTokenizer::testTokenizerToken() //no separator found CPPUNIT_ASSERT(!t.token(s,tab)); - } void