From: Amos Jeffries Date: Tue, 10 Dec 2013 16:03:03 +0000 (-0800) Subject: Update CharacterSet.h X-Git-Tag: merge-candidate-3-v1~506^2~111 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=92a6eaa13b847920647508d2123d4cd65a6f0f11;p=thirdparty%2Fsquid.git Update CharacterSet.h --- diff --git a/src/parser/CharacterSet.h b/src/parser/CharacterSet.h index 0b0207ef7c..5a24d8ef3f 100644 --- a/src/parser/CharacterSet.h +++ b/src/parser/CharacterSet.h @@ -1,38 +1,40 @@ #ifndef _SQUID_SRC_PARSER_CHARACTERSET_H #define _SQUID_SRC_PARSER_CHARACTERSET_H -#include +#include 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(c)] = true; + chars_[static_cast(c[i])] = true; } } /// whether a given character exists in the set - bool operator[](char t) const {return match_[static_cast(c)];} + bool operator[](char c) const {return chars_[static_cast(c)];} - void add(const char c) {match_[static_cast(c)] = true;} + /// add a given char to the character set + void add(const char c) {chars_[static_cast(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(c)] = true; return *this; } + /// name of this character set + const char * name; + private: - char * name_; - std::map chars_; + /// characters defined in this set + std::vector chars_; }; } // namespace Parser