29 #ifndef ioutils_stringUtils_hpp
30 #define ioutils_stringUtils_hpp
39 #include "../mxlib.hpp"
81 template<
typename typeT,
unsigned w
idth=0,
char pad=' '>
87 std::ostringstream convert;
89 if( std::is_floating_point<typeT>::value )
93 convert.precision( std::numeric_limits<typeT>::max_digits10);
97 convert.precision(precision);
105 return convert.str();
109 std::string
c = convert.str();
111 if(
c.length() > width )
113 c.erase( width,
c.length()-width);
117 return std::string( width-
c.length(), pad) +
c;
127 std::string convertToString<std::string>(
const std::string & value,
147 template<
typename typeT>
155 char convertFromString<char>(
const std::string & str );
158 char16_t convertFromString<char16_t>(
const std::string & str );
161 char32_t convertFromString<char32_t>(
const std::string & str );
164 wchar_t convertFromString<wchar_t>(
const std::string & str );
167 signed char convertFromString<signed char>(
const std::string & str );
170 unsigned char convertFromString<unsigned char>(
const std::string & str );
173 short convertFromString<short>(
const std::string & str );
176 unsigned short convertFromString<unsigned short>(
const std::string & str );
179 int convertFromString<int>(
const std::string & str );
182 unsigned int convertFromString<unsigned int>(
const std::string & str );
185 long convertFromString<long>(
const std::string & str );
188 unsigned long convertFromString<unsigned long>(
const std::string & str );
191 long long convertFromString<long long>(
const std::string & str );
194 unsigned long long convertFromString<unsigned long long>(
const std::string & str );
197 float convertFromString<float>(
const std::string & str );
200 double convertFromString<double>(
const std::string & str );
203 long double convertFromString<long double>(
const std::string & str );
220 void toLower( std::string &outstr,
221 const std::string & instr
230 std::string
toLower(
const std::string & instr );
236 void toUpper( std::string &outstr,
237 const std::string & instr
246 std::string
toUpper(
const std::string & instr );
253 const std::string & instr
267 int stringWrap( std::vector<std::string> & lines,
268 const std::string & str,
286 template<
typename typeT>
288 const std::string & s,
296 com = s.find(delim, st);
300 while(com != std::string::npos)
302 v.push_back( convertFromString<typeT>(s.substr(st, com-st)) );
304 com = s.find(delim, st);
306 v.push_back( convertFromString<typeT>(s.substr(st, s.size()-st)));
324 template<
typename typeT>
326 const std::string & s,
327 const std::string & delims
334 com = s.find_first_of(delims, st);
338 while(com != std::string::npos)
340 v.push_back( convertFromString<typeT>(s.substr(st, com-st)) );
342 com = s.find_first_of(delims, st);
344 v.push_back( convertFromString<typeT>(s.substr(st, s.size()-st)));
constexpr units::realT c()
The speed of light.
void parseStringVector(std::vector< typeT > &v, const std::string &s, const std::string &delims)
Parses a string into a vector of tokens delimited by a set of characters.
int stringWrap(std::vector< std::string > &lines, const std::string &str, int width)
Wrap a string by breaking it into smaller sized portions of a desired width.
std::string removeWhiteSpace(const std::string &instr)
Remove all white space from a string.
std::string convertToString(const typeT &value, int precision=0)
Convert a numerical value to a string.
typeT convertFromString(const std::string &str)
Convert a string to a numerical value.
bool convertFromString< bool >(const std::string &str)
Template specialization of convertFromString for bool.
std::string toUpper(const std::string &instr)
Convert a string to all upper case.
std::string toLower(const std::string &instr)
Convert a string to all lower case.