]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed initialization problem in testCharacterSet
authorFrancesco Chemolli <kinkie@squid-cache.org>
Fri, 13 Dec 2013 07:16:18 +0000 (08:16 +0100)
committerFrancesco Chemolli <kinkie@squid-cache.org>
Fri, 13 Dec 2013 07:16:18 +0000 (08:16 +0100)
Removed debug code in testTokenizer
Completed testTokenizerPrefix

src/parser/CharacterSet.h
src/parser/Tokenizer.cc
src/parser/Tokenizer.h
src/parser/testTokenizer.cc

index 6b7f17ab70b8ce9602ce6f1ec2633a409c47dc2d..2cfa1e7ff329f68c204ea9e0f191d2a6186d429c 100644 (file)
@@ -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<bool>(256,false)) {
         size_t clen = strlen(c);
         for (size_t i = 0; i < clen; ++i)
             chars_[static_cast<uint8_t>(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<bool>::const_iterator s = src.chars_.begin();
         const std::vector<bool>::const_iterator e = src.chars_.end();
         std::vector<bool>::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;
     }
 
index a0ade50b2e0f4fa1be54a020991f4c16b0377730..e0805621db1514b59fd038e2fe2a1ad4549ec268 100644 (file)
@@ -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 */
index 955878b4144dd2ff56652e0992e148cf84a9fad3..3f01ed9a86483b101818077bd3ac02d9a978a3bd 100644 (file)
@@ -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);
 };
 
 
index e3e43abf92c4ad91f36eecdd3dd992b3e5ffecc1..2efd18311585c78d2964608d957df7bb18558643 100644 (file)
@@ -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 <iostream>
-std::ostream &dumpCharSet(std::ostream &os, const Parser::CharacterSet &cs) {
-    for (int i = 0; i < 256; ++i) {
-        if (cs[i])
-            os << static_cast<char>(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());
 }