develooper Front page | perl.perl5.porters | Postings from July 2014

atoi/strtoblah banished

Thread Next
Jarkko Hietaniemi
July 23, 2014 03:05
atoi/strtoblah banished
Message ID:
In 6313e544..f4379102 I implement a new rabid^Wthoughtful
interface for parsing unsigned integers.  This was then used
to replace the uses of atoi/atoll?/strtoll?/strtoull? in the core.

atoi is notoriously bad in detecting failures, it cannot be used
for incremental parsing ("how far did we get?"), and to top it all,
it believes locale settings (at least the amusingly badly named
"thousands separator", maybe even isdigit?).

strtol family is much better in the first two items, but it fails the 
third one.

The new interface is called "grok_atou" (the branch name was 
"krakatau"... I'll be here all week, folks, please tip the waiters).

It *only* handles unsigned integers (Size_t), by design.  If fancy 
features like negative inputs or optional leading whitespace are 
required-- use the C, Luke.

I extended my new toy, t/porting/libperl.t, to detect and punish if
someone attempts to reintroduce any of the atoi/atol/strtoblah back to 
the core.

For earlier discussion, see:

grok_atou is completely new code, instead of trying to bolt
new parameters/flags to grok_number.  This makes it easier to
be extremely strict, and not worry about breaking grok_number.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About