}
CharacterSet &
-CharacterSet::addRange(const RangeSpec & v)
+CharacterSet::addRange(unsigned char low, unsigned char high)
{
- for (RangeSpec::const_iterator i = v.begin(); i != v.end(); ++i) {
- assert(i->first <= i->second);
- unsigned char c = i->first;
- unsigned char high = i->second;
- while (c <= high) {
- chars_[static_cast<uint8_t>(c)] = 1;
- ++c;
- }
+ while (low <= high) {
+ chars_[static_cast<uint8_t>(low)] = 1;
+ ++low;
}
return *this;
}
add(c[i]);
}
-CharacterSet::CharacterSet(const char *label, const RangeSpec & ranges)
+CharacterSet::CharacterSet(const char *label, unsigned char low, unsigned char high)
: name(label == NULL ? "anonymous" : label), chars_(Storage(256,0))
{
- addRange(ranges);
+ addRange(low,high);
}
const CharacterSet
-CharacterSet::ALPHA("ALPHA", {{ 'a', 'z' }, { 'A', 'Z'}}),
+CharacterSet::ALPHA("ALPHA", "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),
CharacterSet::BIT("BIT","01"),
-CharacterSet::CHAR("CHAR",{{ 1, 127}}),
CharacterSet::CR("CR","\r"),
+CharacterSet::LF("LF","\n"),
CharacterSet::CRLF("CRLF","\r\n"),
CharacterSet::DIGIT("DIGIT","0123456789"),
CharacterSet::DQUOTE("DQUOTE","\""),
CharacterSet::HTAB("HTAB","\t"),
CharacterSet::HEXDIG("HEXDIG","0123456789aAbBcCdDeEfF"),
CharacterSet::SP("SP"," "),
-CharacterSet::VCHAR("VCHAR",{{ 0x21, 0x7e }} ),
+CharacterSet::VCHAR("VCHAR", 0x21, 0x7e),
CharacterSet::WSP("WSP"," \t"),
CharacterSet::TCHAR("TCHAR","!#$%&'*+-.^_`|~0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"),
CharacterSet::SPECIAL("SPECIAL","()<>@,;:\\\"/[]?={}")
//,CharacterSet::QDTEXT("QDTEXT",{{9,9},{0x20,0x21},{0x23,0x5b},{0x5d,0x7e},{0x80,0xff}})
-//,CharacterSet::OBSTEXT("OBSTEXT",{{0x80,0xff}})
+//,CharacterSet::OBSTEXT("OBSTEXT",0x80,0xff)
;
{
public:
typedef std::vector<uint8_t> Storage;
- typedef std::vector<std::pair<unsigned char, unsigned char> > RangeSpec;
/// define a character set with the given label ("anonymous" if NULL)
/// with specified initial contents
/// define a character set with the given label ("anonymous" if NULL)
/// containing characters defined in the supplied ranges
/// \see addRange
- CharacterSet(const char *label, const RangeSpec &);
+ CharacterSet(const char *label, unsigned char low, unsigned char high);
/// whether a given character exists in the set
bool operator[](unsigned char c) const {return chars_[static_cast<uint8_t>(c)] != 0;}
/// add a given character to the character set
CharacterSet & add(const unsigned char c);
- /** add a list of character ranges, expressed as pairs [low,high]
- *
- * Both ends of the specified ranges are included in the added set
- * e.g. addRange(RangeSpec( { { '0','9'}, { 'a', 'z' } ) )
- */
- CharacterSet & addRange(const RangeSpec &);
+ /// add a list of character ranges, expressed as pairs [low,high], including both ends
+ CharacterSet & addRange(unsigned char low, unsigned char high);
/// add all characters from the given CharacterSet to this one
CharacterSet &operator +=(const CharacterSet &src);
static const CharacterSet ALPHA;
// 0-1
static const CharacterSet BIT;
- // any 7-bit US-ASCII character, except for NUL
- static const CharacterSet CHAR;
// carriage return
static const CharacterSet CR;
+ // line feed
+ static const CharacterSet LF;
// CRLF
static const CharacterSet CRLF;
// double quote