Function

GLibascii_string_to_unsigned

since: 2.54

Declaration [src]

gboolean
g_ascii_string_to_unsigned (
  const gchar* str,
  guint base,
  guint64 min,
  guint64 max,
  guint64* out_num,
  GError** error
)

Description [src]

A convenience function for converting a string to an unsigned number.

This function assumes that str contains only a number of the given base that is within inclusive bounds limited by min and max. If this is true, then the converted number is stored in out_num. An empty string is not a valid input. A string with leading or trailing whitespace is also an invalid input. A string with a leading sign (- or +) is not a valid input for the unsigned parser.

base can be between 2 and 36 inclusive. Hexadecimal numbers must not be prefixed with “0x” or “0X”. Such a problem does not exist for octal numbers, since they were usually prefixed with a zero which does not change the value of the parsed number.

Parsing failures result in an error with the G_NUMBER_PARSER_ERROR domain. If the input is invalid, the error code will be G_NUMBER_PARSER_ERROR_INVALID. If the parsed number is out of bounds - G_NUMBER_PARSER_ERROR_OUT_OF_BOUNDS.

See g_ascii_strtoull() if you have more complex needs such as parsing a string which starts with a number, but then has other characters.

Available since: 2.54

Parameters

str

Type: const gchar*

A string.

The data is owned by the caller of the function.
The value is a NUL terminated UTF-8 string.
base

Type: guint

Base of a parsed number.

min

Type: guint64

A lower bound (inclusive).

max

Type: guint64

An upper bound (inclusive).

out_num

Type: guint64*

A return location for a number.

The argument will be set by the function.
The argument can be NULL.
error

Type: GError **

The return location for a recoverable error.

The argument can be NULL.
If the return location is not NULL, then you must initialize it to a NULL GError*.
The argument will be left initialized to NULL by the function if there are no errors.
In case of error, the argument will be set to a newly allocated GError; the caller will take ownership of the data, and be responsible for freeing it.

Return value

Type: gboolean

True if str was a number, false otherwise.