gstrfuncs: Add replacement for string-to-number functions

Very often when we want to convert a string to number, we assume that
the string contains only a number. We have g_ascii_strto* family of
functions to do the conversion but they are awkward to use - one has
to check if errno is zero, end_ptr is not NULL and *end_ptr points to
the terminating nul and then do the bounds checking. Many projects
need this kind of functionality, so it gets reimplemented all the
time.

This commit adds some replacement functions that convert a string to a
signed or unsigned number that also follows the usual way of error
reporting - returning FALSE on failure and filling an error output
parameter.
This commit is contained in:
Krzesimir Nowak
2017-04-27 12:53:51 +02:00
parent 58ecc57ca7
commit 4fe89b0437
4 changed files with 486 additions and 0 deletions

View File

@@ -1475,6 +1475,15 @@ g_ascii_dtostr
g_ascii_formatd
g_strtod
<SUBSECTION>
GNumberParserError
G_NUMBER_PARSER_ERROR
g_ascii_string_to_signed
g_ascii_string_to_unsigned
<SUBSECTION Private>
g_number_parser_error_quark
<SUBSECTION>
g_strchug
g_strchomp