Skip to main content

zend_ini_parse_quantity

Function zend_ini_parse_quantity 

Source
pub unsafe extern "C" fn zend_ini_parse_quantity(
    value: *mut zend_string,
    errstr: *mut *mut zend_string,
) -> zend_long
Expand description

Parses an ini quantity

The value parameter must be a string in the form

sign? digits ws* multiplier?

with

sign: [+-]
digit: [0-9]
digits: digit+
ws: [ \t\n\r\v\f]
multiplier: [KMG]

Leading and trailing whitespaces are ignored.

If the string is empty or consists only of only whitespaces, 0 is returned.

Digits is parsed as decimal unless the first digit is ‘0’, in which case digits is parsed as octal.

The multiplier is case-insensitive. K, M, and G multiply the quantity by 210, 220, and 2**30, respectively.

For backwards compatibility, ill-formatted values are handled as follows:

  • No leading digits: value is treated as ‘0’
  • Invalid multiplier: multiplier is ignored
  • Invalid characters between digits and multiplier: invalid characters are ignored
  • Integer overflow: The result of the overflow is returned

In any of these cases an error string is stored in *errstr (caller must release it), otherwise *errstr is set to NULL.