diff --git a/src/ExpatMetalinkProcessor.cc b/src/ExpatMetalinkProcessor.cc index de90bf03..afe6eefd 100644 --- a/src/ExpatMetalinkProcessor.cc +++ b/src/ExpatMetalinkProcessor.cc @@ -35,6 +35,7 @@ #include "ExpatMetalinkProcessor.h" #include +#include #include "DefaultDiskWriter.h" #include "MetalinkParserStateMachine.h" @@ -63,17 +64,18 @@ public: } // namespace namespace { +template void splitNsName (std::string& localname, std::string& prefix, std::string& nsUri, - const std::string& nsName) + InputIterator first, InputIterator last) { - std::pair nsNamePair; - util::divide(nsNamePair, nsName, '\t'); - if(nsNamePair.second.empty()) { - localname = nsNamePair.first; + std::pair nsNamePair; + util::divide(nsNamePair, first, last, '\t'); + if(nsNamePair.second.first == nsNamePair.second.second) { + localname.assign(nsNamePair.first.first, nsNamePair.first.second); } else { - nsUri = nsNamePair.first; - localname = nsNamePair.second; + nsUri.assign(nsNamePair.first.first, nsNamePair.first.second); + localname.assign(nsNamePair.second.first, nsNamePair.second.second); } } } // namespace @@ -87,29 +89,22 @@ void mlStartElement(void* userData, const char* nsName, const char** attrs) if(attrs) { const char** p = attrs; while(*p != 0) { - std::string attrNsName = *p++; + const char* attrNsName = *p++; if(*p == 0) { break; } - std::string value = *p++; - std::pair nsNamePair; - util::divide(nsNamePair, attrNsName, '\t'); XmlAttr xa; - if(nsNamePair.second.empty()) { - xa.localname = nsNamePair.first; - } else { - xa.nsUri = nsNamePair.first; - xa.localname = nsNamePair.second; - } - xa.value = value; + splitNsName(xa.localname, xa.prefix, xa.nsUri, + attrNsName, attrNsName+strlen(attrNsName)); + const char* value = *p++; + xa.value.assign(value, value+strlen(value)); xmlAttrs.push_back(xa); } } std::string localname; std::string prefix; std::string nsUri; - splitNsName(localname, prefix, nsUri, nsName); - + splitNsName(localname, prefix, nsUri, nsName, nsName+strlen(nsName)); sd->stm_->beginElement(localname, prefix, nsUri, xmlAttrs); if(sd->stm_->needsCharactersBuffering()) { sd->charactersStack_.push_front(A2STR::NIL); @@ -123,7 +118,7 @@ void mlEndElement(void* userData, const char* nsName) std::string localname; std::string prefix; std::string nsUri; - splitNsName(localname, prefix, nsUri, nsName); + splitNsName(localname, prefix, nsUri, nsName, nsName+strlen(nsName)); SessionData* sd = reinterpret_cast(userData); std::string characters; diff --git a/src/FtpConnection.cc b/src/FtpConnection.cc index 9da2b730..9a2bbaa7 100644 --- a/src/FtpConnection.cc +++ b/src/FtpConnection.cc @@ -435,9 +435,9 @@ unsigned int FtpConnection::receiveSizeResponse(uint64_t& size) std::pair response; if(bulkReceiveResponse(response)) { if(response.first == 213) { - std::pair rp; - util::divide(rp, response.second, ' '); - size = util::parseULLInt(rp.second.begin(), rp.second.end()); + std::pair rp; + util::divide(rp, response.second.begin(), response.second.end(), ' '); + size = util::parseULLInt(rp.second.first, rp.second.second); } return response.first; } else { diff --git a/src/HttpResponse.cc b/src/HttpResponse.cc index 993f2604..460227b4 100644 --- a/src/HttpResponse.cc +++ b/src/HttpResponse.cc @@ -249,9 +249,10 @@ std::string HttpResponse::getContentType() const if(!httpHeader_) { return A2STR::NIL; } else { - std::pair p; - util::divide(p, httpHeader_->getFirst(HttpHeader::CONTENT_TYPE), ';'); - return p.first; + const std::string& ctype = httpHeader_->getFirst(HttpHeader::CONTENT_TYPE); + std::string::const_iterator i = std::find(ctype.begin(), ctype.end(), ';'); + Scip p = util::stripIter(ctype.begin(), i); + return std::string(p.first, p.second); } } diff --git a/src/HttpServer.cc b/src/HttpServer.cc index 9d3eaaa7..67116c32 100644 --- a/src/HttpServer.cc +++ b/src/HttpServer.cc @@ -203,19 +203,26 @@ bool HttpServer::authenticate() return true; } - std::string authHeader = lastRequestHeader_->getFirst("Authorization"); + const std::string& authHeader = lastRequestHeader_->getFirst("Authorization"); if(authHeader.empty()) { return false; } - std::pair p; - util::divide(p, authHeader, ' '); - if(p.first != "Basic") { + std::pair p; + util::divide(p, authHeader.begin(), authHeader.end(), ' '); + const char authMethod[] = "Basic"; + if(!std::distance(p.first.first, p.first.second) == sizeof(authMethod) || + !std::equal(p.first.first, p.first.second, &authMethod[0])) { return false; } - std::string userpass = Base64::decode(p.second); - std::pair userpassPair; - util::divide(userpassPair, userpass, ':'); - return username_ == userpassPair.first && password_ == userpassPair.second; + std::string userpass = Base64::decode(std::string(p.second.first, + p.second.second)); + util::divide(p, userpass.begin(), userpass.end(), ':'); + return username_.size() == + static_cast(std::distance(p.first.first, p.first.second)) && + std::equal(username_.begin(), username_.end(), p.first.first) && + password_.size() == + static_cast(std::distance(p.second.first, p.second.second)) && + std::equal(password_.begin(), password_.end(), p.second.first); } void HttpServer::setUsernamePassword diff --git a/src/OptionHandlerImpl.cc b/src/OptionHandlerImpl.cc index f7a7991e..4fdc5e35 100644 --- a/src/OptionHandlerImpl.cc +++ b/src/OptionHandlerImpl.cc @@ -365,11 +365,13 @@ ChecksumOptionHandler::~ChecksumOptionHandler() {} void ChecksumOptionHandler::parseArg(Option& option, const std::string& optarg) { - std::pair p; - util::divide(p, optarg, '='); - util::lowercase(p.first); - util::lowercase(p.second); - if(!MessageDigest::isValidHash(p.first, p.second)) { + std::pair p; + util::divide(p, optarg.begin(), optarg.end(), '='); + std::string hashType(p.first.first, p.first.second); + std::string hexDigest(p.second.first, p.second.second); + util::lowercase(hashType); + util::lowercase(hexDigest); + if(!MessageDigest::isValidHash(hashType, hexDigest)) { throw DL_ABORT_EX(_("Unrecognized checksum")); } option.put(pref_, optarg); diff --git a/src/OptionParser.cc b/src/OptionParser.cc index bd7551c1..08a4301e 100644 --- a/src/OptionParser.cc +++ b/src/OptionParser.cc @@ -184,14 +184,15 @@ void OptionParser::parse(Option& option, std::istream& is) const if(util::startsWith(line, A2STR::SHARP_C)) { continue; } - std::pair nv; - util::divide(nv, line, '='); - if(nv.first.empty()) { + std::pair nv; + util::divide(nv, line.begin(), line.end(), '='); + if(nv.first.first == nv.first.second) { continue; } - const SharedHandle& handler = find(option::k2p(nv.first)); + const SharedHandle& handler = + find(option::k2p(std::string(nv.first.first, nv.first.second))); if(handler) { - handler->parse(option, nv.second); + handler->parse(option, std::string(nv.second.first, nv.second.second)); } } } diff --git a/src/ParameterizedStringParser.cc b/src/ParameterizedStringParser.cc index d40a289a..72e31566 100644 --- a/src/ParameterizedStringParser.cc +++ b/src/ParameterizedStringParser.cc @@ -124,26 +124,29 @@ ParameterizedStringParser::createLoop(const std::string& src, int& offset) } loopStr.erase(colonIndex); } - std::pair range; - util::divide(range, loopStr, '-'); - if(range.first.empty() || range.second.empty()) { + std::pair range; + util::divide(range, loopStr.begin(), loopStr.end(), '-'); + if(range.first.first == range.first.second || + range.second.first == range.second.second) { throw DL_ABORT_EX("Loop range missing."); } SharedHandle nd; unsigned int start; unsigned int end; - if(util::isNumber(range.first) && util::isNumber(range.second)) { - nd.reset(new FixedWidthNumberDecorator(range.first.size())); - start = util::parseUInt(range.first.begin(), range.first.end()); - end = util::parseUInt(range.second.begin(), range.second.end()); - } else if(util::isLowercase(range.first) && util::isLowercase(range.second)) { - nd.reset(new AlphaNumberDecorator(range.first.size())); - start = util::alphaToNum(range.first); - end = util::alphaToNum(range.second); - } else if(util::isUppercase(range.first) && util::isUppercase(range.second)) { - nd.reset(new AlphaNumberDecorator(range.first.size(), true)); - start = util::alphaToNum(range.first); - end = util::alphaToNum(range.second); + std::string rstart(range.first.first, range.first.second); + std::string rend(range.second.first, range.second.second); + if(util::isNumber(rstart) && util::isNumber(rend)) { + nd.reset(new FixedWidthNumberDecorator(rstart.size())); + start = util::parseUInt(rstart.begin(), rstart.end()); + end = util::parseUInt(rend.begin(), rend.end()); + } else if(util::isLowercase(rstart) && util::isLowercase(rend)) { + nd.reset(new AlphaNumberDecorator(rstart.size())); + start = util::alphaToNum(rstart); + end = util::alphaToNum(rend); + } else if(util::isUppercase(rstart) && util::isUppercase(rend)) { + nd.reset(new AlphaNumberDecorator(rstart.size(), true)); + start = util::alphaToNum(rstart); + end = util::alphaToNum(rend); } else { throw DL_ABORT_EX("Invalid loop range."); } diff --git a/src/RpcMethodImpl.cc b/src/RpcMethodImpl.cc index ba1939c5..ac709670 100644 --- a/src/RpcMethodImpl.cc +++ b/src/RpcMethodImpl.cc @@ -1126,11 +1126,14 @@ void changeOption const SharedHandle