Skip to content

Commit 8e698ee

Browse files
committed
perlapi: Combine grok_(bin|hex|oct) into single entry
1 parent 209bfe3 commit 8e698ee

File tree

1 file changed

+50
-80
lines changed

1 file changed

+50
-80
lines changed

numeric.c

Lines changed: 50 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,13 @@ Perl_cast_uv(NV f)
217217
}
218218

219219
/*
220-
=for apidoc grok_bin
220+
=for apidoc grok_bin
221+
=for apidoc_item grok_hex
222+
=for apidoc_item grok_oct
221223
222-
converts a string representing a binary number to numeric form.
224+
These each convert a string representing a number to numeric form. The
225+
number is binary in C<grok_bin>, octal in C<grok_oct>, and hexadecimal in
226+
C<grok_hex>.
223227
224228
On entry C<start> and C<*len_p> give the string to scan, C<*flags> gives
225229
conversion flags, and C<result> should be C<NULL> or a pointer to an NV. The
@@ -229,18 +233,50 @@ encountering an invalid character (except NUL) will also trigger a warning. On
229233
return C<*len_p> is set to the length of the scanned string, and C<*flags>
230234
gives output flags.
231235
232-
If the value is <= C<UV_MAX> it is returned as a UV, the output flags are clear,
233-
and nothing is written to C<*result>. If the value is > C<UV_MAX>, C<grok_bin>
234-
returns C<UV_MAX>, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
235-
and writes an approximation of the correct value into C<*result> (which is an
236-
NV; or the approximation is discarded if C<result> is NULL).
236+
If the value is S<E<lt>= C<UV_MAX>>, it is returned as a UV, the output flags are
237+
clear, and nothing is written to C<*result>. If the value is S<E<gt>
238+
C<UV_MAX>>:
237239
238-
The binary number may optionally be prefixed with C<"0b"> or C<"b"> unless
239-
C<PERL_SCAN_DISALLOW_PREFIX> is set in C<*flags> on entry.
240+
=over
241+
242+
=item *
243+
244+
C<UV_MAX> is returned
245+
246+
=item *
247+
248+
C<PERL_SCAN_GREATER_THAN_UV_MAX> is set in C<*flags>.
249+
250+
=item *
251+
252+
If C<result> is not null, an approximation of the correct value is written
253+
into C<*result> (which is an NV).
254+
255+
=back
256+
257+
Unless C<PERL_SCAN_DISALLOW_PREFIX> is set in C<*flags> on entry:
258+
259+
=over
260+
261+
=item For C<grok_bin>
262+
263+
the input string may optionally be prefixed with C<"0b"> or plain C<"b">
264+
265+
=item For C<grok_hex>
266+
267+
the input string may optionally be prefixed with C<"0x"> or plain C<"x">
268+
unless
269+
270+
=item For C<grok_oct>
271+
272+
this flag is ignored; there is no optional prefix. The typical C<0> prefix is
273+
just part of the number.
274+
275+
=back
240276
241277
If C<PERL_SCAN_ALLOW_UNDERSCORES> is set in C<*flags> then any or all pairs of
242-
digits may be separated from each other by a single underscore; also a single
243-
leading underscore is accepted.
278+
digits may be separated from each other by a single underscore, and also a
279+
single leading underscore is accepted.
244280
245281
=for apidoc Amnh||PERL_SCAN_ALLOW_UNDERSCORES
246282
=for apidoc Amnh||PERL_SCAN_DISALLOW_PREFIX
@@ -249,9 +285,9 @@ leading underscore is accepted.
249285
250286
=cut
251287
252-
Not documented yet because experimental is C<PERL_SCAN_SILENT_NON_PORTABLE
253-
which suppresses any message for non-portable numbers that are still valid
254-
on this platform.
288+
Not available externally yet because experimental is
289+
C<PERL_SCAN_SILENT_NON_PORTABLE which suppresses any message for non-portable
290+
numbers that are still valid on this platform.
255291
*/
256292

257293
UV
@@ -262,39 +298,6 @@ Perl_grok_bin(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result)
262298
return grok_bin(start, len_p, flags, result);
263299
}
264300

265-
/*
266-
=for apidoc grok_hex
267-
268-
converts a string representing a hex number to numeric form.
269-
270-
On entry C<start> and C<*len_p> give the string to scan, C<*flags> gives
271-
conversion flags, and C<result> should be C<NULL> or a pointer to an NV. The
272-
scan stops at the end of the string, or at just before the first invalid
273-
character. Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in C<*flags>,
274-
encountering an invalid character (except NUL) will also trigger a warning. On
275-
return C<*len_p> is set to the length of the scanned string, and C<*flags>
276-
gives output flags.
277-
278-
If the value is <= C<UV_MAX> it is returned as a UV, the output flags are clear,
279-
and nothing is written to C<*result>. If the value is > C<UV_MAX>, C<grok_hex>
280-
returns C<UV_MAX>, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
281-
and writes an approximation of the correct value into C<*result> (which is an
282-
NV; or the approximation is discarded if C<result> is NULL).
283-
284-
The hex number may optionally be prefixed with C<"0x"> or C<"x"> unless
285-
C<PERL_SCAN_DISALLOW_PREFIX> is set in C<*flags> on entry.
286-
287-
If C<PERL_SCAN_ALLOW_UNDERSCORES> is set in C<*flags> then any or all pairs of
288-
digits may be separated from each other by a single underscore; also a single
289-
leading underscore is accepted.
290-
291-
=cut
292-
293-
Not documented yet because experimental is C<PERL_SCAN_SILENT_NON_PORTABLE>
294-
which suppresses any message for non-portable numbers, but which are valid
295-
on this platform. But, C<*flags> will have the corresponding flag bit set.
296-
*/
297-
298301
UV
299302
Perl_grok_hex(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result)
300303
{
@@ -303,39 +306,6 @@ Perl_grok_hex(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result)
303306
return grok_hex(start, len_p, flags, result);
304307
}
305308

306-
/*
307-
=for apidoc grok_oct
308-
309-
converts a string representing an octal number to numeric form.
310-
311-
On entry C<start> and C<*len_p> give the string to scan, C<*flags> gives
312-
conversion flags, and C<result> should be C<NULL> or a pointer to an NV. The
313-
scan stops at the end of the string, or at just before the first invalid
314-
character. Unless C<PERL_SCAN_SILENT_ILLDIGIT> is set in C<*flags>,
315-
encountering an invalid character (except NUL) will also trigger a warning. On
316-
return C<*len_p> is set to the length of the scanned string, and C<*flags>
317-
gives output flags.
318-
319-
If the value is <= C<UV_MAX> it is returned as a UV, the output flags are clear,
320-
and nothing is written to C<*result>. If the value is > C<UV_MAX>, C<grok_oct>
321-
returns C<UV_MAX>, sets C<PERL_SCAN_GREATER_THAN_UV_MAX> in the output flags,
322-
and writes an approximation of the correct value into C<*result> (which is an
323-
NV; or the approximation is discarded if C<result> is NULL).
324-
325-
If C<PERL_SCAN_ALLOW_UNDERSCORES> is set in C<*flags> then any or all pairs of
326-
digits may be separated from each other by a single underscore; also a single
327-
leading underscore is accepted.
328-
329-
The C<PERL_SCAN_DISALLOW_PREFIX> flag is always treated as being set for
330-
this function.
331-
332-
=cut
333-
334-
Not documented yet because experimental is C<PERL_SCAN_SILENT_NON_PORTABLE>
335-
which suppresses any message for non-portable numbers, but which are valid
336-
on this platform.
337-
*/
338-
339309
UV
340310
Perl_grok_oct(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result)
341311
{

0 commit comments

Comments
 (0)