Skip to content
Snippets Groups Projects
string.cpp 1.36 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jan Trávníček's avatar
    Jan Trávníček committed
     * string.cpp
    
     *
     * Created on: Apr 1, 2013
     * Author: Jan Travnicek
     */
    
    
    Jan Trávníček's avatar
    Jan Trávníček committed
    #include <string>
    
    #include <sstream>
    
    
    template < >
    
    std::string to_string ( const std::string & value ) {
    
    	return 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;
    }
    
    
    long from_string ( const std::string & value ) {
    	return std::stol__private ( value.c_str() );
    
    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() );
    
    unsigned long from_string ( const std::string & value ) {
    	return std::stoul__private ( value.c_str() );
    
    unsigned long long from_string ( const std::string & value ) {
    	return std::stoull__private ( value.c_str() );
    
    Jan Trávníček's avatar
    Jan Trávníček committed
    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;
    
    } /* namespace ext */