From: Alex Rousskov Date: Thu, 7 Aug 2014 17:20:27 +0000 (-0600) Subject: Added CharacterSet::complement() to create "all except those in that set" sets X-Git-Tag: SQUID_3_5_0_1~117^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b5cb2dbfed944c2d82ba10858a1d41b30ca5d4ee;p=thirdparty%2Fsquid.git Added CharacterSet::complement() to create "all except those in that set" sets 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"). --- diff --git a/src/base/CharacterSet.cc b/src/base/CharacterSet.cc index 0955ebd4e2..72e69c1180 100644 --- a/src/base/CharacterSet.cc +++ b/src/base/CharacterSet.cc @@ -1,6 +1,9 @@ #include "squid.h" #include "CharacterSet.h" +#include +#include + 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()); + return result; +} + CharacterSet::CharacterSet(const char *label, const char * const c) : name(label == NULL ? "anonymous" : label), chars_(Storage(256,0)) diff --git a/src/base/CharacterSet.h b/src/base/CharacterSet.h index 8fd809af04..ab7b9ed196 100644 --- a/src/base/CharacterSet.h +++ b/src/base/CharacterSet.h @@ -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;