44 #include <QtCore/QString>
45 #include <boost/spirit/include/qi.hpp>
46 #include <boost/spirit/include/karma.hpp>
47 #include <boost/type_traits.hpp>
72 if (!boost::spirit::qi::phrase_parse(it, this_s.end(), boost::spirit::qi::int_, boost::spirit::ascii::space, ret))
77 if (it != this_s.end())
79 throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
String(
"Prefix of string '") + this_s +
"' successfully converted to an int32 value. Additional characters found at position " + (
int)(distance(this_s.begin(), it) + 1));
91 if (!boost::spirit::qi::phrase_parse(it, this_s.end(), boost::spirit::qi::long_long, boost::spirit::ascii::space, ret))
96 if (it != this_s.end())
99 String(
"Prefix of string '") + this_s +
"' successfully converted to an integer value. Additional characters found at position " +
100 (
int)(distance(this_s.begin(), it) + 1));
112 if (!boost::spirit::qi::phrase_parse(it, this_s.end(), parse_float_, boost::spirit::ascii::space, ret))
117 if (it != this_s.end())
119 throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
String(
"Prefix of string '") + this_s +
"' successfully converted to a float value. Additional characters found at position " + (
int)(distance(this_s.begin(), it) + 1));
137 if (!boost::spirit::qi::phrase_parse(it, s.end(), parse_double_, boost::spirit::ascii::space, ret))
144 throw Exception::ConversionError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION,
String(
"Prefix of string '") + s +
"' successfully converted to a double value. Additional characters found at position " + (
int)(distance(s.begin(), it) + 1));
153 template <
typename IteratorT>
154 static bool extractDouble(IteratorT& begin,
const IteratorT& end,
double& target)
160 return boost::spirit::qi::parse(begin, end, parse_double_, target);
172 template <
typename T>
175 template <
typename Iterator,
typename Attribute>
182 if (*first !=
'n' && *first !=
'N')
186 if (boost::spirit::qi::detail::string_parse(
"nan",
"NAN", first, last, boost::spirit::qi::unused))
188 if (first != last && *first ==
'(')
193 while (++i != last && *i !=
')')
200 attr_ = std::numeric_limits<T>::quiet_NaN();
209 static boost::spirit::qi::real_parser<double, real_policies_NANfixed_<double> >
parse_double_;
210 static boost::spirit::qi::real_parser<float, real_policies_NANfixed_<float> >
parse_float_;
214 namespace StringUtils
224 return QString(this_s.c_str());
247 template <
typename IteratorT>
248 static bool extractDouble(IteratorT& begin,
const IteratorT& end,
double& target)
Invalid conversion exception.
Definition: Exception.h:356
Definition: StringUtils.h:58
static double toDouble(const String &s)
convert String (leading and trailing whitespace allowed) to double
Definition: StringUtils.h:131
static bool extractDouble(IteratorT &begin, const IteratorT &end, double &target)
Definition: StringUtils.h:154
static Int64 toInt64(const String &this_s)
Definition: StringUtils.h:84
static float toFloat(const String &this_s)
Definition: StringUtils.h:105
static Int toInt32(const String &this_s)
Functions.
Definition: StringUtils.h:65
static boost::spirit::qi::real_parser< double, real_policies_NANfixed_< double > > parse_double_
Definition: StringUtils.h:209
static boost::spirit::qi::real_parser< float, real_policies_NANfixed_< float > > parse_float_
Definition: StringUtils.h:210
A more convenient string class.
Definition: String.h:60
const_iterator ConstIterator
Const Iterator.
Definition: String.h:72
int Int
Signed integer type.
Definition: Types.h:102
OPENMS_INT32_TYPE Int32
Signed integer type (32bit)
Definition: Types.h:56
OPENMS_INT64_TYPE Int64
Signed integer type (64bit)
Definition: Types.h:70
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
static bool extractDouble(IteratorT &begin, const IteratorT &end, double &target)
Definition: StringUtils.h:248
static String number(double d, UInt n)
Definition: StringUtils.h:217
static Int32 toInt32(const String &this_s)
Definition: StringUtils.h:227
static Int64 toInt64(const String &this_s)
Definition: StringUtils.h:232
static double toDouble(const String &this_s)
Definition: StringUtils.h:242
static float toFloat(const String &this_s)
Definition: StringUtils.h:237
static QString toQString(const String &this_s)
Definition: StringUtils.h:222
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
Definition: StringUtils.h:174
static bool parse_nan(Iterator &first, Iterator const &last, Attribute &attr_)
Definition: StringUtils.h:177