X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/7d59d161cb0d8b62aecb78fa8c5e011538e6a17e..3f7602fa4cd6923ae409dbb4a71c27905a0abd30:/numeric.c diff --git a/numeric.c b/numeric.c index e52064c..4876ece 100644 --- a/numeric.c +++ b/numeric.c @@ -548,7 +548,7 @@ Perl_grok_numeric_radix(pTHX_ const char **sp, const char *send) } /* -=for apidoc grok_number +=for apidoc grok_number_flags Recognise (or not) a number. The type of the number is returned (0 if unrecognised), otherwise it is a bit-ORed combination of @@ -568,11 +568,27 @@ IS_NUMBER_NEG if the number is negative (in which case *valuep holds the absolute value). IS_NUMBER_IN_UV is not set if e notation was used or the number is larger than a UV. +C allows only C, which allows for trailing +non-numeric text on an otherwise successful I, setting +C on the result. + +=for apidoc grok_number + +Identical to grok_number_flags() with flags set to zero. + =cut */ int Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep) { + PERL_ARGS_ASSERT_GROK_NUMBER; + + return grok_number_flags(pv, len, valuep, 0); +} + +int +Perl_grok_number_flags(pTHX_ const char *pv, STRLEN len, UV *valuep, U32 flags) +{ const char *s = pv; const char * const send = pv + len; const UV max_div_10 = UV_MAX / 10; @@ -581,7 +597,7 @@ Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep) int sawinf = 0; int sawnan = 0; - PERL_ARGS_ASSERT_GROK_NUMBER; + PERL_ARGS_ASSERT_GROK_NUMBER_FLAGS; while (s < send && isSPACE(*s)) s++; @@ -736,9 +752,6 @@ Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep) } else if (s < send) { /* we can have an optional exponent part */ if (*s == 'e' || *s == 'E') { - /* The only flag we keep is sign. Blow away any "it's UV" */ - numtype &= IS_NUMBER_NEG; - numtype |= IS_NUMBER_NOT_INT; s++; if (s < send && (*s == '-' || *s == '+')) s++; @@ -747,8 +760,14 @@ Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep) s++; } while (s < send && isDIGIT(*s)); } + else if (flags & PERL_SCAN_TRAILING) + return numtype | IS_NUMBER_TRAILING; else - return 0; + return 0; + + /* The only flag we keep is sign. Blow away any "it's UV" */ + numtype &= IS_NUMBER_NEG; + numtype |= IS_NUMBER_NOT_INT; } } while (s < send && isSPACE(*s)) @@ -760,6 +779,10 @@ Perl_grok_number(pTHX_ const char *pv, STRLEN len, UV *valuep) *valuep = 0; return IS_NUMBER_IN_UV; } + else if (flags & PERL_SCAN_TRAILING) { + return numtype | IS_NUMBER_TRAILING; + } + return 0; }