/* * string.cpp * * Created on: Apr 1, 2013 * Author: Jan Travnicek */ #include <string> #include <sstream> namespace ext { std::string to_string ( const std::string & value ) { return value; } std::string to_string ( int value ) { return std::to_string__private ( value ); } std::string to_string ( bool value ) { return std::to_string__private ( value ); } std::string to_string ( long value ) { return std::to_string__private ( value ); } std::string to_string ( long long value ) { return std::to_string__private ( value ); } std::string to_string ( unsigned value ) { return std::to_string__private ( value ); } std::string to_string ( unsigned long value ) { return std::to_string__private ( value ); } std::string to_string ( unsigned long long value ) { return std::to_string__private ( value ); } std::string to_string ( double value ) { return std::to_string__private ( value ); } template < > std::string from_string ( const std::string & value ) { return value; } template < > int from_string ( const std::string & value ) { return std::stoi__private ( value.c_str() ); } template < > bool from_string ( const std::string & value ) { if ( value == "true" || value == "1" ) return true; else return false; } template < > long from_string ( const std::string & value ) { return std::stol__private ( value.c_str() ); } template < > long long from_string ( const std::string & value ) { return std::stoll__private ( value.c_str() ); } template < > unsigned from_string ( const std::string & value ) { return std::stoul__private ( value.c_str() ); } template < > unsigned long from_string ( const std::string & value ) { return std::stoul__private ( value.c_str() ); } template < > unsigned long long from_string ( const std::string & value ) { return std::stoull__private ( value.c_str() ); } template < > double from_string ( const std::string & value ) { return std::stod__private ( value.c_str() ); } std::string cstringToString ( char * param ) { std::string res ( param ); free ( param ); return res; } ext::vector < std::string > explode ( std::string source, std::string delimiter ) { std::string part; ext::vector < std::string > res; size_t start_pos = 0; size_t end_pos; while ( ( end_pos = source.find ( delimiter, start_pos ) ) != std::string::npos ) { res.push_back ( source.substr ( start_pos, end_pos - start_pos ) ); start_pos = end_pos + delimiter.size ( ); } res.push_back ( source.substr ( start_pos, source.size ( ) ) ); return res; } } /* namespace ext */