]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Merged from trunk
authorFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 18 Dec 2013 18:24:18 +0000 (19:24 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Wed, 18 Dec 2013 18:24:18 +0000 (19:24 +0100)
src/parser/CharacterSet.h [deleted file]
src/parser/Makefile.am
src/parser/Tokenizer.cc
src/parser/Tokenizer.h
src/parser/testTokenizer.cc

diff --git a/src/parser/CharacterSet.h b/src/parser/CharacterSet.h
deleted file mode 100644 (file)
index 2cfa1e7..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-#ifndef _SQUID_SRC_PARSER_CHARACTERSET_H
-#define _SQUID_SRC_PARSER_CHARACTERSET_H
-
-#include <vector>
-
-namespace Parser {
-
-class CharacterSet
-{
-public:
-    //XXX: use unsigned chars?
-    CharacterSet(const char *label, const char * const c) : name(label), chars_(std::vector<bool>(256,false)) {
-        size_t clen = strlen(c);
-        for (size_t i = 0; i < clen; ++i)
-            chars_[static_cast<uint8_t>(c[i])] = true;
-    }
-
-    /// whether a given character exists in the set
-    bool operator[](char c) const {return chars_[static_cast<uint8_t>(c)];}
-
-    /// add a given char to the character set
-    CharacterSet & add(const char c) {chars_[static_cast<uint8_t>(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<bool>::const_iterator s = src.chars_.begin();
-        const std::vector<bool>::const_iterator e = src.chars_.end();
-        std::vector<bool>::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<bool> chars_; //std::vector<bool> is optimized
-};
-
-} // namespace Parser
-
-#endif /* _SQUID_SRC_PARSER_CHARACTERSET_H */
index 82cc83f53406711d9cceb88bb1287f938e0b86a7..8a05b46a786ad88b789afbd5c4c54ffbda4eeeb1 100644 (file)
@@ -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)
index 709ad31af7aa197ed02a42f336492bfbef9ceca7..b76aa1ec67b036a7fbdd5814ea7170f7f5306059 100644 (file)
@@ -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);
index 9e73521d4ee98a04963b1b1afa5e8e139735dcb9..d40869875d2b708dd4904cee8867025eee20e301 100644 (file)
@@ -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
 };
index eac74150218580ff2e46058f7681f01c8fbb8095..7334d743e526fc83c239cd26006a8dd8db5ccc8a 100644 (file)
@@ -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