mirror of https://github.com/aria2/aria2
Removed util::endsWith(a, b). Added util::iendsWith()
parent
601ec0f44a
commit
79876af88f
|
@ -215,7 +215,7 @@ AuthConfigFactory::BasicCred::BasicCred
|
|||
user_(user), password_(password),
|
||||
host_(host), port_(port), path_(path), activated_(activated)
|
||||
{
|
||||
if(!util::endsWith(path_, "/")) {
|
||||
if(path_.empty() || path_[path_.size()-1] != '/') {
|
||||
path_ += "/";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,8 @@ bool tailMatch
|
|||
(InputIterator first, InputIterator last, const std::string& target)
|
||||
{
|
||||
for(; first != last; ++first) {
|
||||
if(util::endsWith(target, *first)) {
|
||||
if(util::endsWith(target.begin(), target.end(),
|
||||
(*first).begin(), (*first).end())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,9 +71,13 @@ bool DHTMessageTrackerEntry::match(const std::string& transactionID, const std::
|
|||
if(targetNode_->getIPAddress() == ipaddr) {
|
||||
return true;
|
||||
}
|
||||
if(util::endsWith(targetNode_->getIPAddress(), ipaddr)) {
|
||||
if(util::endsWith(targetNode_->getIPAddress().begin(),
|
||||
targetNode_->getIPAddress().end(),
|
||||
ipaddr.begin(), ipaddr.end())) {
|
||||
return targetNode_->getIPAddress() == "::ffff:"+ipaddr;
|
||||
} else if(util::endsWith(ipaddr, targetNode_->getIPAddress())) {
|
||||
} else if(util::endsWith(ipaddr.begin(), ipaddr.end(),
|
||||
targetNode_->getIPAddress().begin(),
|
||||
targetNode_->getIPAddress().end())) {
|
||||
return ipaddr == "::ffff:"+targetNode_->getIPAddress();
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -380,8 +380,11 @@ void DownloadCommand::installStreamFilter
|
|||
}
|
||||
streamFilter->installDelegate(streamFilter_);
|
||||
streamFilter_ = streamFilter;
|
||||
const std::string& name = streamFilter_->getName();
|
||||
sinkFilterOnly_ =
|
||||
util::endsWith(streamFilter_->getName(), SinkStreamFilter::NAME);
|
||||
util::endsWith(name.begin(), name.end(),
|
||||
SinkStreamFilter::NAME.begin(),
|
||||
SinkStreamFilter::NAME.end());
|
||||
}
|
||||
|
||||
} // namespace aria2
|
||||
|
|
|
@ -87,12 +87,15 @@ bool HttpDownloadCommand::prepareForNextSegment() {
|
|||
getDownloadEngine()->addCommand(command);
|
||||
return true;
|
||||
} else {
|
||||
const std::string& streamFilterName = getStreamFilter()->getName();
|
||||
if(getRequest()->isPipeliningEnabled() ||
|
||||
(getRequest()->isKeepAliveEnabled() &&
|
||||
(
|
||||
// Make sure that all filters are finished to pool socket
|
||||
(!util::endsWith(getStreamFilter()->getName(),
|
||||
SinkStreamFilter::NAME) &&
|
||||
(!util::endsWith(streamFilterName.begin(),
|
||||
streamFilterName.end(),
|
||||
SinkStreamFilter::NAME.begin(),
|
||||
SinkStreamFilter::NAME.end()) &&
|
||||
getStreamFilter()->finished()) ||
|
||||
getRequestEndOffset() ==
|
||||
getFileEntry()->gtoloff(getSegments().front()->getPositionToWrite())
|
||||
|
|
|
@ -185,7 +185,9 @@ void HttpServer::feedResponse(const std::string& status,
|
|||
}
|
||||
if(!headers.empty()) {
|
||||
header += headers;
|
||||
if(!util::endsWith(headers, "\r\n")) {
|
||||
if(headers.size() < 2 ||
|
||||
(headers[headers.size()-2] != '\r' &&
|
||||
headers[headers.size()-1] != '\n')) {
|
||||
header += "\r\n";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -94,8 +94,11 @@ void HttpSkipResponseCommand::installStreamFilter
|
|||
}
|
||||
streamFilter->installDelegate(streamFilter_);
|
||||
streamFilter_ = streamFilter;
|
||||
const std::string& name = streamFilter_->getName();
|
||||
sinkFilterOnly_ =
|
||||
util::endsWith(streamFilter_->getName(), SinkStreamFilter::NAME);
|
||||
util::endsWith(name.begin(), name.end(),
|
||||
SinkStreamFilter::NAME.begin(),
|
||||
SinkStreamFilter::NAME.end());
|
||||
}
|
||||
|
||||
bool HttpSkipResponseCommand::executeInternal()
|
||||
|
|
|
@ -520,7 +520,9 @@ HttpProxyUserOptionHandler::HttpProxyUserOptionHandler
|
|||
void HttpProxyUserOptionHandler::parseArg
|
||||
(Option& option, const std::string& optarg)
|
||||
{
|
||||
if(util::endsWith(pref_->k, "-user")) {
|
||||
const char A2_USER[] = "-user";
|
||||
if(util::endsWith(pref_->k.begin(), pref_->k.end(),
|
||||
A2_USER, vend(A2_USER)-1)) {
|
||||
const Pref* proxyPref = option::k2p(pref_->k.substr(0, pref_->k.size()-5));
|
||||
const std::string& olduri = option.get(proxyPref);
|
||||
if(!olduri.empty()) {
|
||||
|
@ -562,7 +564,9 @@ HttpProxyPasswdOptionHandler::HttpProxyPasswdOptionHandler
|
|||
void HttpProxyPasswdOptionHandler::parseArg
|
||||
(Option& option, const std::string& optarg)
|
||||
{
|
||||
if(util::endsWith(pref_->k, "-passwd")) {
|
||||
const char A2_PASSWD[] = "-passwd";
|
||||
if(util::endsWith(pref_->k.begin(), pref_->k.end(),
|
||||
A2_PASSWD, vend(A2_PASSWD)-1)) {
|
||||
const Pref* proxyPref = option::k2p(pref_->k.substr(0, pref_->k.size()-7));
|
||||
const std::string& olduri = option.get(proxyPref);
|
||||
if(!olduri.empty()) {
|
||||
|
|
|
@ -182,7 +182,7 @@ OutputIterator createUri
|
|||
const std::string& filePath)
|
||||
{
|
||||
for(; first != last; ++first) {
|
||||
if(util::endsWith(*first, "/")) {
|
||||
if(!(*first).empty() && (*first)[(*first).size()-1] == '/') {
|
||||
*out++ = (*first)+filePath;
|
||||
} else {
|
||||
*out++ = (*first)+"/"+filePath;
|
||||
|
@ -310,7 +310,7 @@ void extractFileEntries
|
|||
std::vector<std::string> uris;
|
||||
for(std::vector<std::string>::const_iterator i = urlList.begin(),
|
||||
eoi = urlList.end(); i != eoi; ++i) {
|
||||
if(util::endsWith(*i, A2STR::SLASH_C)) {
|
||||
if(!(*i).empty() && (*i)[(*i).size()-1] == '/') {
|
||||
uris.push_back((*i)+util::percentEncode(utf8Name));
|
||||
} else {
|
||||
uris.push_back(*i);
|
||||
|
|
|
@ -368,7 +368,8 @@ std::string canonicalizeHost(const std::string& host)
|
|||
bool domainMatch(const std::string& requestHost, const std::string& domain)
|
||||
{
|
||||
return requestHost == domain ||
|
||||
(util::endsWith(requestHost, domain) &&
|
||||
(util::endsWith(requestHost.begin(), requestHost.end(),
|
||||
domain.begin(), domain.end()) &&
|
||||
requestHost[requestHost.size()-domain.size()-1] == '.' &&
|
||||
!util::isNumericHost(requestHost));
|
||||
}
|
||||
|
|
21
src/util.cc
21
src/util.cc
|
@ -230,20 +230,6 @@ int32_t difftvsec(struct timeval tv1, struct timeval tv2) {
|
|||
return tv1.tv_sec-tv2.tv_sec;
|
||||
}
|
||||
|
||||
bool endsWith(const std::string& target, const std::string& part) {
|
||||
if(target.size() < part.size()) {
|
||||
return false;
|
||||
}
|
||||
if(part.empty()) {
|
||||
return true;
|
||||
}
|
||||
if(target.rfind(part) == target.size()-part.size()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string replace(const std::string& target, const std::string& oldstr, const std::string& newstr) {
|
||||
if(target.empty() || oldstr.empty()) {
|
||||
return target;
|
||||
|
@ -1516,7 +1502,9 @@ void executeHook
|
|||
|
||||
memset(&pi, 0, sizeof (pi));
|
||||
|
||||
bool batch = util::endsWith(util::toLower(command), ".bat");
|
||||
const char A2_BAT[] = ".bat";
|
||||
bool batch = util::iendsWith(command.begin(), command.end(),
|
||||
A2_BAT, vend(A2_BAT)-1);
|
||||
std::string cmdline;
|
||||
std::string cmdexe;
|
||||
if(batch) {
|
||||
|
@ -1618,7 +1606,8 @@ bool noProxyDomainMatch
|
|||
const std::string& domain)
|
||||
{
|
||||
if(!domain.empty() && domain[0] == '.' && !util::isNumericHost(hostname)) {
|
||||
return util::endsWith(hostname, domain);
|
||||
return util::endsWith(hostname.begin(), hostname.end(),
|
||||
domain.begin(), domain.end());
|
||||
} else {
|
||||
return hostname == domain;
|
||||
}
|
||||
|
|
18
src/util.h
18
src/util.h
|
@ -205,10 +205,6 @@ InputIterator lstripIter
|
|||
std::string strip
|
||||
(const std::string& str, const std::string& chars = DEFAULT_STRIP_CHARSET);
|
||||
|
||||
bool startsWith(const std::string& target, const std::string& part);
|
||||
|
||||
bool endsWith(const std::string& target, const std::string& part);
|
||||
|
||||
std::string replace(const std::string& target, const std::string& oldstr, const std::string& newstr);
|
||||
|
||||
std::string percentEncode(const unsigned char* target, size_t len);
|
||||
|
@ -714,6 +710,20 @@ bool endsWith
|
|||
return std::equal(first2, last2, last1-(last2-first2));
|
||||
}
|
||||
|
||||
template<typename InputIterator1, typename InputIterator2>
|
||||
bool iendsWith
|
||||
(InputIterator1 first1,
|
||||
InputIterator1 last1,
|
||||
InputIterator2 first2,
|
||||
InputIterator2 last2)
|
||||
{
|
||||
if(last1-first1 < last2-first2) {
|
||||
return false;
|
||||
}
|
||||
first1 = last1-(last2-first2);
|
||||
return strieq(first1, last1, first2, last2);
|
||||
}
|
||||
|
||||
void generateRandomData(unsigned char* data, size_t length);
|
||||
|
||||
// Saves data to file whose name is filename. If overwrite is true,
|
||||
|
|
|
@ -33,6 +33,7 @@ class UtilTest:public CppUnit::TestFixture {
|
|||
CPPUNIT_TEST(testStreq);
|
||||
CPPUNIT_TEST(testStrieq);
|
||||
CPPUNIT_TEST(testEndsWith);
|
||||
CPPUNIT_TEST(testIendsWith);
|
||||
CPPUNIT_TEST(testReplace);
|
||||
CPPUNIT_TEST(testStartsWith);
|
||||
// may be moved to other helper class in the future.
|
||||
|
@ -100,6 +101,7 @@ public:
|
|||
void testStreq();
|
||||
void testStrieq();
|
||||
void testEndsWith();
|
||||
void testIendsWith();
|
||||
void testReplace();
|
||||
void testStartsWith();
|
||||
// may be moved to other helper class in the future.
|
||||
|
@ -635,53 +637,57 @@ void UtilTest::testSplitIterM() {
|
|||
void UtilTest::testEndsWith() {
|
||||
std::string target = "abcdefg";
|
||||
std::string part = "fg";
|
||||
CPPUNIT_ASSERT(util::endsWith(target, part));
|
||||
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
|
||||
part.begin(), part.end()));
|
||||
|
||||
target = "abdefg";
|
||||
part = "g";
|
||||
CPPUNIT_ASSERT(util::endsWith(target, part));
|
||||
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
|
||||
part.begin(), part.end()));
|
||||
|
||||
target = "abdefg";
|
||||
part = "eg";
|
||||
CPPUNIT_ASSERT(!util::endsWith(target, part));
|
||||
CPPUNIT_ASSERT(!util::endsWith(target.begin(), target.end(),
|
||||
part.begin(), part.end()));
|
||||
|
||||
target = "g";
|
||||
part = "eg";
|
||||
CPPUNIT_ASSERT(!util::endsWith(target, part));
|
||||
CPPUNIT_ASSERT(!util::endsWith(target.begin(), target.end(),
|
||||
part.begin(), part.end()));
|
||||
|
||||
target = "g";
|
||||
part = "g";
|
||||
CPPUNIT_ASSERT(util::endsWith(target, part));
|
||||
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
|
||||
part.begin(), part.end()));
|
||||
|
||||
target = "g";
|
||||
part = "";
|
||||
CPPUNIT_ASSERT(util::endsWith(target, part));
|
||||
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
|
||||
part.begin(), part.end()));
|
||||
|
||||
target = "";
|
||||
part = "";
|
||||
CPPUNIT_ASSERT(util::endsWith(target, part));
|
||||
CPPUNIT_ASSERT(util::endsWith(target.begin(), target.end(),
|
||||
part.begin(), part.end()));
|
||||
|
||||
target = "";
|
||||
part = "g";
|
||||
CPPUNIT_ASSERT(!util::endsWith(target, part));
|
||||
CPPUNIT_ASSERT(!util::endsWith(target.begin(), target.end(),
|
||||
part.begin(), part.end()));
|
||||
}
|
||||
|
||||
void UtilTest::testIendsWith() {
|
||||
std::string target = "abcdefg";
|
||||
std::string part = "Fg";
|
||||
CPPUNIT_ASSERT(util::iendsWith(target.begin(), target.end(),
|
||||
part.begin(), part.end()));
|
||||
|
||||
target = "abdefg";
|
||||
part = "ef";
|
||||
CPPUNIT_ASSERT(!util::iendsWith(target.begin(), target.end(),
|
||||
part.begin(), part.end()));
|
||||
}
|
||||
|
||||
void UtilTest::testStreq()
|
||||
{
|
||||
std::string s1, s2;
|
||||
|
|
Loading…
Reference in New Issue