mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-26 17:16:20 +00:00
Changed: New join function to do the opposite work of explode
--HG-- branch : develop
This commit is contained in:
parent
501e1d9d27
commit
d7182af399
1 changed files with 16 additions and 0 deletions
|
@ -478,6 +478,22 @@ template <class T> void explode (const T &src, const T &sep, std::vector<T> &res
|
|||
while(pos != std::string::npos);
|
||||
}
|
||||
|
||||
/** Join a string (or ucstring) from a vector of strings with *sep* as separator. If sep can be more than 1 char, in this case,
|
||||
* we find the entire sep to separator (it s not a set of possible separator)
|
||||
*/
|
||||
template <class T, class U> void join(const std::vector<T>& strings, const U& separator, T &res)
|
||||
{
|
||||
res.clear();
|
||||
|
||||
for (uint i = 0, len = strings.size(); i<len; ++i)
|
||||
{
|
||||
// add in separators before all but the first string
|
||||
if (!res.empty()) res += separator;
|
||||
|
||||
// append next string
|
||||
res += strings[i];
|
||||
}
|
||||
}
|
||||
|
||||
/* All the code above is used to add our types (uint8, ...) in the stringstream (used by the toString() function).
|
||||
* So we can use stringstream operator << and >> with all NeL simple types (except for ucchar and ucstring)
|
||||
|
|
Loading…
Reference in a new issue