mirror of https://github.com/aria2/aria2
2009-06-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Added strjoin function template. Use it in pathJoin() * src/Util.h * src/a2functional.hpull/1/head
parent
3bb2e3b07e
commit
a8c278d026
|
@ -1,3 +1,9 @@
|
||||||
|
2009-06-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
|
Added strjoin function template. Use it in pathJoin()
|
||||||
|
* src/Util.h
|
||||||
|
* src/a2functional.h
|
||||||
|
|
||||||
2009-06-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
2009-06-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||||
|
|
||||||
Avoid intermediate object during string concatenation. Replaced
|
Avoid intermediate object during string concatenation. Replaced
|
||||||
|
|
|
@ -299,11 +299,7 @@ public:
|
||||||
elements.push_back(*first);
|
elements.push_back(*first);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(elements.empty()) {
|
return strjoin(elements.begin(), elements.end(), "/");
|
||||||
return "";
|
|
||||||
}
|
|
||||||
return std::accumulate(elements.begin()+1, elements.end(), elements[0],
|
|
||||||
Concat("/"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parses INDEX=PATH format string. INDEX must be an unsigned
|
// Parses INDEX=PATH format string. INDEX must be an unsigned
|
||||||
|
|
|
@ -165,18 +165,6 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class Concat {
|
|
||||||
private:
|
|
||||||
std::string _delim;
|
|
||||||
public:
|
|
||||||
Concat(const std::string& delim = A2STR::NIL):_delim(delim) {}
|
|
||||||
|
|
||||||
std::string operator()(const std::string& s1, const std::string& s2) const
|
|
||||||
{
|
|
||||||
return s1+_delim+s2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
class Deleter {
|
class Deleter {
|
||||||
public:
|
public:
|
||||||
template<class T>
|
template<class T>
|
||||||
|
@ -216,6 +204,23 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename InputIterator, typename DelimiterType>
|
||||||
|
std::string strjoin(InputIterator first, InputIterator last,
|
||||||
|
const DelimiterType& delim)
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
if(first == last) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
InputIterator beforeLast = last-1;
|
||||||
|
for(; first != beforeLast; ++first) {
|
||||||
|
result += *first;
|
||||||
|
result += delim;
|
||||||
|
}
|
||||||
|
result += *beforeLast;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename T1, typename T2>
|
template<typename T1, typename T2>
|
||||||
inline std::string strconcat(const T1& a1, const T2& a2)
|
inline std::string strconcat(const T1& a1, const T2& a2)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue