2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Added util::lowercase() and util::uppercase().
	* src/cookie_helper.cc
	* src/util.cc
	* src/util.h
	* test/UtilTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-10-10 02:51:38 +00:00
parent 788679f0df
commit 8e059b66fa
5 changed files with 44 additions and 2 deletions

View File

@ -1,3 +1,11 @@
2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added util::lowercase() and util::uppercase().
* src/cookie_helper.cc
* src/util.cc
* src/util.h
* test/UtilTest.cc
2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added test cases for util::parseUIntNoThrow() and

View File

@ -133,7 +133,8 @@ bool parseDate(time_t& time, const std::string& cookieDate)
"may", "jun", "jul", "aug",
"sep", "oct", "nov", "dec" };
if((*i).size() >= 3) {
std::string head = util::toLower((*i).substr(0, 3));
std::string head = (*i).substr(0, 3);
util::lowercase(head);
std::string* mptr = std::find(vbegin(MONTH), vend(MONTH), head);
if(mptr != vend(MONTH)) {
foundMonth = true;
@ -225,7 +226,8 @@ bool parse
for(; j != end && *j != ';'; ++j);
std::string::const_iterator eq = i;
for(; eq != j && *eq != '='; ++eq);
std::string attrName = util::toLower(util::stripIter(i, eq));
std::string attrName = util::stripIter(i, eq);
util::lowercase(attrName);
std::string attrValue;
if(eq != j) {
attrValue = util::stripIter(eq+1, j);

View File

@ -926,6 +926,16 @@ std::string toLower(const std::string& src) {
return temp;
}
void uppercase(std::string& s)
{
std::transform(s.begin(), s.end(), s.begin(), ::toupper);
}
void lowercase(std::string& s)
{
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
}
bool isNumericHost(const std::string& name)
{
struct addrinfo hints;

View File

@ -233,6 +233,10 @@ std::string toUpper(const std::string& src);
std::string toLower(const std::string& src);
void uppercase(std::string& s);
void lowercase(std::string& s);
bool isNumericHost(const std::string& name);
void setGlobalSignalHandler(int signal, void (*handler)(int), int flags);

View File

@ -30,6 +30,8 @@ class UtilTest:public CppUnit::TestFixture {
CPPUNIT_TEST(testRandomAlpha);
CPPUNIT_TEST(testToUpper);
CPPUNIT_TEST(testToLower);
CPPUNIT_TEST(testUppercase);
CPPUNIT_TEST(testLowercase);
CPPUNIT_TEST(testPercentDecode);
CPPUNIT_TEST(testGetRealSize);
CPPUNIT_TEST(testAbbrevSize);
@ -86,6 +88,8 @@ public:
void testRandomAlpha();
void testToUpper();
void testToLower();
void testUppercase();
void testLowercase();
void testPercentDecode();
void testGetRealSize();
void testAbbrevSize();
@ -438,6 +442,20 @@ void UtilTest::testToLower() {
CPPUNIT_ASSERT_EQUAL(upp, util::toLower(src));
}
void UtilTest::testUppercase() {
std::string src = "608cabc0f2fa18c260cafd974516865c772363d5";
std::string ans = "608CABC0F2FA18C260CAFD974516865C772363D5";
util::uppercase(src);
CPPUNIT_ASSERT_EQUAL(ans, src);
}
void UtilTest::testLowercase() {
std::string src = "608CABC0F2FA18C260CAFD974516865C772363D5";
std::string ans = "608cabc0f2fa18c260cafd974516865c772363d5";
util::lowercase(src);
CPPUNIT_ASSERT_EQUAL(ans, src);
}
void UtilTest::testPercentDecode() {
std::string src = "http://aria2.sourceforge.net/aria2%200.7.0%20docs.html";
CPPUNIT_ASSERT_EQUAL(std::string("http://aria2.sourceforge.net/aria2 0.7.0 docs.html"),