Added join in zelda::utility

This commit is contained in:
Antidote 2014-01-18 20:01:31 -08:00 committed by Antidote
parent 3c737226ba
commit aa5c37856f
2 changed files with 12 additions and 2 deletions

View File

@ -1,4 +1,4 @@
// This file is part of libZelda. // This file is part of libZelda.
// //
// libZelda is free software: you can redistribute it and/or modify // libZelda is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -42,6 +42,7 @@ bool isSystemBigEndian();
void fillRandom(Uint8 * rndArea, Uint8 count); void fillRandom(Uint8 * rndArea, Uint8 count);
std::vector<std::string> split(const std::string &s, char delim); std::vector<std::string> split(const std::string &s, char delim);
std::string join(const std::vector<std::string>& elems, const std::string& delims);
void tolower(std::string& str); void tolower(std::string& str);
void toupper(std::string& str); void toupper(std::string& str);
std::string sprintf(const char* fmt, ...); std::string sprintf(const char* fmt, ...);

View File

@ -1,4 +1,4 @@
// This file is part of libZelda. // This file is part of libZelda.
// //
// libZelda is free software: you can redistribute it and/or modify // libZelda is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by // it under the terms of the GNU General Public License as published by
@ -20,6 +20,7 @@
#include <sstream> #include <sstream>
#include <algorithm> #include <algorithm>
#include <cstdarg> #include <cstdarg>
#include <iterator>
namespace zelda namespace zelda
{ {
@ -132,6 +133,14 @@ std::vector<std::string> split(const std::string &s, char delim)
return elems; return elems;
} }
std::string join(const std::vector<std::string>& elems, const std::string& delims)
{
std::ostringstream ret;
std::copy(elems.begin(), elems.end(), std::ostream_iterator<std::string>(ret, delims.c_str()));
return ret.str();
}
void tolower(std::string& str) void tolower(std::string& str)
{ {
std::transform(str.begin(), str.end(), str.begin(), ::tolower); std::transform(str.begin(), str.end(), str.begin(), ::tolower);