00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00033 #include <s3fc/s3_conversion.h>
00034
00035
00036
00037 template<>
00038 std::string s3_conversion::from_string<std::string>(const std::string& s)
00039 {
00040 return s;
00041 }
00042
00043
00044 s3_conversion::exception::exception(const std::string& where,
00045 const std::string& what) :
00046 s3_generic_exception(where, what)
00047 {
00048 }
00049
00050
00051 std::vector<std::string> s3_conversion::string_to_vec_string(
00052 const std::string& str)
00053 {
00054 std::vector<std::string> vs;
00055
00056 size_t pos = 0;
00057
00058 while (true)
00059 {
00060
00061 unsigned int strt_i = str.find_first_not_of(" \t\n\r", pos);
00062
00063 unsigned int end_i = str.find_first_of(" \t\n\r", strt_i);
00064 if ( strt_i != std::string::npos )
00065 {
00066 vs.push_back(str.substr(strt_i, end_i - strt_i));
00067 pos = end_i;
00068 } else
00069 {
00070 break;
00071 }
00072 }
00073 return vs;
00074 }
00075
00076
00077 std::vector<int> s3_conversion::string_to_vec_int(const std::string& str)
00078 {
00079 std::vector<int> vi;
00080
00081 std::vector<std::string> vs = string_to_vec_string(str);
00082 for ( std::vector<std::string>::const_iterator ptr = vs.begin();
00083 ptr != vs.end();
00084 ptr++)
00085 {
00086 vi.push_back(atoi(ptr->c_str()));
00087 }
00088 return vi;
00089 }
00090
00091
00092 std::vector<float> s3_conversion::string_to_vec_float(const std::string& str)
00093 {
00094 std::vector<float> vf;
00095
00096 std::vector<std::string> vs = string_to_vec_string(str);
00097 for ( std::vector<std::string>::const_iterator ptr = vs.begin();
00098 ptr != vs.end();
00099 ptr++)
00100 {
00101 vf.push_back(atof(ptr->c_str()));
00102 }
00103 return vf;
00104 }
00105
00106
00107 std::vector<std::string> s3_conversion::split_string(const std::string& str,
00108 const char* delim)
00109 {
00110 std::vector<std::string> vs;
00111
00112 size_t pos = 0;
00113
00114 while ( true )
00115 {
00116
00117 if (delim == 0)
00118 {
00119
00120 const unsigned int strt_i = str.find_first_not_of(" \t\n\r", pos);
00121
00122 const unsigned int end_i = str.find_first_of(" \t\n\r", strt_i);
00123 if ( strt_i != std::string::npos )
00124 {
00125 vs.push_back(str.substr(strt_i, end_i - strt_i));
00126 pos = end_i;
00127 }
00128 else
00129 {
00130 break;
00131 }
00132 }
00133
00134 else
00135 {
00136
00137 if ( pos >= str.length() )
00138 {
00139 break;
00140 }
00141
00142 const unsigned int delim_i = str.find_first_of(delim, pos);
00143 if ( delim_i != std::string::npos )
00144 {
00145 vs.push_back( str.substr( pos, delim_i-pos ) );
00146 pos = delim_i + 1;
00147 }
00148 else
00149 {
00150 vs.push_back( str.substr(pos, str.length()-pos) );
00151 break;
00152 }
00153 }
00154 }
00155 return vs;
00156 }