From: Francesco Chemolli Date: Mon, 30 Dec 2013 09:44:52 +0000 (+0100) Subject: more predefined charactersets X-Git-Tag: SQUID_3_5_0_1~439^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d1cd883830c386222cd1a56c6e4867470f0d877;p=thirdparty%2Fsquid.git more predefined charactersets --- diff --git a/src/base/CharacterSet.cc b/src/base/CharacterSet.cc index 31a45fb036..8eee3e7317 100644 --- a/src/base/CharacterSet.cc +++ b/src/base/CharacterSet.cc @@ -61,11 +61,20 @@ CharacterSet::CharacterSet(const char *label, const RangeSpec & ranges) } const CharacterSet -CharacterSet::ALPHA("ALPHA", {{ 'a', 'z' }, { 'A', 'Z'} }), +CharacterSet::ALPHA("ALPHA", {{ 'a', 'z' }, { 'A', 'Z'}}), CharacterSet::BIT("BIT","01"), CharacterSet::CHAR("CHAR",{{ 1, 127}}), +CharacterSet::CR("CR","\r"), CharacterSet::CRLF("CRLF","\r\n"), CharacterSet::DIGIT("DIGIT","0123456789"), +CharacterSet::DQUOTE("DQUOTE","\""), +CharacterSet::HTAB("HTAB","\t"), CharacterSet::HEXDIG("HEXDIG","0123456789aAbBcCdDeEfF"), -CharacterSet::WSP("WSP"," \t") +CharacterSet::SP("SP"," "), +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}}) ; diff --git a/src/base/CharacterSet.h b/src/base/CharacterSet.h index 003ea88eb8..569ea84527 100644 --- a/src/base/CharacterSet.h +++ b/src/base/CharacterSet.h @@ -41,20 +41,40 @@ public: /// optional set label for debugging (default: "anonymous") const char * name; + // common character sets, insipired to RFC5234 // A-Za-z 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; // CRLF static const CharacterSet CRLF; + // double quote + static const CharacterSet DQUOTE; // 0-9 static const CharacterSet DIGIT; // 0-9aAbBcCdDeEfF static const CharacterSet HEXDIG; + // horizontal tab + static const CharacterSet HTAB; + // white space + static const CharacterSet SP; + // visible (printable) characters + static const CharacterSet VCHAR; // static const CharacterSet WSP; + // character sets from draft httpbis + // any VCHAR except for SPECIAL + static const CharacterSet TCHAR; + // special VCHARs + static const CharacterSet SPECIAL; + // qdtext (ready but not enabled for now) + //static const CharacterSet QDTEXT; + // obs-text + //static const CharacterSet OBSTEXT; private: /** index of characters in this set diff --git a/src/base/testCharacterSet.cc b/src/base/testCharacterSet.cc index 702d26317d..73df3d774a 100644 --- a/src/base/testCharacterSet.cc +++ b/src/base/testCharacterSet.cc @@ -62,3 +62,21 @@ testCharacterSet::CharacterSetConstants() CPPUNIT_ASSERT_EQUAL(true,CharacterSet::ALPHA['Z']); CPPUNIT_ASSERT_EQUAL(false,CharacterSet::ALPHA['5']); } + +void +testCharacterSet::CharacterSetUnion() +{ + { + CharacterSet hex("hex",""); + hex += CharacterSet::DIGIT; + hex += CharacterSet(NULL,"aAbBcCdDeEfF"); + for (int j = 0; j < 255; ++j) + CPPUNIT_ASSERT_EQUAL(CharacterSet::HEXDIG[j],hex[j]); + } + { + CharacterSet hex(NULL,""); + hex = CharacterSet::DIGIT + CharacterSet(NULL,"aAbBcCdDeEfF"); + for (int j = 0; j < 255; ++j) + CPPUNIT_ASSERT_EQUAL(CharacterSet::HEXDIG[j],hex[j]); + } +} diff --git a/src/base/testCharacterSet.h b/src/base/testCharacterSet.h index dd4319e3ae..83a281758a 100644 --- a/src/base/testCharacterSet.h +++ b/src/base/testCharacterSet.h @@ -12,6 +12,7 @@ class testCharacterSet : public CPPUNIT_NS::TestFixture CPPUNIT_TEST( CharacterSetAdd ); CPPUNIT_TEST( CharacterSetAddRange ); CPPUNIT_TEST( CharacterSetConstants ); + CPPUNIT_TEST( CharacterSetUnion ); CPPUNIT_TEST_SUITE_END(); protected: @@ -19,6 +20,7 @@ protected: void CharacterSetAdd(); void CharacterSetAddRange(); void CharacterSetConstants(); + void CharacterSetUnion(); }; #endif /* SQUID_BASE_TESTCHARACTERSET_H */