MCPcopy Create free account
hub / github.com/boostorg/parser / parse

Method parse

include/boost/parser/detail/numeric.hpp:676–802  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

674 {
675 template <typename Iterator, typename Sentinel, typename Attribute>
676 static bool
677 parse(Iterator& first, Sentinel last, Attribute& attr,
678 RealPolicies const& p)
679 {
680 if (first == last)
681 return false;
682 Iterator save = first;
683
684 // Start by parsing the sign. neg will be true if
685 // we got a "-" sign, false otherwise.
686 bool neg = p.parse_sign(first, last);
687
688 // Now attempt to parse an integer
689 T n = 0;
690 bool got_a_number = p.parse_n(first, last, n);
691
692 // If we did not get a number it might be a NaN, Inf or a leading
693 // dot.
694 if (!got_a_number)
695 {
696 // Check whether the number to parse is a NaN or Inf
697 if (p.parse_nan(first, last, n) ||
698 p.parse_inf(first, last, n))
699 {
700 // If we got a negative sign, negate the number
701 attr = detail_spirit_x3::negate(neg, n);
702 return true; // got a NaN or Inf, return early
703 }
704
705 // If we did not get a number and our policies do not
706 // allow a leading dot, fail and return early (no-match)
707 if (!p.allow_leading_dot)
708 {
709 first = save;
710 return false;
711 }
712 }
713
714 bool e_hit = false;
715 Iterator e_pos;
716 int frac_digits = 0;
717
718 // Try to parse the dot ('.' decimal point)
719 if (p.parse_dot(first, last))
720 {
721 // We got the decimal point. Now we will try to parse
722 // the fraction if it is there. If not, it defaults
723 // to zero (0) only if we already got a number.
724 Iterator savef = first;
725 if (p.parse_frac_n(first, last, n))
726 {
727 // Optimization note: don't compute frac_digits if T is
728 // an unused_type. This should be optimized away by the compiler.
729 if (!std::is_same_v<T, unused_type>)
730 frac_digits =
731 static_cast<int>(std::distance(savef, first));
732 BOOST_PARSER_DEBUG_ASSERT(frac_digits >= 0);
733 }

Callers

nothing calls this directly

Calls 11

negateFunction · 0.85
distanceFunction · 0.85
scaleFunction · 0.85
parse_nMethod · 0.80
parse_nanMethod · 0.80
parse_infMethod · 0.80
parse_dotMethod · 0.80
parse_frac_nMethod · 0.80
parse_expMethod · 0.80
parse_exp_nMethod · 0.80
parse_signMethod · 0.45

Tested by

no test coverage detected