ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


new:number_parsing

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
new:number_parsing [2018/02/17 22:22] korshunnew:number_parsing [2018/02/18 18:01] (current) korshun
Line 5: Line 5:
 ===== Simple number parsing ===== ===== Simple number parsing =====
  
-Simple number parsing functions return 0 if the input string cannot be parsed as a number, and return the minimum or maximum possible value if the input string is a number beyond [[limits|value limits]] of ACS variables.+Simple number parsing functions return 0 if the input string cannot be parsed as a number, and return the minimum or maximum possible value (''INT_MIN'' or ''INT_MAX''if the input string is a number beyond [[limits|value limits]] of ACS variables.
  
   * ''int atoi(str s)'' parses a string as integer and returns its value.   * ''int atoi(str s)'' parses a string as integer and returns its value.
Line 18: Line 18:
   * Integers: ''<sign> <base prefix> <digits>''   * Integers: ''<sign> <base prefix> <digits>''
   * Fixed-point numbers: ''<sign> <base prefix> <digits> . <digits>''   * Fixed-point numbers: ''<sign> <base prefix> <digits> . <digits>''
 +
 +There must be no spaces in the string, not even around the number.
  
 Sign can be ''+'', ''-'', or nothing (equivalent to ''+''_. Sign can be ''+'', ''-'', or nothing (equivalent to ''+''_.
Line 24: Line 26:
  
   * Nothing -- base 10   * Nothing -- base 10
-  * ''0x'' -- base 16+  * ''0x'' -- base 16 (case-insensitive)
   * ''0o'' -- base 8   * ''0o'' -- base 8
   * ''0b'' -- base 2   * ''0b'' -- base 2
- 
-Bases up to 36 are supported, using the following digits: ''0123456789abcdefghijklmnopqrstuvwxyz''. Digits beyond ''9'' are case-insensitive. 
  
 ===== Advanced parsing functions ===== ===== Advanced parsing functions =====
 +
 +  * ''int, int ParseInt(str s, int default_base)''
 +  * ''int, fixed ParseFixed(str s, int default_base)''
 +
 +Advanced number parsing functions return two values. The first one is a status code, and the second is parsing result:
 +
 +  * ''PARSENUMBER_SUCCESS'' -- no errors happened while parsing the number. The second value is the parsed number
 +  * ''PARSENUMBER_OVERFLOW'' -- the value is out of [[limits|range limits]] of ''int''. The second value is either ''INT_MIN'' or ''INT_MAX'', depending on the sign of the input number.
 +  * ''PARSENUMBER_BADFORMAT'' -- the input string doesn't conform to the format. The second value is 0.
 +
 +The parameter ''default_base'' sets the default base to parse the number in if it has no base prefix. Bases up to 36 are supported, using the following digits: ''0123456789abcdefghijklmnopqrstuvwxyz''. Digits beyond ''9'' are case-insensitive.
  
  
new/number_parsing.1518898935.txt.gz · Last modified: 2018/02/17 22:22 by korshun