Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef STRING_HELPER_H
00021 #define STRING_HELPER_H
00022
00023 #include <stdlib.h>
00024 #include <vector>
00025 #include <iostream>
00026 #include <sstream>
00027 #include <string>
00028
00029
00030
00031 namespace cpe
00032 {
00033
00034
00035
00037
00039 class string_converter
00040 {
00041
00042
00043 public:
00044
00045
00051 template <typename T>
00052 static T value_of(const std::string& in,bool *is_ok=0)
00053 {
00054 T obj;
00055 std::istringstream is(in);
00056 bool _is_ok=bool(is>>obj);
00057 if(is_ok!=0)
00058 *is_ok=_is_ok;
00059 return obj;
00060 }
00061
00063 template <typename T>
00064 static std::vector <T> value_of(const std::vector <std::string>& in,bool *is_ok=0)
00065 {
00066
00067 if(is_ok!=0)
00068 *is_ok=true;
00069
00070 int N=in.size();
00071 std::vector <T> obj(N);
00072 bool temp_is_ok=true;
00073 for(int k=0;k<N;++k)
00074 {
00075 obj[k]=value_of<T> (in[k],&temp_is_ok);
00076 if(is_ok!=0 && temp_is_ok==false)
00077 *is_ok=false;
00078 }
00079 return obj;
00080 }
00081
00086 template <typename T>
00087 static std::string to_string(const T& t)
00088 {
00089 std::ostringstream oss;
00090 oss<<t;
00091 return std::string(oss.str());
00092 }
00093
00100 static std::string zero_padding(const std::string& input,const int& zero_number=4);
00101
00103 template <typename T>
00104 static std::string to_string_padded(const T& x,const unsigned int& zero_number=4)
00105 {return string_converter::zero_padding(string_converter::to_string(x),zero_number);}
00106
00108 static std::string to_lower(const std::string& input);
00110 static std::string to_upper(const std::string& input);
00111
00113 static std::vector <std::string> delete_empty(const std::vector <std::string>& in);
00114
00115
00124 static std::pair<std::pair<int,int>,std::pair<std::string,std::string> > extract_number_part(const std::string& filename);
00125
00130 static std::vector<std::string> load_filename_sequence(const std::string filename,const unsigned int& iteration=1);
00131
00132
00133 private:
00134 };
00135
00136
00138 class string_tokenizer
00139 {
00140
00141 public:
00149 static std::vector <std::string> tokenize(const std::string& str,const std::string& delimiters=" ");
00150 private:
00151 };
00152
00154 class file_helper
00155 {
00156 public:
00157
00163 static file_helper copy(const std::string& input_filename,const std::string& output_filename);
00164
00165 private:
00166 };
00167
00168
00169 }
00170
00171 #endif