Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages

StringUtils.hpp

Go to the documentation of this file.
00001 #ifndef StringUtils_HPP
00002 #define StringUtils_HPP
00003 
00004 #include <string>
00005 #include <sstream>
00006 
00007 using std::string;
00008 using std::istringstream;
00009 
00010   class StringUtils{
00011 
00012     public:
00013 
00014       //---------------------------------------------------------------------
00015       static void filterComments(string & str){
00016 
00017         unsigned int index = str.find_first_of('#');
00018         if (index != string::npos)
00019           str.erase(index, str.size() - index);
00020       }
00021 
00022       //---------------------------------------------------------------------
00023       //FIXME: It's better to use boost lexical-cast
00024       static int string2int(const string & str){
00025 
00026         istringstream iss(str);
00027         int result;
00028         iss >> result;
00029         return result;
00030 
00031       }
00032 
00033       //---------------------------------------------------------------------
00034       //FIXME: It's better to use boost lexical-cast
00035       static float string2float(const string & str){
00036 
00037         istringstream iss(str);
00038         float result;
00039         iss >> result;
00040         return result;
00041       }
00042 
00043       //---------------------------------------------------------------------
00044       //FIXME: It's better to use boost lexical-cast
00045       static string int2string(const int & i){
00046         stringstream sstr;
00047         sstr << i;
00048         return sstr.str();
00049       }
00050 
00051      //---------------------------------------------------------------------
00052      template<typename T> static  string num2String(const T & num){
00053        stringstream sstr;
00054        sstr << num;
00055        return sstr.str();
00056      }
00057 
00058      //---------------------------------------------------------------------
00059      static string stripPath(const string & path){
00060        string tmpFilePath = path;
00061        unsigned int lastSlashIndex = tmpFilePath.find_last_of('/');
00062        if(lastSlashIndex != string::npos)
00063          tmpFilePath = tmpFilePath.substr(lastSlashIndex + 1);
00064        return tmpFilePath;
00065      }
00066 
00067   };
00068 #endif//StringUtils_HPP
00069 

Generated on Mon Sep 6 16:12:48 2004 by doxygen 1.3.3