develooper Front page | perl.perl5.porters | Postings from May 2017

RFC: optional parameter to Unicode::UCD::num()

Thread Next
From:
Karl Williamson
Date:
May 19, 2017 18:14
Subject:
RFC: optional parameter to Unicode::UCD::num()
Message ID:
f9082f21-4aa8-aa06-1437-687f3ef6ef8c@khwilliamson.com
I propose to add an optional parameter to calling the num() function.

Recall that num() is used to get the numeric value of the input string 
parameter, or undef if none.  Only if the entire string is a valid 
number is something other than undef returned.   If you call it with a 
single character that means 1/2, then 0.5 is returned, but for strings 
of more than a single character, the string must consist entirely of 
decimal digits used in a positional notation, all from the same script, 
for something other than undef to be returned.

Thus, it can be used to defeat spoofing, where something that appears to 
be a digit, but is really from a different script makes the number 
appear to be a different value than it actually is.  For example, 
someone could say, I'll pay you $৪০,using the Bengali characters for 4 
and 0.  num() detects this and return 40.

Some applications would prefer num() to work more like atoi(), so that 
if the first segment of the input string is all digits, they would want 
that substring's numeric value.  This optional parameter would help 
them.  It would be a reference to a scalar, and num would set it to how 
many characters in a row at the beginning of the string form a valid 
number.  0 would be returned if the string begins with a character that 
has no numeric value.  If num returns a numeric value, this parameter 
would be set to the length of the input string.  It would be the case 
that if you call num($string, \$len), then substr($string, 0, $len) 
would be numeric for $len > 0.

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About