From ea49e9c297ade01cad641f468271e7e0444fe2b3 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Thu, 25 Nov 2010 12:13:33 +0000 Subject: [PATCH] 2010-11-25 Tatsuhiro Tsujikawa Made strings which are only used in comparison plain C strings. * src/HttpHeader.cc * src/HttpHeader.h * src/Netrc.cc * src/Netrc.h * test/HttpHeaderTest.cc --- ChangeLog | 9 +++++++++ src/HttpHeader.cc | 14 +++++--------- src/HttpHeader.h | 18 +++++++++--------- src/Netrc.cc | 24 ++++++------------------ src/Netrc.h | 12 ------------ test/HttpHeaderTest.cc | 2 +- 6 files changed, 30 insertions(+), 49 deletions(-) diff --git a/ChangeLog b/ChangeLog index a10756b8..b048c815 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-11-25 Tatsuhiro Tsujikawa + + Made strings which are only used in comparison plain C strings. + * src/HttpHeader.cc + * src/HttpHeader.h + * src/Netrc.cc + * src/Netrc.h + * test/HttpHeaderTest.cc + 2010-11-24 Tatsuhiro Tsujikawa Added white space after ',' when enumerating valid parameters. diff --git a/src/HttpHeader.cc b/src/HttpHeader.cc index 2de6db94..9e191ab1 100644 --- a/src/HttpHeader.cc +++ b/src/HttpHeader.cc @@ -52,20 +52,12 @@ const std::string HttpHeader::CONTENT_DISPOSITION("Content-Disposition"); const std::string HttpHeader::SET_COOKIE("Set-Cookie"); -const std::string HttpHeader::CHUNKED("chunked"); - -const std::string HttpHeader::GZIP("gzip"); - -const std::string HttpHeader::DEFLATE("deflate"); - const std::string HttpHeader::CONTENT_TYPE("Content-Type"); const std::string HttpHeader::RETRY_AFTER("Retry-After"); const std::string HttpHeader::CONNECTION("Connection"); -const std::string HttpHeader::CLOSE("close"); - const std::string HttpHeader::CONTENT_LENGTH("Content-Length"); const std::string HttpHeader::CONTENT_RANGE("Content-Range"); @@ -74,7 +66,11 @@ const std::string HttpHeader::LAST_MODIFIED("Last-Modified"); const std::string HttpHeader::ACCEPT_ENCODING("Accept-Encoding"); -const std::string HttpHeader::HTTP_1_1("HTTP/1.1"); +const char HttpHeader::HTTP_1_1[] = "HTTP/1.1"; +const char HttpHeader::CLOSE[] = "close"; +const char HttpHeader::CHUNKED[] = "chunked"; +const char HttpHeader::GZIP[] = "gzip"; +const char HttpHeader::DEFLATE[] = "deflate"; HttpHeader::HttpHeader() {} HttpHeader::~HttpHeader() {} diff --git a/src/HttpHeader.h b/src/HttpHeader.h index 6eb6ad1d..d0d60c93 100644 --- a/src/HttpHeader.h +++ b/src/HttpHeader.h @@ -122,20 +122,12 @@ public: static const std::string SET_COOKIE; - static const std::string CHUNKED; - - static const std::string GZIP; - - static const std::string DEFLATE; - static const std::string CONTENT_TYPE; static const std::string RETRY_AFTER; static const std::string CONNECTION; - static const std::string CLOSE; - static const std::string CONTENT_LENGTH; static const std::string CONTENT_RANGE; @@ -144,7 +136,15 @@ public: static const std::string ACCEPT_ENCODING; - static const std::string HTTP_1_1; + static const char HTTP_1_1[]; + + static const char CLOSE[]; + + static const char CHUNKED[]; + + static const char GZIP[]; + + static const char DEFLATE[]; }; typedef SharedHandle HttpHeaderHandle; diff --git a/src/Netrc.cc b/src/Netrc.cc index 44acdbe5..507a7f81 100644 --- a/src/Netrc.cc +++ b/src/Netrc.cc @@ -108,18 +108,6 @@ bool DefaultAuthenticator::match(const std::string& hostname) const return true; } -const std::string Netrc::A2_MACHINE("machine"); - -const std::string Netrc::A2_DEFAULT("default"); - -const std::string Netrc::A2_LOGIN("login"); - -const std::string Netrc::A2_PASSWORD("password"); - -const std::string Netrc::A2_ACCOUNT("account"); - -const std::string Netrc::A2_MACDEF("macdef"); - Netrc::Netrc() {} Netrc::~Netrc() {} @@ -169,11 +157,11 @@ void Netrc::parse(const std::string& path) eoi = tokens.end(); iter != eoi; ++iter) { const std::string& token = *iter; if(state == GET_TOKEN) { - if(token == Netrc::A2_MACHINE) { + if(token == "machine") { storeAuthenticator(authenticator); authenticator.reset(new Authenticator()); state = SET_MACHINE; - } else if(token == Netrc::A2_DEFAULT) { + } else if(token == "default") { storeAuthenticator(authenticator); authenticator.reset(new DefaultAuthenticator()); } else { @@ -182,13 +170,13 @@ void Netrc::parse(const std::string& path) (fmt("Netrc:parse error. %s encounterd where 'machine'" " or 'default' expected.", token.c_str())); } - if(token == Netrc::A2_LOGIN) { + if(token == "login") { state = SET_LOGIN; - } else if(token == Netrc::A2_PASSWORD) { + } else if(token == "password") { state = SET_PASSWORD; - } else if(token == Netrc::A2_ACCOUNT) { + } else if(token == "account") { state = SET_ACCOUNT; - } else if(token == Netrc::A2_MACDEF) { + } else if(token == "macdef") { state = SET_MACDEF; } } diff --git a/src/Netrc.h b/src/Netrc.h index be9e46fb..896b8f43 100644 --- a/src/Netrc.h +++ b/src/Netrc.h @@ -137,18 +137,6 @@ public: } void addAuthenticator(const SharedHandle& authenticator); - - static const std::string A2_MACHINE; - - static const std::string A2_DEFAULT; - - static const std::string A2_LOGIN; - - static const std::string A2_PASSWORD; - - static const std::string A2_ACCOUNT; - - static const std::string A2_MACDEF; }; } // namespace aria2 diff --git a/test/HttpHeaderTest.cc b/test/HttpHeaderTest.cc index 47a9bd65..93a6064f 100644 --- a/test/HttpHeaderTest.cc +++ b/test/HttpHeaderTest.cc @@ -93,7 +93,7 @@ void HttpHeaderTest::testClearField() CPPUNIT_ASSERT_EQUAL(std::string(""), h.getFirst("Foo")); CPPUNIT_ASSERT_EQUAL(200, h.getStatusCode()); - CPPUNIT_ASSERT_EQUAL(HttpHeader::HTTP_1_1, h.getVersion()); + CPPUNIT_ASSERT_EQUAL(std::string(HttpHeader::HTTP_1_1), h.getVersion()); } } // namespace aria2