diff --git a/src/AuthConfigFactory.cc b/src/AuthConfigFactory.cc index e8450269..a9922f54 100644 --- a/src/AuthConfigFactory.cc +++ b/src/AuthConfigFactory.cc @@ -253,8 +253,7 @@ AuthConfigFactory::findBasicCred std::lower_bound(basicCreds_.begin(), basicCreds_.end(), bc); for(; i != basicCreds_.end() && (*i).host_ == host && (*i).port_ == port; ++i) { - if(util::startsWith(bc.path_.begin(), bc.path_.end(), - (*i).path_.begin(), (*i).path_.end())) { + if(util::startsWith(bc.path_, (*i).path_)) { return i; } } diff --git a/src/ContentTypeRequestGroupCriteria.cc b/src/ContentTypeRequestGroupCriteria.cc index b61c3bb7..078ef7df 100644 --- a/src/ContentTypeRequestGroupCriteria.cc +++ b/src/ContentTypeRequestGroupCriteria.cc @@ -49,8 +49,7 @@ bool tailMatch (InputIterator first, InputIterator last, const std::string& target) { for(; first != last; ++first) { - if(util::endsWith(target.begin(), target.end(), - (*first).begin(), (*first).end())) { + if(util::endsWith(target, *first)) { return true; } } diff --git a/src/DHTMessageTrackerEntry.cc b/src/DHTMessageTrackerEntry.cc index bf3e34d0..59ad4322 100644 --- a/src/DHTMessageTrackerEntry.cc +++ b/src/DHTMessageTrackerEntry.cc @@ -71,13 +71,9 @@ bool DHTMessageTrackerEntry::match(const std::string& transactionID, const std:: if(targetNode_->getIPAddress() == ipaddr) { return true; } - if(util::endsWith(targetNode_->getIPAddress().begin(), - targetNode_->getIPAddress().end(), - ipaddr.begin(), ipaddr.end())) { + if(util::endsWith(targetNode_->getIPAddress(), ipaddr)) { return targetNode_->getIPAddress() == "::ffff:"+ipaddr; - } else if(util::endsWith(ipaddr.begin(), ipaddr.end(), - targetNode_->getIPAddress().begin(), - targetNode_->getIPAddress().end())) { + } else if(util::endsWith(ipaddr, targetNode_->getIPAddress())) { return ipaddr == "::ffff:"+targetNode_->getIPAddress(); } return false; diff --git a/src/DownloadCommand.cc b/src/DownloadCommand.cc index 4bdbe506..e405236f 100644 --- a/src/DownloadCommand.cc +++ b/src/DownloadCommand.cc @@ -383,10 +383,7 @@ void DownloadCommand::installStreamFilter streamFilter->installDelegate(streamFilter_); streamFilter_ = streamFilter; const std::string& name = streamFilter_->getName(); - sinkFilterOnly_ = - util::endsWith(name.begin(), name.end(), - SinkStreamFilter::NAME.begin(), - SinkStreamFilter::NAME.end()); + sinkFilterOnly_ = util::endsWith(name, SinkStreamFilter::NAME); } } // namespace aria2 diff --git a/src/HttpDownloadCommand.cc b/src/HttpDownloadCommand.cc index c31b6089..f919dbfd 100644 --- a/src/HttpDownloadCommand.cc +++ b/src/HttpDownloadCommand.cc @@ -92,10 +92,7 @@ bool HttpDownloadCommand::prepareForNextSegment() { (getRequest()->isKeepAliveEnabled() && ( // Make sure that all filters are finished to pool socket - (!util::endsWith(streamFilterName.begin(), - streamFilterName.end(), - SinkStreamFilter::NAME.begin(), - SinkStreamFilter::NAME.end()) && + (!util::endsWith(streamFilterName, SinkStreamFilter::NAME) && getStreamFilter()->finished()) || getRequestEndOffset() == getFileEntry()->gtoloff(getSegments().front()->getPositionToWrite()) diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc index 2b9ba982..d35acc96 100644 --- a/src/HttpRequest.cc +++ b/src/HttpRequest.cc @@ -248,8 +248,7 @@ std::string HttpRequest::createRequest() std::vector::const_iterator j = headers_.begin(); std::vector::const_iterator jend = headers_.end(); for(; j != jend; ++j) { - if(util::startsWith((*j).begin(), (*j).end(), - (*i).first.begin(), (*i).first.end())) { + if(util::startsWith(*j, (*i).first)) { break; } } diff --git a/src/HttpSkipResponseCommand.cc b/src/HttpSkipResponseCommand.cc index 08499240..97ed1419 100644 --- a/src/HttpSkipResponseCommand.cc +++ b/src/HttpSkipResponseCommand.cc @@ -95,10 +95,7 @@ void HttpSkipResponseCommand::installStreamFilter streamFilter->installDelegate(streamFilter_); streamFilter_ = streamFilter; const std::string& name = streamFilter_->getName(); - sinkFilterOnly_ = - util::endsWith(name.begin(), name.end(), - SinkStreamFilter::NAME.begin(), - SinkStreamFilter::NAME.end()); + sinkFilterOnly_ = util::endsWith(name, SinkStreamFilter::NAME); } bool HttpSkipResponseCommand::executeInternal() diff --git a/src/OptionHandlerImpl.cc b/src/OptionHandlerImpl.cc index f43ea01c..8241e736 100644 --- a/src/OptionHandlerImpl.cc +++ b/src/OptionHandlerImpl.cc @@ -528,9 +528,9 @@ void HttpProxyOptionHandler::parseArg(Option& option, const std::string& optarg) option.put(pref_, optarg); } else { std::string uri; - if(util::startsWith(optarg.begin(), optarg.end(), "http://") || - util::startsWith(optarg.begin(), optarg.end(), "https://") || - util::startsWith(optarg.begin(), optarg.end(), "ftp://")) { + if(util::startsWith(optarg, "http://") || + util::startsWith(optarg, "https://") || + util::startsWith(optarg, "ftp://")) { uri = optarg; } else { uri = "http://"; diff --git a/src/cookie_helper.cc b/src/cookie_helper.cc index 678728e3..d91108a8 100644 --- a/src/cookie_helper.cc +++ b/src/cookie_helper.cc @@ -373,8 +373,7 @@ std::string canonicalizeHost(const std::string& host) bool domainMatch(const std::string& requestHost, const std::string& domain) { return requestHost == domain || - (util::endsWith(requestHost.begin(), requestHost.end(), - domain.begin(), domain.end()) && + (util::endsWith(requestHost, domain) && requestHost[requestHost.size()-domain.size()-1] == '.' && !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) { return requestPath == path || - (util::startsWith(requestPath.begin(), requestPath.end(), - path.begin(), path.end()) && + (util::startsWith(requestPath, path) && (path[path.size()-1] == '/' || requestPath[path.size()] == '/')); } diff --git a/src/util.cc b/src/util.cc index 9c56a408..db5a32a2 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1616,6 +1616,11 @@ bool startsWith(const std::string& a, const char* 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) { return istartsWith(a.begin(), a.end(), b, b+strlen(b)); diff --git a/src/util.h b/src/util.h index 83fb1fc5..e655d4f9 100644 --- a/src/util.h +++ b/src/util.h @@ -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 std::string& b); template bool istartsWith