2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Use util::strip() instead of util::trim()
	* src/ExpatXmlRpcRequestProcessor.cc
	* src/FeatureConfig.cc
	* src/HttpHeader.cc
	* src/MetalinkParserStateV3Impl.cc
	* src/OptionHandlerImpl.h
	* src/ServerStatMan.cc
	* src/UriListParser.cc
	* src/Xml2XmlRpcRequestProcessor.cc
	* src/bittorrent_helper.cc
	* src/cookie_helper.cc
	* src/messageDigest.cc
	* src/util.cc
	* src/util.h
	* test/FeatureConfigTest.cc
	* test/HttpRequestTest.cc
	* test/UriListParserTest.cc
	* test/UtilTest.cc
pull/1/head
Tatsuhiro Tsujikawa 2010-10-09 16:49:02 +00:00
parent dbea00fa9d
commit 1505671e7b
18 changed files with 79 additions and 104 deletions

View File

@ -1,3 +1,24 @@
2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Use util::strip() instead of util::trim()
* src/ExpatXmlRpcRequestProcessor.cc
* src/FeatureConfig.cc
* src/HttpHeader.cc
* src/MetalinkParserStateV3Impl.cc
* src/OptionHandlerImpl.h
* src/ServerStatMan.cc
* src/UriListParser.cc
* src/Xml2XmlRpcRequestProcessor.cc
* src/bittorrent_helper.cc
* src/cookie_helper.cc
* src/messageDigest.cc
* src/util.cc
* src/util.h
* test/FeatureConfigTest.cc
* test/HttpRequestTest.cc
* test/UriListParserTest.cc
* test/UtilTest.cc
2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net> 2010-10-10 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added util::strip() Added util::strip()

View File

@ -69,7 +69,7 @@ static void mlStartElement(void* userData, const char* name, const char** attrs)
if(*p == 0) { if(*p == 0) {
break; break;
} }
std::string value = util::trim(*p++); std::string value = util::strip(*p++);
attrmap[name] = value; attrmap[name] = value;
} }
} }
@ -84,7 +84,7 @@ static void mlEndElement(void* userData, const char* name)
SessionData* sd = reinterpret_cast<SessionData*>(userData); SessionData* sd = reinterpret_cast<SessionData*>(userData);
std::string characters; std::string characters;
if(sd->stm_->needsCharactersBuffering()) { if(sd->stm_->needsCharactersBuffering()) {
characters = util::trim(sd->charactersStack_.top()); characters = util::strip(sd->charactersStack_.top());
sd->charactersStack_.pop(); sd->charactersStack_.pop();
} }
sd->stm_->endElement(name, characters); sd->stm_->endElement(name, characters);

View File

@ -158,7 +158,7 @@ std::string FeatureConfig::featureSummary() const
s += ", "; s += ", ";
} }
} }
return util::trim(s, ", "); return util::strip(s, ", ");
} }
} // namespace aria2 } // namespace aria2

View File

@ -214,7 +214,7 @@ void HttpHeader::fill(std::istream& in)
{ {
std::string line; std::string line;
while(std::getline(in, line)) { while(std::getline(in, line)) {
line = util::trim(line); line = util::strip(line);
if(line.empty()) { if(line.empty()) {
continue; continue;
} }

View File

@ -113,7 +113,7 @@ void FilesMetalinkParserState::beginElement
stm->setFileState(); stm->setFileState();
std::vector<XmlAttr>::const_iterator itr = findAttr(attrs, NAME); std::vector<XmlAttr>::const_iterator itr = findAttr(attrs, NAME);
if(itr != attrs.end()) { if(itr != attrs.end()) {
std::string name = util::trim((*itr).value); std::string name = util::strip((*itr).value);
if(name.empty() || util::detectDirTraversal(name)) { if(name.empty() || util::detectDirTraversal(name)) {
return; return;
} }
@ -196,7 +196,7 @@ void VersionMetalinkParserState::endElement
const std::string& nsUri, const std::string& nsUri,
const std::string& characters) const std::string& characters)
{ {
stm->setVersionOfEntry(util::trim(characters)); stm->setVersionOfEntry(util::strip(characters));
} }
void LanguageMetalinkParserState::endElement void LanguageMetalinkParserState::endElement
@ -206,7 +206,7 @@ void LanguageMetalinkParserState::endElement
const std::string& nsUri, const std::string& nsUri,
const std::string& characters) const std::string& characters)
{ {
stm->setLanguageOfEntry(util::trim(characters)); stm->setLanguageOfEntry(util::strip(characters));
} }
void OSMetalinkParserState::endElement void OSMetalinkParserState::endElement
@ -216,7 +216,7 @@ void OSMetalinkParserState::endElement
const std::string& nsUri, const std::string& nsUri,
const std::string& characters) const std::string& characters)
{ {
stm->setOSOfEntry(util::trim(characters)); stm->setOSOfEntry(util::strip(characters));
} }
void VerificationMetalinkParserState::beginElement void VerificationMetalinkParserState::beginElement
@ -236,7 +236,7 @@ void VerificationMetalinkParserState::beginElement
if(itr == attrs.end()) { if(itr == attrs.end()) {
return; return;
} else { } else {
std::string type = util::trim((*itr).value); std::string type = util::strip((*itr).value);
stm->newChecksumTransaction(); stm->newChecksumTransaction();
stm->setTypeOfChecksum(type); stm->setTypeOfChecksum(type);
} }
@ -258,7 +258,7 @@ void VerificationMetalinkParserState::beginElement
if(itr == attrs.end()) { if(itr == attrs.end()) {
return; return;
} else { } else {
type = util::trim((*itr).value); type = util::strip((*itr).value);
} }
} }
stm->newChunkChecksumTransaction(); stm->newChunkChecksumTransaction();
@ -276,10 +276,10 @@ void VerificationMetalinkParserState::beginElement
return; return;
} else { } else {
stm->newSignatureTransaction(); stm->newSignatureTransaction();
stm->setTypeOfSignature(util::trim((*itr).value)); stm->setTypeOfSignature(util::strip((*itr).value));
std::vector<XmlAttr>::const_iterator itr = findAttr(attrs, FILE); std::vector<XmlAttr>::const_iterator itr = findAttr(attrs, FILE);
if(itr != attrs.end()) { if(itr != attrs.end()) {
std::string file = util::trim((*itr).value); std::string file = util::strip((*itr).value);
if(!util::detectDirTraversal(file)) { if(!util::detectDirTraversal(file)) {
stm->setFileOfSignature(file); stm->setFileOfSignature(file);
} }
@ -297,7 +297,7 @@ void HashMetalinkParserState::endElement
const std::string& nsUri, const std::string& nsUri,
const std::string& characters) const std::string& characters)
{ {
stm->setHashOfChecksum(util::trim(characters)); stm->setHashOfChecksum(util::strip(characters));
stm->commitChecksumTransaction(); stm->commitChecksumTransaction();
} }
@ -342,7 +342,7 @@ void PieceHashMetalinkParserState::endElement
const std::string& nsUri, const std::string& nsUri,
const std::string& characters) const std::string& characters)
{ {
stm->setMessageDigestOfChunkChecksum(util::trim(characters)); stm->setMessageDigestOfChunkChecksum(util::strip(characters));
stm->addHashOfChunkChecksum(); stm->addHashOfChunkChecksum();
} }
@ -353,7 +353,7 @@ void SignatureMetalinkParserState::endElement
const std::string& nsUri, const std::string& nsUri,
const std::string& characters) const std::string& characters)
{ {
stm->setBodyOfSignature(util::trim(characters)); stm->setBodyOfSignature(util::strip(characters));
stm->commitSignatureTransaction(); stm->commitSignatureTransaction();
} }
@ -374,14 +374,14 @@ void ResourcesMetalinkParserState::beginElement
if(itr == attrs.end()) { if(itr == attrs.end()) {
return; return;
} else { } else {
type = util::trim((*itr).value); type = util::strip((*itr).value);
} }
} }
std::string location; std::string location;
{ {
std::vector<XmlAttr>::const_iterator itr = findAttr(attrs, LOCATION); std::vector<XmlAttr>::const_iterator itr = findAttr(attrs, LOCATION);
if(itr != attrs.end()) { if(itr != attrs.end()) {
location = util::trim((*itr).value); location = util::strip((*itr).value);
} }
} }
int preference; int preference;
@ -430,7 +430,7 @@ void URLMetalinkParserState::endElement
const std::string& nsUri, const std::string& nsUri,
const std::string& characters) const std::string& characters)
{ {
stm->setURLOfResource(util::trim(characters)); stm->setURLOfResource(util::strip(characters));
stm->commitResourceTransaction(); stm->commitResourceTransaction();
} }

View File

@ -497,7 +497,7 @@ public:
std::stringstream s; std::stringstream s;
std::copy(validParamValues_.begin(), validParamValues_.end(), std::copy(validParamValues_.begin(), validParamValues_.end(),
std::ostream_iterator<std::string>(s, ",")); std::ostream_iterator<std::string>(s, ","));
return util::trim(s.str(), ", "); return util::strip(s.str(), ", ");
} }
}; };

View File

@ -98,7 +98,7 @@ bool ServerStatMan::load(std::istream& in)
std::string line; std::string line;
while(getline(in, line)) { while(getline(in, line)) {
util::trimSelf(line); line = util::strip(line);
if(line.empty()) { if(line.empty()) {
continue; continue;
} }
@ -108,8 +108,8 @@ bool ServerStatMan::load(std::istream& in)
for(std::vector<std::string>::const_iterator i = items.begin(), for(std::vector<std::string>::const_iterator i = items.begin(),
eoi = items.end(); i != eoi; ++i) { eoi = items.end(); i != eoi; ++i) {
std::pair<std::string, std::string> p = util::split(*i, "="); std::pair<std::string, std::string> p = util::split(*i, "=");
util::trimSelf(p.first); p.first = util::strip(p.first);
util::trimSelf(p.second); p.second = util::strip(p.second);
m[p.first] = p.second; m[p.first] = p.second;
} }
if(m[S_HOST].empty() || m[S_PROTOCOL].empty()) { if(m[S_HOST].empty() || m[S_PROTOCOL].empty()) {

View File

@ -76,7 +76,7 @@ void UriListParser::parseNext(std::vector<std::string>& uris, Option& op)
return; return;
} }
do { do {
if(!util::startsWith(line_, A2STR::SHARP_C) && !util::trim(line_).empty()) { if(!util::startsWith(line_, A2STR::SHARP_C) && !util::strip(line_).empty()){
util::split(line_, std::back_inserter(uris), "\t", true); util::split(line_, std::back_inserter(uris), "\t", true);
getOptions(op); getOptions(op);
return; return;

View File

@ -70,7 +70,7 @@ static void mlStartElement(void* userData, const xmlChar* name,
if(*p == 0) { if(*p == 0) {
break; break;
} }
std::string value = util::trim(reinterpret_cast<const char*>(*p)); std::string value = util::strip(reinterpret_cast<const char*>(*p));
++p; ++p;
attrmap[name] = value; attrmap[name] = value;
} }
@ -86,7 +86,7 @@ static void mlEndElement(void* userData, const xmlChar* name)
SessionData* sd = reinterpret_cast<SessionData*>(userData); SessionData* sd = reinterpret_cast<SessionData*>(userData);
std::string characters; std::string characters;
if(sd->stm_->needsCharactersBuffering()) { if(sd->stm_->needsCharactersBuffering()) {
characters = util::trim(sd->charactersStack_.top()); characters = util::strip(sd->charactersStack_.top());
sd->charactersStack_.pop(); sd->charactersStack_.pop();
} }
sd->stm_->endElement(reinterpret_cast<const char*>(name), characters); sd->stm_->endElement(reinterpret_cast<const char*>(name), characters);

View File

@ -325,7 +325,7 @@ static void extractAnnounce
eoi2 = tier->end(); uriIter != eoi2; ++uriIter) { eoi2 = tier->end(); uriIter != eoi2; ++uriIter) {
const String* uri = asString(*uriIter); const String* uri = asString(*uriIter);
if(uri) { if(uri) {
ntier.push_back(util::trim(uri->s())); ntier.push_back(util::strip(uri->s()));
} }
} }
if(!ntier.empty()) { if(!ntier.empty()) {
@ -336,7 +336,7 @@ static void extractAnnounce
const String* announce = asString(rootDict->get(C_ANNOUNCE)); const String* announce = asString(rootDict->get(C_ANNOUNCE));
if(announce) { if(announce) {
std::vector<std::string> tier; std::vector<std::string> tier;
tier.push_back(util::trim(announce->s())); tier.push_back(util::strip(announce->s()));
torrent->announceList.push_back(tier); torrent->announceList.push_back(tier);
} }
} }
@ -357,7 +357,7 @@ static void extractNodes
if(!hostname) { if(!hostname) {
continue; continue;
} }
if(util::trim(hostname->s()).empty()) { if(util::strip(hostname->s()).empty()) {
continue; continue;
} }
const Integer* port = asInteger(addrPairList->get(1)); const Integer* port = asInteger(addrPairList->get(1));

View File

@ -204,11 +204,11 @@ bool parse
if(eq == nvEnd) { if(eq == nvEnd) {
return false; return false;
} }
std::string cookieName = util::trim(std::string(cookieStr.begin(), eq)); std::string cookieName = util::stripIter(cookieStr.begin(), eq);
if(cookieName.empty()) { if(cookieName.empty()) {
return false; return false;
} }
std::string cookieValue = util::trim(std::string(eq+1, nvEnd)); std::string cookieValue = util::stripIter(eq+1, nvEnd);
time_t expiryTime = 0; time_t expiryTime = 0;
bool foundExpires = false; bool foundExpires = false;
bool persistent = false; bool persistent = false;
@ -225,10 +225,10 @@ bool parse
for(; j != end && *j != ';'; ++j); for(; j != end && *j != ';'; ++j);
std::string::const_iterator eq = i; std::string::const_iterator eq = i;
for(; eq != j && *eq != '='; ++eq); for(; eq != j && *eq != '='; ++eq);
std::string attrName = util::toLower(util::trim(std::string(i, eq))); std::string attrName = util::toLower(util::stripIter(i, eq));
std::string attrValue; std::string attrValue;
if(eq != j) { if(eq != j) {
attrValue = util::trim(std::string(eq+1, j)); attrValue = util::stripIter(eq+1, j);
} }
i = j; i = j;
if(j != end) { if(j != end) {

View File

@ -144,7 +144,7 @@ std::string MessageDigestContext::getSupportedAlgoString()
algos += (*itr).first; algos += (*itr).first;
algos += ", "; algos += ", ";
} }
return util::trim(algos, ", "); return util::strip(algos, ", ");
} }
bool MessageDigestContext::isStronger bool MessageDigestContext::isStronger

View File

@ -92,26 +92,7 @@ namespace aria2 {
namespace util { namespace util {
const std::string DEFAULT_TRIM_CHARSET("\r\n\t "); const std::string DEFAULT_STRIP_CHARSET("\r\n\t ");
std::string trim(const std::string& src, const std::string& trimCharset)
{
std::string temp(src);
trimSelf(temp, trimCharset);
return temp;
}
void trimSelf(std::string& str, const std::string& trimCharset)
{
std::string::size_type first = str.find_first_not_of(trimCharset);
if(first == std::string::npos) {
str.clear();
} else {
std::string::size_type last = str.find_last_not_of(trimCharset)+1;
str.erase(last);
str.erase(0, first);
}
}
std::string strip(const std::string& str, const std::string& chars) std::string strip(const std::string& str, const std::string& chars)
{ {
@ -124,11 +105,11 @@ void split(std::pair<std::string, std::string>& hp, const std::string& src, char
hp.second = A2STR::NIL; hp.second = A2STR::NIL;
std::string::size_type p = src.find(delim); std::string::size_type p = src.find(delim);
if(p == std::string::npos) { if(p == std::string::npos) {
hp.first = trim(src); hp.first = strip(src);
hp.second = A2STR::NIL; hp.second = A2STR::NIL;
} else { } else {
hp.first = trim(src.substr(0, p)); hp.first = strip(src.substr(0, p));
hp.second = trim(src.substr(p+1)); hp.second = strip(src.substr(p+1));
} }
} }
@ -139,11 +120,11 @@ std::pair<std::string, std::string> split(const std::string& src, const std::str
hp.second = A2STR::NIL; hp.second = A2STR::NIL;
std::string::size_type p = src.find_first_of(delims); std::string::size_type p = src.find_first_of(delims);
if(p == std::string::npos) { if(p == std::string::npos) {
hp.first = trim(src); hp.first = strip(src);
hp.second = A2STR::NIL; hp.second = A2STR::NIL;
} else { } else {
hp.first = trim(src.substr(0, p)); hp.first = strip(src.substr(0, p));
hp.second = trim(src.substr(p+1)); hp.second = strip(src.substr(p+1));
} }
return hp; return hp;
} }
@ -555,7 +536,8 @@ uint32_t parseUInt(const std::string& s, int base)
bool parseUIntNoThrow(uint32_t& result, const std::string& s, int base) bool parseUIntNoThrow(uint32_t& result, const std::string& s, int base)
{ {
std::string trimed = trim(s); // TODO what happens when we don't trim s?
std::string trimed = strip(s);
if(trimed.empty()) { if(trimed.empty()) {
return false; return false;
} }
@ -577,7 +559,7 @@ bool parseUIntNoThrow(uint32_t& result, const std::string& s, int base)
int64_t parseLLInt(const std::string& s, int32_t base) int64_t parseLLInt(const std::string& s, int32_t base)
{ {
std::string trimed = trim(s); std::string trimed = strip(s);
if(trimed.empty()) { if(trimed.empty()) {
throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE, throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
"empty string").str()); "empty string").str());
@ -597,7 +579,7 @@ int64_t parseLLInt(const std::string& s, int32_t base)
bool parseLLIntNoThrow(int64_t& result, const std::string& s, int base) bool parseLLIntNoThrow(int64_t& result, const std::string& s, int base)
{ {
std::string trimed = trim(s); std::string trimed = strip(s);
if(trimed.empty()) { if(trimed.empty()) {
return false; return false;
} }
@ -615,7 +597,7 @@ bool parseLLIntNoThrow(int64_t& result, const std::string& s, int base)
uint64_t parseULLInt(const std::string& s, int base) uint64_t parseULLInt(const std::string& s, int base)
{ {
std::string trimed = trim(s); std::string trimed = strip(s);
if(trimed.empty()) { if(trimed.empty()) {
throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE, throw DL_ABORT_EX(StringFormat(MSG_STRING_INTEGER_CONVERSION_FAILURE,
"empty string").str()); "empty string").str());
@ -800,7 +782,7 @@ static void parseParam(OutputIterator out, const std::string& header)
param = std::string(paramFirst, paramLast); param = std::string(paramFirst, paramLast);
} }
} }
trimSelf(param); param = strip(param);
*out++ = param; *out++ = param;
if(paramLast == eoi) { if(paramLast == eoi) {
break; break;
@ -910,7 +892,7 @@ std::string getContentDispositionFilename(const std::string& header)
} }
static const std::string TRIMMED("\r\n\t '\""); static const std::string TRIMMED("\r\n\t '\"");
value = percentDecode(std::string(value.begin(), filenameLast)); value = percentDecode(std::string(value.begin(), filenameLast));
trimSelf(value, TRIMMED); value = strip(value, TRIMMED);
value.erase(std::remove(value.begin(), value.end(), '\\'), value.end()); value.erase(std::remove(value.begin(), value.end(), '\\'), value.end());
if(!detectDirTraversal(value) && if(!detectDirTraversal(value) &&
value.find(A2STR::SLASH_C) == std::string::npos) { value.find(A2STR::SLASH_C) == std::string::npos) {

View File

@ -126,18 +126,12 @@ std::string itos(int64_t value, bool comma = false);
int64_t difftv(struct timeval tv1, struct timeval tv2); int64_t difftv(struct timeval tv1, struct timeval tv2);
int32_t difftvsec(struct timeval tv1, struct timeval tv2); int32_t difftvsec(struct timeval tv1, struct timeval tv2);
extern const std::string DEFAULT_TRIM_CHARSET; extern const std::string DEFAULT_STRIP_CHARSET;
std::string trim(const std::string& src,
const std::string& trimCharset = DEFAULT_TRIM_CHARSET);
void trimSelf(std::string& str,
const std::string& trimCharset = DEFAULT_TRIM_CHARSET);
template<typename InputIterator> template<typename InputIterator>
std::string stripIter std::string stripIter
(InputIterator first, InputIterator last, (InputIterator first, InputIterator last,
const std::string& chars = DEFAULT_TRIM_CHARSET) const std::string& chars = DEFAULT_STRIP_CHARSET)
{ {
if(std::distance(first, last) == 0) { if(std::distance(first, last) == 0) {
return A2STR::NIL; return A2STR::NIL;
@ -154,7 +148,7 @@ std::string stripIter
} }
std::string strip std::string strip
(const std::string& str, const std::string& chars = DEFAULT_TRIM_CHARSET); (const std::string& str, const std::string& chars = DEFAULT_STRIP_CHARSET);
bool startsWith(const std::string& target, const std::string& part); bool startsWith(const std::string& target, const std::string& part);
@ -340,7 +334,7 @@ std::map<size_t, std::string> createIndexPathMap(std::istream& i);
*/ */
template<typename OutputIterator> template<typename OutputIterator>
OutputIterator split(const std::string& src, OutputIterator out, OutputIterator split(const std::string& src, OutputIterator out,
const std::string& delims, bool doTrim = false, const std::string& delims, bool doStrip = false,
bool allowEmpty = false) bool allowEmpty = false)
{ {
std::string::size_type p = 0; std::string::size_type p = 0;
@ -348,8 +342,8 @@ OutputIterator split(const std::string& src, OutputIterator out,
std::string::size_type np = src.find_first_of(delims, p); std::string::size_type np = src.find_first_of(delims, p);
if(np == std::string::npos) { if(np == std::string::npos) {
std::string term = src.substr(p); std::string term = src.substr(p);
if(doTrim) { if(doStrip) {
term = util::trim(term); term = util::strip(term);
} }
if(allowEmpty || !term.empty()) { if(allowEmpty || !term.empty()) {
*out = term; *out = term;
@ -358,8 +352,8 @@ OutputIterator split(const std::string& src, OutputIterator out,
break; break;
} }
std::string term = src.substr(p, np-p); std::string term = src.substr(p, np-p);
if(doTrim) { if(doStrip) {
term = util::trim(term); term = util::strip(term);
} }
p = np+1; p = np+1;
if(allowEmpty || !term.empty()) { if(allowEmpty || !term.empty()) {

View File

@ -91,8 +91,7 @@ void FeatureConfigTest::testFeatureSummary() {
const std::string delim(", "); const std::string delim(", ");
std::for_each(vbegin(features), vend(features), std::for_each(vbegin(features), vend(features),
StringAppend(featuresString, delim)); StringAppend(featuresString, delim));
// USE util::trimSelf(featureString); featuresString = util::strip(featuresString, delim);
featuresString = util::trim(featuresString, delim);
CPPUNIT_ASSERT_EQUAL(featuresString, CPPUNIT_ASSERT_EQUAL(featuresString,
FeatureConfig::getInstance()->featureSummary()); FeatureConfig::getInstance()->featureSummary());

View File

@ -524,7 +524,7 @@ void HttpRequestTest::testCreateRequest_head()
std::stringstream result(httpRequest.createRequest()); std::stringstream result(httpRequest.createRequest());
std::string line; std::string line;
CPPUNIT_ASSERT(getline(result, line)); CPPUNIT_ASSERT(getline(result, line));
util::trimSelf(line); line = util::strip(line);
CPPUNIT_ASSERT_EQUAL(std::string("HEAD /aria2-1.0.0.tar.bz2 HTTP/1.1"), line); CPPUNIT_ASSERT_EQUAL(std::string("HEAD /aria2-1.0.0.tar.bz2 HTTP/1.1"), line);
} }

View File

@ -36,7 +36,7 @@ std::string UriListParserTest::list2String(const std::vector<std::string>& src)
{ {
std::ostringstream strm; std::ostringstream strm;
std::copy(src.begin(), src.end(), std::ostream_iterator<std::string>(strm, " ")); std::copy(src.begin(), src.end(), std::ostream_iterator<std::string>(strm, " "));
return util::trim(strm.str()); return util::strip(strm.str());
} }
void UriListParserTest::testHasNext() void UriListParserTest::testHasNext()

View File

@ -19,7 +19,6 @@ namespace aria2 {
class UtilTest:public CppUnit::TestFixture { class UtilTest:public CppUnit::TestFixture {
CPPUNIT_TEST_SUITE(UtilTest); CPPUNIT_TEST_SUITE(UtilTest);
CPPUNIT_TEST(testTrim);
CPPUNIT_TEST(testStrip); CPPUNIT_TEST(testStrip);
CPPUNIT_TEST(testSplit); CPPUNIT_TEST(testSplit);
CPPUNIT_TEST(testSplit_many); CPPUNIT_TEST(testSplit_many);
@ -74,7 +73,6 @@ public:
void setUp() { void setUp() {
} }
void testTrim();
void testStrip(); void testStrip();
void testSplit(); void testSplit();
void testSplit_many(); void testSplit_many();
@ -127,25 +125,6 @@ public:
CPPUNIT_TEST_SUITE_REGISTRATION( UtilTest ); CPPUNIT_TEST_SUITE_REGISTRATION( UtilTest );
void UtilTest::testTrim() {
std::string str1 = "aria2";
CPPUNIT_ASSERT_EQUAL(str1, util::trim("aria2"));
CPPUNIT_ASSERT_EQUAL(str1, util::trim(" aria2"));
CPPUNIT_ASSERT_EQUAL(str1, util::trim(" aria2 "));
CPPUNIT_ASSERT_EQUAL(str1, util::trim(" aria2 "));
std::string str2 = "aria2 debut";
CPPUNIT_ASSERT_EQUAL(str2, util::trim("aria2 debut"));
CPPUNIT_ASSERT_EQUAL(str2, util::trim(" aria2 debut "));
std::string str3 = "";
CPPUNIT_ASSERT_EQUAL(str3, util::trim(""));
CPPUNIT_ASSERT_EQUAL(str3, util::trim(" "));
CPPUNIT_ASSERT_EQUAL(str3, util::trim(" "));
std::string str4 = "A";
CPPUNIT_ASSERT_EQUAL(str4, util::trim("A"));
CPPUNIT_ASSERT_EQUAL(str4, util::trim(" A "));
CPPUNIT_ASSERT_EQUAL(str4, util::trim(" A "));
}
void UtilTest::testStrip() void UtilTest::testStrip()
{ {
std::string str1 = "aria2"; std::string str1 = "aria2";