File indexing completed on 2025-01-31 10:02:36
0001
0002
0003
0004
0005
0006
0007
0008 #if !defined(BOOST_SPIRIT_X3_REAL_POLICIES_APRIL_17_2006_1158PM)
0009 #define BOOST_SPIRIT_X3_REAL_POLICIES_APRIL_17_2006_1158PM
0010
0011 #include <boost/spirit/home/x3/string/detail/string_parse.hpp>
0012 #include <boost/spirit/home/x3/support/numeric_utils/extract_int.hpp>
0013
0014 namespace boost { namespace spirit { namespace x3
0015 {
0016
0017
0018
0019 template <typename T>
0020 struct ureal_policies
0021 {
0022
0023 static bool const allow_leading_dot = true;
0024 static bool const allow_trailing_dot = true;
0025 static bool const expect_dot = false;
0026
0027 template <typename Iterator>
0028 static bool
0029 parse_sign(Iterator& , Iterator const& )
0030 {
0031 return false;
0032 }
0033
0034 template <typename Iterator, typename Attribute>
0035 static bool
0036 parse_n(Iterator& first, Iterator const& last, Attribute& attr_)
0037 {
0038 return extract_uint<T, 10, 1, -1>::call(first, last, attr_);
0039 }
0040
0041 template <typename Iterator>
0042 static bool
0043 parse_dot(Iterator& first, Iterator const& last)
0044 {
0045 if (first == last || *first != '.')
0046 return false;
0047 ++first;
0048 return true;
0049 }
0050
0051 template <typename Iterator, typename Attribute>
0052 static bool
0053 parse_frac_n(Iterator& first, Iterator const& last, Attribute& attr_)
0054 {
0055 return extract_uint<T, 10, 1, -1, true>::call(first, last, attr_);
0056 }
0057
0058 template <typename Iterator>
0059 static bool
0060 parse_exp(Iterator& first, Iterator const& last)
0061 {
0062 if (first == last || (*first != 'e' && *first != 'E'))
0063 return false;
0064 ++first;
0065 return true;
0066 }
0067
0068 template <typename Iterator>
0069 static bool
0070 parse_exp_n(Iterator& first, Iterator const& last, int& attr_)
0071 {
0072 return extract_int<int, 10, 1, -1>::call(first, last, attr_);
0073 }
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089 template <typename Iterator, typename Attribute>
0090 static bool
0091 parse_nan(Iterator& first, Iterator const& last, Attribute& attr_)
0092 {
0093 if (first == last)
0094 return false;
0095
0096 if (*first != 'n' && *first != 'N')
0097 return false;
0098
0099
0100 if (detail::string_parse("nan", "NAN", first, last, unused))
0101 {
0102 if (first != last && *first == '(')
0103 {
0104
0105 Iterator i = first;
0106
0107 while (++i != last && *i != ')')
0108 ;
0109 if (i == last)
0110 return false;
0111
0112 first = ++i;
0113 }
0114 attr_ = std::numeric_limits<T>::quiet_NaN();
0115 return true;
0116 }
0117 return false;
0118 }
0119
0120 template <typename Iterator, typename Attribute>
0121 static bool
0122 parse_inf(Iterator& first, Iterator const& last, Attribute& attr_)
0123 {
0124 if (first == last)
0125 return false;
0126
0127 if (*first != 'i' && *first != 'I')
0128 return false;
0129
0130
0131 if (detail::string_parse("inf", "INF", first, last, unused))
0132 {
0133
0134 detail::string_parse("inity", "INITY", first, last, unused);
0135 attr_ = std::numeric_limits<T>::infinity();
0136 return true;
0137 }
0138 return false;
0139 }
0140 };
0141
0142
0143
0144
0145 template <typename T>
0146 struct real_policies : ureal_policies<T>
0147 {
0148 template <typename Iterator>
0149 static bool
0150 parse_sign(Iterator& first, Iterator const& last)
0151 {
0152 return extract_sign(first, last);
0153 }
0154 };
0155
0156 template <typename T>
0157 struct strict_ureal_policies : ureal_policies<T>
0158 {
0159 static bool const expect_dot = true;
0160 };
0161
0162 template <typename T>
0163 struct strict_real_policies : real_policies<T>
0164 {
0165 static bool const expect_dot = true;
0166 };
0167 }}}
0168
0169 #endif