29#ifndef ioutils_stringUtils_hpp
30#define ioutils_stringUtils_hpp
38#include "../meta/tagT.hpp"
39#include "../mxlib.hpp"
83template <
typename typeT,
unsigned w
idth = 0,
char pad = ' '>
84[[deprecated(
"Use std::format instead" )]]
92 std::ostringstream convert;
94 if( std::is_floating_point<typeT>::value )
98 convert.precision( std::numeric_limits<typeT>::max_digits10 );
102 convert.precision( precision );
110 return convert.str();
114 std::string c = convert.str();
116 if( c.length() > width )
118 c.erase( width, c.length() - width );
122 return std::string( width - c.length(), pad ) + c;
128std::string convertToString<std::string>(
const std::string &value,
int precision );
188template <
typename typeT>
189typeT
stoT(
const std::string &str,
210template <
typename typeT>
211typeT
stoT(
const std::string &str,
223template <
typename typeT>
224[[deprecated(
"Use mx::ioutils::stoT<typeT> instead" )]]
229 return stoT<typeT>( str, errc );
242 const std::string &instr
258std::string
toLower(
const std::string &instr,
271 const std::string &instr
286std::string
toUpper(
const std::string &instr,
294 const std::string &instr
308int stringWrap( std::vector<std::string> &lines,
310 const std::string &str,
328template <
typename typeT>
330 std::vector<typeT> &v,
331 const std::string &s,
339 com = s.find( delim, st );
343 while( com != std::string::npos )
345 v.push_back( convertFromString<typeT>( s.substr( st, com - st ) ) );
347 com = s.find( delim, st );
349 v.push_back( convertFromString<typeT>( s.substr( st, s.size() - st ) ) );
366template <
typename typeT>
368 std::vector<typeT> &v,
369 const std::string &s,
370 const std::string &delims
377 com = s.find_first_of( delims, st );
381 while( com != std::string::npos )
383 v.push_back( convertFromString<typeT>( s.substr( st, com - st ) ) );
385 com = s.find_first_of( delims, st );
387 v.push_back( convertFromString<typeT>( s.substr( st, s.size() - st ) ) );
error_t
The mxlib error codes.
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 convertToString(const typeT &value, int precision=0)
Convert a numerical value to a string.
void parseStringVector(std::vector< typeT > &v, const std::string &s, char delim=',')
Parses a string into a vector of tokens delimited by a character.
mx::error_t toLower(std::string &outstr, const std::string &instr)
Convert a string to all lower case.
mx::error_t toUpper(std::string &outstr, const std::string &instr)
Convert a string to all upper case.
void removeWhiteSpace(std::string &outstr, const std::string &instr)
Remove all white space from a string.
typeT convertFromString(const std::string &str, error_t *errc=nullptr)
Convert a string to a numerical value.
typeT stoT(const std::string &str, error_t *errc=nullptr)
Convert a string to a numerical value.