diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-10-18 12:31:07 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-10-18 12:31:07 +0000 |
| commit | c8d34a46bee7bcc2f377dd1ba57f61b1b8108ffc (patch) | |
| tree | 564c707b7aa2703f5f509eb4db4f70c94b7e63fc /src | |
| parent | 1a7064f6f67564ede3f31bb300caebbeb61c6f66 (diff) | |
2009-10-18 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Replaced Util::slice() with split()
* src/AbstractCommand.cc
* src/CookieParser.cc
* src/File.cc
* src/HttpHeaderProcessor.cc
* src/HttpRequest.cc
* src/Metalink2RequestGroup.cc
* src/MetalinkParserController.cc
* src/Netrc.cc
* src/NsCookieParser.cc
* src/ParameterizedStringParser.cc
* src/ServerStatMan.cc
* src/UriListParser.cc
* src/Util.cc
* src/Util.h
* src/bittorrent_helper.cc
* test/UtilTest.cc
Diffstat (limited to 'src')
| -rw-r--r-- | src/AbstractCommand.cc | 4 | ||||
| -rw-r--r-- | src/CookieParser.cc | 7 | ||||
| -rw-r--r-- | src/File.cc | 10 | ||||
| -rw-r--r-- | src/HttpHeaderProcessor.cc | 5 | ||||
| -rw-r--r-- | src/HttpRequest.cc | 5 | ||||
| -rw-r--r-- | src/Metalink2RequestGroup.cc | 3 | ||||
| -rw-r--r-- | src/MetalinkParserController.cc | 5 | ||||
| -rw-r--r-- | src/Netrc.cc | 2 | ||||
| -rw-r--r-- | src/NsCookieParser.cc | 5 | ||||
| -rw-r--r-- | src/ParameterizedStringParser.cc | 3 | ||||
| -rw-r--r-- | src/ServerStatMan.cc | 7 | ||||
| -rw-r--r-- | src/UriListParser.cc | 2 | ||||
| -rw-r--r-- | src/Util.cc | 25 | ||||
| -rw-r--r-- | src/Util.h | 72 | ||||
| -rw-r--r-- | src/bittorrent_helper.cc | 10 |
15 files changed, 73 insertions, 92 deletions
diff --git a/src/AbstractCommand.cc b/src/AbstractCommand.cc index b0e74a42..0f0511d5 100644 --- a/src/AbstractCommand.cc +++ b/src/AbstractCommand.cc @@ -414,8 +414,8 @@ public: static bool inNoProxy(const SharedHandle<Request>& req, const std::string& noProxy) { - std::deque<std::string> entries; - Util::slice(entries, noProxy, ',', true); + std::vector<std::string> entries; + split(noProxy, std::back_inserter(entries), ",", true); if(entries.empty()) { return false; } diff --git a/src/CookieParser.cc b/src/CookieParser.cc index 0f49f6e5..c0f2775d 100644 --- a/src/CookieParser.cc +++ b/src/CookieParser.cc @@ -39,6 +39,7 @@ #include <utility> #include <istream> #include <map> +#include <vector> #include "Util.h" #include "A2STR.h" @@ -61,8 +62,8 @@ Cookie CookieParser::parse(const std::string& cookieStr) const Cookie CookieParser::parse(const std::string& cookieStr, const std::string& defaultDomain, const std::string& defaultPath) const { - std::deque<std::string> terms; - Util::slice(terms, Util::trim(cookieStr), ';', true); + std::vector<std::string> terms; + split(Util::trim(cookieStr), std::back_inserter(terms), ";", true); if(terms.empty()) { return Cookie(); } @@ -73,7 +74,7 @@ Cookie CookieParser::parse(const std::string& cookieStr, const std::string& defa values[C_DOMAIN] = defaultDomain; values[C_PATH] = defaultPath; - for(std::deque<std::string>::iterator itr = terms.begin()+1; + for(std::vector<std::string>::iterator itr = terms.begin()+1; itr != terms.end(); ++itr) { std::pair<std::string, std::string> nv; Util::split(nv, *itr, '='); diff --git a/src/File.cc b/src/File.cc index bcd593a1..8957a954 100644 --- a/src/File.cc +++ b/src/File.cc @@ -39,7 +39,7 @@ #include <utime.h> #include <unistd.h> -#include <deque> +#include <vector> #include <cstring> #include <cstdio> @@ -105,8 +105,8 @@ bool File::mkdirs() { if(isDir()) { return false; } - std::deque<std::string> dirs; - Util::slice(dirs, name, '/'); + std::vector<std::string> dirs; + split(name, std::back_inserter(dirs), "/"); if(!dirs.size()) { return true; } @@ -115,8 +115,8 @@ bool File::mkdirs() { if(Util::startsWith(name, A2STR::SLASH_C)) { accDir = A2STR::SLASH_C; } - for(std::deque<std::string>::const_iterator itr = dirs.begin(); itr != dirs.end(); - ++itr, accDir += A2STR::SLASH_C) { + for(std::vector<std::string>::const_iterator itr = dirs.begin(); + itr != dirs.end(); ++itr, accDir += A2STR::SLASH_C) { accDir += *itr; if(File(accDir).isDir()) { continue; diff --git a/src/HttpHeaderProcessor.cc b/src/HttpHeaderProcessor.cc index 298b936e..10e472a2 100644 --- a/src/HttpHeaderProcessor.cc +++ b/src/HttpHeaderProcessor.cc @@ -35,6 +35,7 @@ #include "HttpHeaderProcessor.h" #include <sstream> +#include <vector> #include "HttpHeader.h" #include "message.h" @@ -124,8 +125,8 @@ SharedHandle<HttpHeader> HttpHeaderProcessor::getHttpRequestHeader() delimpos < 14) { throw DL_RETRY_EX(EX_NO_STATUS_HEADER); } - std::deque<std::string> firstLine; - Util::slice(firstLine, _buf.substr(0, delimpos), ' ', true); + std::vector<std::string> firstLine; + split(_buf.substr(0, delimpos), std::back_inserter(firstLine), " ", true); if(firstLine.size() != 3) { throw DL_ABORT_EX("Malformed HTTP request header."); } diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 63bdc557..7bf407dc 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -36,6 +36,7 @@ #include <cassert> #include <numeric> +#include <vector> #include "Segment.h" #include "Range.h" @@ -276,8 +277,8 @@ void HttpRequest::disableContentEncoding() void HttpRequest::addHeader(const std::string& headersString) { - std::deque<std::string> headers; - Util::slice(headers, headersString, '\n', true); + std::vector<std::string> headers; + split(headersString, std::back_inserter(headers), "\n", true); _headers.insert(_headers.end(), headers.begin(), headers.end()); } diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc index 9ca59766..dabd04a6 100644 --- a/src/Metalink2RequestGroup.cc +++ b/src/Metalink2RequestGroup.cc @@ -143,7 +143,8 @@ Metalink2RequestGroup::createRequestGroup SharedHandle<MetalinkEntry>& entry = *itr; if(option->defined(PREF_METALINK_LOCATION)) { std::deque<std::string> locations; - Util::slice(locations, option->get(PREF_METALINK_LOCATION), ',', true); + split(option->get(PREF_METALINK_LOCATION), std::back_inserter(locations), + ",", true); entry->setLocationPreference(locations, 100); } if(option->get(PREF_METALINK_PREFERRED_PROTOCOL) != V_NONE) { diff --git a/src/MetalinkParserController.cc b/src/MetalinkParserController.cc index 94a78d09..71b45e75 100644 --- a/src/MetalinkParserController.cc +++ b/src/MetalinkParserController.cc @@ -35,6 +35,7 @@ #include "MetalinkParserController.h" #include <algorithm> +#include <vector> #include "Metalinker.h" #include "MetalinkEntry.h" @@ -75,8 +76,8 @@ void MetalinkParserController::setFileNameOfEntry(const std::string& filename) if(_tEntry.isNull()) { return; } - std::deque<std::string> elements; - Util::slice(elements, filename, '/'); + std::vector<std::string> elements; + split(filename, std::back_inserter(elements), "/"); std::string path = Util::joinPath(elements.begin(), elements.end()); if(_tEntry->file.isNull()) { diff --git a/src/Netrc.cc b/src/Netrc.cc index 453cddbd..d5332945 100644 --- a/src/Netrc.cc +++ b/src/Netrc.cc @@ -93,7 +93,7 @@ void Netrc::parse(const std::string& path) continue; } std::vector<std::string> tokens; - Util::split(line, std::back_inserter(tokens), " \t", true); + split(line, std::back_inserter(tokens), " \t", true); for(std::vector<std::string>::const_iterator iter = tokens.begin(); iter != tokens.end(); ++iter) { const std::string& token = *iter; diff --git a/src/NsCookieParser.cc b/src/NsCookieParser.cc index 4a146932..962dcef1 100644 --- a/src/NsCookieParser.cc +++ b/src/NsCookieParser.cc @@ -35,6 +35,7 @@ #include "NsCookieParser.h" #include <fstream> +#include <vector> #include "Util.h" #include "A2STR.h" @@ -51,8 +52,8 @@ static const std::string C_TRUE("TRUE"); static Cookie parseNsCookie(const std::string& nsCookieStr) { - std::deque<std::string> vs; - Util::slice(vs, nsCookieStr, '\t', true); + std::vector<std::string> vs; + split(nsCookieStr, std::back_inserter(vs), "\t", true); if(vs.size() < 6 ) { return Cookie(); } diff --git a/src/ParameterizedStringParser.cc b/src/ParameterizedStringParser.cc index 870f4c1b..74f81ce4 100644 --- a/src/ParameterizedStringParser.cc +++ b/src/ParameterizedStringParser.cc @@ -91,7 +91,8 @@ PStringDatumHandle ParameterizedStringParser::createSelect(const std::string& sr throw DL_ABORT_EX("Missing '}' in the parameterized string."); } std::deque<std::string> values; - Util::slice(values, src.substr(offset, rightParenIndex-offset), ',', true); + split(src.substr(offset, rightParenIndex-offset), std::back_inserter(values), + ",", true); if(values.empty()) { throw DL_ABORT_EX("Empty {} is not allowed."); } diff --git a/src/ServerStatMan.cc b/src/ServerStatMan.cc index 8948fa2c..f8422d7a 100644 --- a/src/ServerStatMan.cc +++ b/src/ServerStatMan.cc @@ -38,6 +38,7 @@ #include <ostream> #include <iterator> #include <map> +#include <vector> #include "ServerStat.h" #include "Util.h" @@ -101,10 +102,10 @@ bool ServerStatMan::load(std::istream& in) if(line.empty()) { continue; } - std::deque<std::string> items; - Util::slice(items, line, ','); + std::vector<std::string> items; + split(line, std::back_inserter(items), ","); std::map<std::string, std::string> m; - for(std::deque<std::string>::const_iterator i = items.begin(); + for(std::vector<std::string>::const_iterator i = items.begin(); i != items.end(); ++i) { std::pair<std::string, std::string> p = Util::split(*i, "="); Util::trimSelf(p.first); diff --git a/src/UriListParser.cc b/src/UriListParser.cc index f1bcf4a2..14d6d52c 100644 --- a/src/UriListParser.cc +++ b/src/UriListParser.cc @@ -74,7 +74,7 @@ void UriListParser::parseNext(std::deque<std::string>& uris, Option& op) } do { if(!Util::trim(_line).empty()) { - Util::slice(uris, _line, '\t', true); + split(_line, std::back_inserter(uris), "\t", true); getOptions(op); return; } diff --git a/src/Util.cc b/src/Util.cc index d52cdd3f..08412da8 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -141,31 +141,6 @@ int32_t Util::difftvsec(struct timeval tv1, struct timeval tv2) { return tv1.tv_sec-tv2.tv_sec; } -void Util::slice(std::deque<std::string>& result, const std::string& src, char delim, bool doTrim) { - std::string::size_type p = 0; - while(1) { - std::string::size_type np = src.find(delim, p); - if(np == std::string::npos) { - std::string term = src.substr(p); - if(doTrim) { - term = trim(term); - } - if(term.size()) { - result.push_back(term); - } - break; - } - std::string term = src.substr(p, np-p); - if(doTrim) { - term = trim(term); - } - p = np+1; - if(term.size()) { - result.push_back(term); - } - } -} - bool Util::startsWith(const std::string& target, const std::string& part) { if(target.size() < part.size()) { return false; @@ -133,43 +133,6 @@ public: */ static int64_t difftv(struct timeval tv1, struct timeval tv2); static int32_t difftvsec(struct timeval tv1, struct timeval tv2); - /** - * Take a string src which is a deliminated list and add its elements - * into result. result is not cleared before conversion begins. - */ - static void slice(std::deque<std::string>& result, const std::string& src, - char delim, bool trim = false); - - template<typename OutputIterator> - static OutputIterator split(const std::string& src, OutputIterator out, - const std::string& delims, bool doTrim = false) - { - std::string::size_type p = 0; - while(1) { - std::string::size_type np = src.find_first_of(delims, p); - if(np == std::string::npos) { - std::string term = src.substr(p); - if(doTrim) { - term = trim(term); - } - if(!term.empty()) { - *out = term; - ++out; - } - break; - } - std::string term = src.substr(p, np-p); - if(doTrim) { - term = trim(term); - } - p = np+1; - if(!term.empty()) { - *out = term; - ++out; - } - } - return out; - } static const std::string DEFAULT_TRIM_CHARSET; @@ -334,6 +297,41 @@ public: static std::map<size_t, std::string> createIndexPathMap(std::istream& i); }; +/** + * Take a string src which is a deliminated list and add its elements + * into result. result is stored in out. + */ +template<typename OutputIterator> +static OutputIterator split(const std::string& src, OutputIterator out, + const std::string& delims, bool doTrim = false) +{ + std::string::size_type p = 0; + while(1) { + std::string::size_type np = src.find_first_of(delims, p); + if(np == std::string::npos) { + std::string term = src.substr(p); + if(doTrim) { + term = Util::trim(term); + } + if(!term.empty()) { + *out = term; + ++out; + } + break; + } + std::string term = src.substr(p, np-p); + if(doTrim) { + term = Util::trim(term); + } + p = np+1; + if(!term.empty()) { + *out = term; + ++out; + } + } + return out; +} + } // namespace aria2 #endif // _D_UTIL_H_ diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc index a161a98a..27400212 100644 --- a/src/bittorrent_helper.cc +++ b/src/bittorrent_helper.cc @@ -195,9 +195,9 @@ static void extractFileEntries } const BDE& nameData = infoDict[nameKey]; if(nameData.isString()) { - // Slice path by '/' just in case nasty ".." is included in name - std::deque<std::string> pathelems; - Util::slice(pathelems, nameData.s(), '/'); + // Split path by '/' just in case nasty ".." is included in name + std::vector<std::string> pathelems; + split(nameData.s(), std::back_inserter(pathelems), "/"); name = Util::joinPath(pathelems.begin(), pathelems.end()); torrent[NAME] = nameData.s(); } else { @@ -248,8 +248,8 @@ static void extractFileEntries strappend(path, "/", Util::joinPath(pathelem.begin(), pathelem.end())); // Split path with '/' again because each pathList element can // contain "/" inside. - std::deque<std::string> elements; - Util::slice(elements, path, '/'); + std::vector<std::string> elements; + split(path, std::back_inserter(elements), "/"); path = Util::joinPath(elements.begin(), elements.end()); std::deque<std::string> uris; |
