Add a stringVector join function for future use

This commit is contained in:
Isaac Connor 2014-11-05 14:01:48 -05:00
parent 4863ce96a3
commit a88ce80716
2 changed files with 13 additions and 0 deletions

View File

@ -126,6 +126,17 @@ StringVector split( const std::string &string, const std::string chars, int limi
return( stringVector ); return( stringVector );
} }
const std::string join(const StringVector v, const char * delim ) {
std::stringstream ss;
for(size_t i = 0; i < v.size(); ++i) {
if(i != 0)
ss << ",";
ss << v[i];
}
return ss.str();
}
const std::string base64Encode( const std::string &inString ) const std::string base64Encode( const std::string &inString )
{ {
static char base64_table[64] = { '\0' }; static char base64_table[64] = { '\0' };

View File

@ -23,6 +23,7 @@
#include <time.h> #include <time.h>
#include <sys/time.h> #include <sys/time.h>
#include <string> #include <string>
#include <sstream>
#include <vector> #include <vector>
typedef std::vector<std::string> StringVector; typedef std::vector<std::string> StringVector;
@ -36,6 +37,7 @@ const std::string stringtf( const std::string &format, ... );
bool startsWith( const std::string &haystack, const std::string &needle ); bool startsWith( const std::string &haystack, const std::string &needle );
StringVector split( const std::string &string, const std::string chars, int limit=0 ); StringVector split( const std::string &string, const std::string chars, int limit=0 );
const std::string join( const StringVector, const char * );
const std::string base64Encode( const std::string &inString ); const std::string base64Encode( const std::string &inString );