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 integer value. Additional characters found at position " + (
int)(distance(this_s.begin(), it) + 1));
91 if (!boost::spirit::qi::phrase_parse(it, this_s.end(), parse_float_, boost::spirit::ascii::space, ret))
96 if (it != this_s.end())
98 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));
116 if (!boost::spirit::qi::phrase_parse(it, s.end(), parse_double_, boost::spirit::ascii::space, ret))
123 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));
132 template <
typename IteratorT>
133 static bool extractDouble(IteratorT& begin,
const IteratorT& end,
double& target)
139 return boost::spirit::qi::parse(begin, end, parse_double_, target);
151 template <
typename T>
154 template <
typename Iterator,
typename Attribute>
161 if (*first !=
'n' && *first !=
'N')
165 if (boost::spirit::qi::detail::string_parse(
"nan",
"NAN", first, last, boost::spirit::qi::unused))
167 if (first != last && *first ==
'(')
172 while (++i != last && *i !=
')')
179 attr_ = std::numeric_limits<T>::quiet_NaN();
188 static boost::spirit::qi::real_parser<double, real_policies_NANfixed_<double> >
parse_double_;
189 static boost::spirit::qi::real_parser<float, real_policies_NANfixed_<float> >
parse_float_;
193 namespace StringUtils
203 return QString(this_s.c_str());
221 template <
typename IteratorT>
222 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:110
static bool extractDouble(IteratorT &begin, const IteratorT &end, double &target)
Definition: StringUtils.h:133
static Int toInt(const String &this_s)
Functions.
Definition: StringUtils.h:65
static float toFloat(const String &this_s)
Definition: StringUtils.h:84
static boost::spirit::qi::real_parser< double, real_policies_NANfixed_< double > > parse_double_
Definition: StringUtils.h:188
static boost::spirit::qi::real_parser< float, real_policies_NANfixed_< float > > parse_float_
Definition: StringUtils.h:189
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
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
static bool extractDouble(IteratorT &begin, const IteratorT &end, double &target)
Definition: StringUtils.h:222
static String number(double d, UInt n)
Definition: StringUtils.h:196
static Int toInt(const String &this_s)
Definition: StringUtils.h:206
static double toDouble(const String &this_s)
Definition: StringUtils.h:216
static float toFloat(const String &this_s)
Definition: StringUtils.h:211
static QString toQString(const String &this_s)
Definition: StringUtils.h:201
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47
Definition: StringUtils.h:153
static bool parse_nan(Iterator &first, Iterator const &last, Attribute &attr_)
Definition: StringUtils.h:156