#include "squid.h"
-
#include "CharacterSet.h"
-#include <algorithm>
-
-static bool
-isNonZero(uint8_t i) {
- return i!=0;
-}
-
const CharacterSet &
CharacterSet::operator +=(const CharacterSet &src)
{
- std::copy_if(src.chars_.begin(),src.chars_.end(),chars_.begin(),isNonZero);
+ Storage::const_iterator s = src.chars_.begin();
+ const Storage::const_iterator e = src.chars_.end();
+ Storage::iterator d = chars_.begin();
+ while (s != e) {
+ if (*s)
+ *d = 1;
+ ++s;
+ ++d;
+ }
return *this;
}
}
CharacterSet::CharacterSet(const char *label, const char * const c)
-: name(label == NULL ? "anonymous" : label), chars_(vector_type(256,0))
+: name(label == NULL ? "anonymous" : label), chars_(Storage(256,0))
{
const size_t clen = strlen(c);
for (size_t i = 0; i < clen; ++i)
#include <vector>
-/// Optimized set of C chars, with quick membership test and merge support
+/// optimized set of C chars, with quick membership test and merge support
class CharacterSet
{
public:
- typedef std::vector<uint8_t> vector_type;
+ typedef std::vector<uint8_t> Storage;
- /// define a character set with the given label ("anonymous" if NULL,
+ /// define a character set with the given label ("anonymous" if NULL)
/// with specified initial contents
CharacterSet(const char *label, const char * const initial);
/// whether a given character exists in the set
- bool operator[](unsigned char c) const {return chars_[static_cast<uint8_t>(c)] == 1;}
+ bool operator[](unsigned char c) const {return chars_[static_cast<uint8_t>(c)] != 0;}
- /// add a given character to the character set.
+ /// add a given character to the character set
CharacterSet & add(const unsigned char c);
/// add all characters from the given CharacterSet to this one
const char * name;
private:
- /** characters present in this set.
+ /** index of characters in this set
*
* \note guaranteed to be always 256 slots big, as forced in the
* constructor. This assumption is relied upon in operator[], add,
* operator+=
*/
- vector_type chars_;
+ Storage chars_;
};
#endif /* _SQUID_SRC_PARSER_CHARACTERSET_H */