bug-libunistring
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-libunistring] atoi/strtol like functions?


From: Bruno Haible
Subject: Re: [bug-libunistring] atoi/strtol like functions?
Date: Tue, 14 Mar 2017 19:09:39 +0100
User-agent: KMail/5.1.3 (Linux/4.4.0-66-generic; KDE/5.18.0; x86_64; ; )

Hi Amadeusz,

> I'm trying to convert program which makes use of atoi() to parse some
> strings, but there doesn't seem to be any sufficient equivalent.
> Is there chance of introducing something like u32toi or maybe
> u32_strtol?

Thanks for the suggestion. It's already in the bug/wish tracker at
https://savannah.gnu.org/bugs/?49905

You can implement such a function yourself, roughly like this:
1) Decide what kinds of decimal point character, decimal 
   grouping character, exponent marker, sign character,
   and digit scripts you want to support in that conversion.
2) Verify that all digits in the input are from the same
   script.
3) Convert the digits to their numerical value using the
   uc_digit_value function.
4) Build up a 'char *' string with the corresponding ASCII
   digits and sign, and without grouping characters.
5) Pass that string to strtol or strtod. 

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]