]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added CharacterSet::complement() to create "all except those in that set" sets
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 7 Aug 2014 17:20:27 +0000 (11:20 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Thu, 7 Aug 2014 17:20:27 +0000 (11:20 -0600)
handy for parsing (e.g., "get all characters until the end of line").

Added CharacterSet::rename() to label sets. Handy in const declarations that
use expressions. For example: const CharacterSet AB = (A+B).renamed("AB").

src/base/CharacterSet.cc
src/base/CharacterSet.h

index 0955ebd4e283581216222b3910e6b005e5fa45e7..72e69c11801704712c288870362bf8542e5ffe24 100644 (file)
@@ -1,6 +1,9 @@
 #include "squid.h"
 #include "CharacterSet.h"
 
+#include <algorithm>
+#include <functional>
+
 CharacterSet &
 CharacterSet::operator +=(const CharacterSet &src)
 {
@@ -44,6 +47,16 @@ CharacterSet::addRange(unsigned char low, unsigned char high)
     return *this;
 }
 
+CharacterSet
+CharacterSet::complement(const char *label) const
+{
+    CharacterSet result((label ? label : "complement_of_some_other_set"), "");
+    // negate each of our elements and add them to the result storage
+    std::transform(chars_.begin(), chars_.end(), result.chars_.begin(),
+                   std::logical_not<Storage::value_type>());
+    return result;
+}
+
 CharacterSet::CharacterSet(const char *label, const char * const c) :
         name(label == NULL ? "anonymous" : label),
         chars_(Storage(256,0))
index 8fd809af04fcbfc5a694d19355d8a17fb9fb460a..ab7b9ed1961e21adc61ea964731c55b90ae0a131 100644 (file)
@@ -33,6 +33,12 @@ public:
     /// return a new CharacterSet containing the union of two sets
     CharacterSet operator +(const CharacterSet &src) const;
 
+    /// return a new CharacterSet containing characters not in this set
+    CharacterSet complement(const char *complementLabel = NULL) const;
+
+    /// change name; handy in const declarations that use operators
+    CharacterSet &rename(const char *label) { name = label; return *this; }
+
     /// optional set label for debugging (default: "anonymous")
     const char * name;