Go to the documentation of this file.
23 #ifndef O2SCL_STRING_CONV_H
24 #define O2SCL_STRING_CONV_H
40 #include <o2scl/misc.h>
42 #ifndef DOXYGEN_NO_O2NS
53 std::string
ptos(
void *p);
57 std::string
itos(
int x);
61 std::string
szttos(
size_t x);
67 std::string
btos(
bool b);
77 std::string
dtos(
const fp_t &x,
int prec=6,
bool auto_prec=
false) {
79 std::ostringstream strout;
81 size_t max=std::numeric_limits<fp_t>::digits10;
82 if (prec<0 || (prec>((
int)max) && prec>6)) prec=((int)max);
85 if (!auto_prec) strout.setf(std::ios::scientific);
86 strout.precision(prec);
93 O2SCL_ERR2(
"Conversion from floating point value to string failed in ",
110 std::string
dtos(
double x, std::ostream &format);
116 int stoi(std::string s);
129 size_t stoszt(std::string s);
150 bool stob(std::string s,
bool err_on_fail=
true);
160 double stod(std::string s);
232 void split_string(std::string str, std::vector<std::string> &sv);
242 void rewrap(std::string str, std::vector<std::string> &sv,
257 template<
class size_vec_t>
262 std::vector<std::string> ranges;
264 while (k<x.length()) {
265 size_t loc=x.find(
',',k);
266 if (loc!=std::string::npos) {
267 std::string stemp=x.substr(k,loc-k);
268 ranges.push_back(stemp);
272 ranges.push_back(x.substr(k,x.length()-k));
277 size_t uitmp, uitmp2;
278 for(
size_t j=0;j<ranges.size();j++) {
279 if (ranges[j].find(
'-')==std::string::npos) {
281 if (ret!=0)
return ret;
282 list.push_back(uitmp);
284 size_t loc=ranges[j].find(
'-');
285 std::string sstart=ranges[j].substr(0,loc);
286 std::string send=ranges[j].substr(loc+1,ranges[j].size()-loc);
288 if (ret!=0)
return ret;
290 if (ret!=0)
return ret;
291 for(
size_t jk=uitmp;jk<=uitmp2;jk++) {
301 #ifndef DOXYGEN_NO_O2NS
bool is_number(std::string s)
Return true if the string s is likely a integral or floating point number.
int string_to_uint_list(const std::string &x, size_vec_t &list)
Convert a string-based list of unsigned integers to a list.
std::string dtos(const fp_t &x, int prec=6, bool auto_prec=false)
Convert a double to a string.
bool has_minus_sign(double *x)
Find out if the number pointed to by x has a minus sign.
std::string btos(bool b)
Convert a boolean value to a string.
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
int stoi(std::string s)
Convert a string to an integer.
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
size_t stoszt(std::string s)
Convert a string to a size_t.
double stod(std::string s)
Convert a string to a double.
void rewrap_keep_endlines(std::string str, std::vector< std::string > &sv, size_t ncol=79)
Rewrap a string into a single column, avoiding strings less than a particular number of characters.
@ exc_einval
invalid argument supplied by user
int stoi_nothrow(std::string s, int &result)
Convert a string to an integer without throwing an exception.
void rewrap(std::string str, std::vector< std::string > &sv, size_t ncol=79)
Rewrap a string into a single column, avoiding strings less than a particular number of characters.
size_t size_of_exponent(double x)
Returns the number of characters required to display the exponent of x in scientific mode.
int stoszt_nothrow(std::string s, size_t &result)
Convert a string to a size_t without throwing an exception.
std::string itos(int x)
Convert an integer to a string.
int stod_nothrow(std::string s, double &result)
Convert a string to a double returning non-zero value for failure.
void split_string(std::string str, std::vector< std::string > &sv)
Split a string into words using whitespace for delimiters and (partially) respecting quotes.
std::string ptos(void *p)
Convert a pointer to a string.
double function_to_double(std::string s)
Convert a formula to a double.
int split_string_delim(std::string str, std::vector< std::string > &list, char delim)
Split a string into parts using a delimiter.
bool stob(std::string s, bool err_on_fail=true)
Convert a string to a boolean value.
int function_to_double_nothrow(std::string s, double &result)
Convert a formula to a double and return an integer to indicate success or failure.
std::string szttos(size_t x)
Convert a size_t to a string.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).