]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Update CharacterSet.h
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 10 Dec 2013 16:03:03 +0000 (08:03 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 10 Dec 2013 16:03:03 +0000 (08:03 -0800)
src/parser/CharacterSet.h

index 0b0207ef7cd68d672e07e059bfa55ea063c3a940..5a24d8ef3f986074454e6896b603a83895e3fce9 100644 (file)
@@ -1,38 +1,40 @@
 #ifndef _SQUID_SRC_PARSER_CHARACTERSET_H
 #define _SQUID_SRC_PARSER_CHARACTERSET_H
 
-#include <map>
+#include <vector>
 
 namespace Parser {
 
 class CharacterSet
 {
 public:
-    CharacterSet(const char *label, const char * const c) : name_(label) {
-        memset(match_, 0, sizeof(match_));
+    CharacterSet(const char *label, const char * const c) : name(label) {
         const size_t = strlen(c);
         for (size_t i = 0; i < len; ++i) {
-            match_[static_cast<uint8_t>(c)] = true;
+            chars_[static_cast<uint8_t>(c[i])] = true;
         }
     }
 
     /// whether a given character exists in the set
-    bool operator[](char t) const {return match_[static_cast<uint8_t>(c)];}
+    bool operator[](char c) const {return chars_[static_cast<uint8_t>(c)];}
 
-    void add(const char c) {match_[static_cast<uint8_t>(c)] = true;}
+    /// add a given char to the character set
+    void add(const char c) {chars_[static_cast<uint8_t>(c)] = true;}
 
     /// add all characters from the given CharacterSet to this one
     const CharacterSet &operator +=(const CharacterSet &src) {
-        for (size_t i = 0; i < 256; ++i) {
-            if(src.match_[i])
-                match_[i] = true;
-        }
+        // TODO: iterate src.chars_ vector instead of walking the entire 8-bit space
+        for (size_t i = 0; i < 256; ++i)
+            chars_[static_cast<uint8_t>(c)] = true;
         return *this;
     }
 
+    /// name of this character set
+    const char * name;
+
 private:
-  char * name_;
-  std::map<bool> chars_;
+    /// characters defined in this set
+    std::vector<bool> chars_;
 };
 
 } // namespace Parser