|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file.
55 if( cont ==
"true" || cont ==
"yes" || cont ==
"on" || cont ==
"1" ) {
58 }
else if( cont.empty() || cont ==
"false" || cont ==
"no" || cont ==
"off" || cont ==
"0" ) {
69 throw std::runtime_error(
"String is not convertible to bool: \"" + str +
"\"" );
90 if( cont ==
"true" || cont ==
"yes" || cont ==
"on" || cont ==
"1" ) {
93 }
else if( cont ==
"false" || cont ==
"no" || cont ==
"off" || cont ==
"0" ) {
96 }
else if( cont.empty() ) {
97 result = std::numeric_limits<double>::quiet_NaN();
107 throw std::runtime_error(
"String is not convertible to bool: \"" + str +
"\"" );
122 template<
typename T,
class F>
128 auto const lower =
trim( str );
129 if( lower.empty() ) {
136 result = conversion( lower, &pos );
137 if( pos != lower.size() ) {
154 str, result, std::numeric_limits<double>::quiet_NaN(),
155 []( std::string
const& str, std::size_t* pos ){
156 return std::stod( str, pos );
165 throw std::runtime_error(
166 "String is not convertible to double: \"" + str +
"\""
186 str, result,
static_cast<long long>(0),
187 []( std::string
const& str, std::size_t* pos ){
188 return std::stoll( str, pos );
197 throw std::runtime_error(
198 "String is not convertible to signed integer (long long): \"" + str +
"\""
218 str, result,
static_cast<unsigned long long>(0),
219 []( std::string
const& str, std::size_t* pos ){
220 return std::stoull( str, pos );
227 unsigned long long result;
229 throw std::runtime_error(
230 "String is not convertible to unsigned integer (unsigned long long): \"" + str +
"\""
238 unsigned long long result;
bool is_convertible_to_unsigned_integer(std::string const &str)
Return whether a string can be converted to unsigned integer.
bool is_convertible_to_bool(Dataframe const &df, size_t col_index)
std::string trim(std::string const &s, std::string const &delimiters)
Return a copy of the input string, with trimmed white spaces (or any other delimiters).
void convert_to_double(Dataframe &df, size_t col_index)
Provides some commonly used string utility functions.
bool convert_to_unsigned_integer(std::string const &str, unsigned long long &result)
Convert a string to unsigned integer, store the result in result, and return whether the conversion a...
bool is_convertible_to_bool_double(std::string const &str)
Return whether a string can be converted to bool (and stored as a double).
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
bool is_convertible_to_double(Dataframe const &df, size_t col_index)
std::string to_lower_ascii(std::string const &str)
Return an all-lowercase copy of the given string, ASCII-only.
void convert_to_bool(Dataframe &df, size_t col_index)
bool is_convertible_to_signed_integer(std::string const &str)
Return whether a string can be converted to signed integer.
bool convert_to_signed_integer(std::string const &str, long long &result)
Convert a string to signed integer, store the result in result, and return whether the conversion as ...
bool convert_to_bool_double(std::string const &str, double &result)
Convert a string to bool, but store the result as a double in result, and return whether the conversi...
bool convert_to_numeric_(std::string const &str, T &result, T initial, F conversion)