Skip to content

Instantly share code, notes, and snippets.

View NewbiZ's full-sized avatar
😎

Aurélien Vallée NewbiZ

😎
View GitHub Profile
@NewbiZ
NewbiZ / join_string.cpp
Created December 8, 2010 22:16
Join a container of strings into a single one, with a delimiter
namespace
{
struct add_delimiter
{
add_delimiter( const std::string& d )
{ delimiter = d; }
std::string operator()( const std::string& lhs, const std::string& rhs )
{ return lhs + (lhs.empty() ? "" : delimiter) + rhs; }
@NewbiZ
NewbiZ / chop_string.cpp
Created December 6, 2010 08:15
Chop trailing characters from a string
void chop( std::string& str, const std::string& whitespaces=" \t\f\v\n\r" )
{
size_t found = str.find_last_not_of( whitespaces );
if ( found!=std::string::npos )
str.erase( found+1 );
else
str.clear();
}
@NewbiZ
NewbiZ / split_string.cpp
Created December 6, 2010 08:12
Split a string using a delimiter
void split( const std::string& str, char delim, std::vector<std::string>& tokens )
{
std::stringstream iss(str);
std::string item;
while ( std::getline(iss, item, delim) )
{
if ( !item.empty() )
tokens.push_back(item);
}
}