Use short form of util::startsWith and util::endsWith

pull/9/head
Tatsuhiro Tsujikawa 2012-01-11 01:17:51 +09:00
parent 9331f6a43d
commit b6fd4366fe
11 changed files with 19 additions and 31 deletions

View File

@ -253,8 +253,7 @@ AuthConfigFactory::findBasicCred
std::lower_bound(basicCreds_.begin(), basicCreds_.end(), bc); std::lower_bound(basicCreds_.begin(), basicCreds_.end(), bc);
for(; i != basicCreds_.end() && (*i).host_ == host && (*i).port_ == port; for(; i != basicCreds_.end() && (*i).host_ == host && (*i).port_ == port;
++i) { ++i) {
if(util::startsWith(bc.path_.begin(), bc.path_.end(), if(util::startsWith(bc.path_, (*i).path_)) {
(*i).path_.begin(), (*i).path_.end())) {
return i; return i;
} }
} }

View File

@ -49,8 +49,7 @@ bool tailMatch
(InputIterator first, InputIterator last, const std::string& target) (InputIterator first, InputIterator last, const std::string& target)
{ {
for(; first != last; ++first) { for(; first != last; ++first) {
if(util::endsWith(target.begin(), target.end(), if(util::endsWith(target, *first)) {
(*first).begin(), (*first).end())) {
return true; return true;
} }
} }

View File

@ -71,13 +71,9 @@ bool DHTMessageTrackerEntry::match(const std::string& transactionID, const std::
if(targetNode_->getIPAddress() == ipaddr) { if(targetNode_->getIPAddress() == ipaddr) {
return true; return true;
} }
if(util::endsWith(targetNode_->getIPAddress().begin(), if(util::endsWith(targetNode_->getIPAddress(), ipaddr)) {
targetNode_->getIPAddress().end(),
ipaddr.begin(), ipaddr.end())) {
return targetNode_->getIPAddress() == "::ffff:"+ipaddr; return targetNode_->getIPAddress() == "::ffff:"+ipaddr;
} else if(util::endsWith(ipaddr.begin(), ipaddr.end(), } else if(util::endsWith(ipaddr, targetNode_->getIPAddress())) {
targetNode_->getIPAddress().begin(),
targetNode_->getIPAddress().end())) {
return ipaddr == "::ffff:"+targetNode_->getIPAddress(); return ipaddr == "::ffff:"+targetNode_->getIPAddress();
} }
return false; return false;

View File

@ -383,10 +383,7 @@ void DownloadCommand::installStreamFilter
streamFilter->installDelegate(streamFilter_); streamFilter->installDelegate(streamFilter_);
streamFilter_ = streamFilter; streamFilter_ = streamFilter;
const std::string& name = streamFilter_->getName(); const std::string& name = streamFilter_->getName();
sinkFilterOnly_ = sinkFilterOnly_ = util::endsWith(name, SinkStreamFilter::NAME);
util::endsWith(name.begin(), name.end(),
SinkStreamFilter::NAME.begin(),
SinkStreamFilter::NAME.end());
} }
} // namespace aria2 } // namespace aria2

View File

@ -92,10 +92,7 @@ bool HttpDownloadCommand::prepareForNextSegment() {
(getRequest()->isKeepAliveEnabled() && (getRequest()->isKeepAliveEnabled() &&
( (
// Make sure that all filters are finished to pool socket // Make sure that all filters are finished to pool socket
(!util::endsWith(streamFilterName.begin(), (!util::endsWith(streamFilterName, SinkStreamFilter::NAME) &&
streamFilterName.end(),
SinkStreamFilter::NAME.begin(),
SinkStreamFilter::NAME.end()) &&
getStreamFilter()->finished()) || getStreamFilter()->finished()) ||
getRequestEndOffset() == getRequestEndOffset() ==
getFileEntry()->gtoloff(getSegments().front()->getPositionToWrite()) getFileEntry()->gtoloff(getSegments().front()->getPositionToWrite())

View File

@ -248,8 +248,7 @@ std::string HttpRequest::createRequest()
std::vector<std::string>::const_iterator j = headers_.begin(); std::vector<std::string>::const_iterator j = headers_.begin();
std::vector<std::string>::const_iterator jend = headers_.end(); std::vector<std::string>::const_iterator jend = headers_.end();
for(; j != jend; ++j) { for(; j != jend; ++j) {
if(util::startsWith((*j).begin(), (*j).end(), if(util::startsWith(*j, (*i).first)) {
(*i).first.begin(), (*i).first.end())) {
break; break;
} }
} }

View File

@ -95,10 +95,7 @@ void HttpSkipResponseCommand::installStreamFilter
streamFilter->installDelegate(streamFilter_); streamFilter->installDelegate(streamFilter_);
streamFilter_ = streamFilter; streamFilter_ = streamFilter;
const std::string& name = streamFilter_->getName(); const std::string& name = streamFilter_->getName();
sinkFilterOnly_ = sinkFilterOnly_ = util::endsWith(name, SinkStreamFilter::NAME);
util::endsWith(name.begin(), name.end(),
SinkStreamFilter::NAME.begin(),
SinkStreamFilter::NAME.end());
} }
bool HttpSkipResponseCommand::executeInternal() bool HttpSkipResponseCommand::executeInternal()

View File

@ -528,9 +528,9 @@ void HttpProxyOptionHandler::parseArg(Option& option, const std::string& optarg)
option.put(pref_, optarg); option.put(pref_, optarg);
} else { } else {
std::string uri; std::string uri;
if(util::startsWith(optarg.begin(), optarg.end(), "http://") || if(util::startsWith(optarg, "http://") ||
util::startsWith(optarg.begin(), optarg.end(), "https://") || util::startsWith(optarg, "https://") ||
util::startsWith(optarg.begin(), optarg.end(), "ftp://")) { util::startsWith(optarg, "ftp://")) {
uri = optarg; uri = optarg;
} else { } else {
uri = "http://"; uri = "http://";

View File

@ -373,8 +373,7 @@ std::string canonicalizeHost(const std::string& host)
bool domainMatch(const std::string& requestHost, const std::string& domain) bool domainMatch(const std::string& requestHost, const std::string& domain)
{ {
return requestHost == domain || return requestHost == domain ||
(util::endsWith(requestHost.begin(), requestHost.end(), (util::endsWith(requestHost, domain) &&
domain.begin(), domain.end()) &&
requestHost[requestHost.size()-domain.size()-1] == '.' && requestHost[requestHost.size()-domain.size()-1] == '.' &&
!util::isNumericHost(requestHost)); !util::isNumericHost(requestHost));
} }
@ -382,8 +381,7 @@ bool domainMatch(const std::string& requestHost, const std::string& domain)
bool pathMatch(const std::string& requestPath, const std::string& path) bool pathMatch(const std::string& requestPath, const std::string& path)
{ {
return requestPath == path || return requestPath == path ||
(util::startsWith(requestPath.begin(), requestPath.end(), (util::startsWith(requestPath, path) &&
path.begin(), path.end()) &&
(path[path.size()-1] == '/' || requestPath[path.size()] == '/')); (path[path.size()-1] == '/' || requestPath[path.size()] == '/'));
} }

View File

@ -1616,6 +1616,11 @@ bool startsWith(const std::string& a, const char* b)
return startsWith(a.begin(), a.end(), b, b+strlen(b)); return startsWith(a.begin(), a.end(), b, b+strlen(b));
} }
bool startsWith(const std::string& a, const std::string& b)
{
return startsWith(a.begin(), a.end(), b.begin(), b.end());
}
bool istartsWith(const std::string& a, const char* b) bool istartsWith(const std::string& a, const char* b)
{ {
return istartsWith(a.begin(), a.end(), b, b+strlen(b)); return istartsWith(a.begin(), a.end(), b, b+strlen(b));

View File

@ -624,6 +624,7 @@ bool startsWith(InputIterator first, InputIterator last, const char* b)
} }
bool startsWith(const std::string& a, const char* b); bool startsWith(const std::string& a, const char* b);
bool startsWith(const std::string& a, const std::string& b);
template<typename InputIterator1, typename InputIterator2> template<typename InputIterator1, typename InputIterator2>
bool istartsWith bool istartsWith