|
CX Framework
Cross-platform C utility framework
|
Modules | |
| Internal conversion functions | |
Functions | |
| bool | strToInt32 (int32 *out, strref s, int base, bool strict) |
| bool | strToUInt32 (uint32 *out, strref s, int base, bool strict) |
| bool | strToInt64 (int64 *out, strref s, int base, bool strict) |
| bool | strToUInt64 (uint64 *out, strref s, int base, bool strict) |
| bool | strFromInt32 (strhandle out, int32 i, uint16 base) |
| bool | strFromUInt32 (strhandle out, uint32 i, uint16 base) |
| bool | strFromInt64 (strhandle out, int64 i, uint16 base) |
| bool | strFromUInt64 (strhandle out, uint64 i, uint16 base) |
| bool | strToFloat32 (float32 *out, strref s, bool strict) |
| bool | strToFloat64 (float64 *out, strref s, bool strict) |
| bool | strFromFloat32 (strhandle out, float32 f) |
| bool | strFromFloat64 (strhandle out, float64 f) |
Functions for converting between strings and numeric values. Both integer and floating-point conversions are supported.
Integer parsing supports bases 2-36. Unlike standard C library functions, a leading '0' does NOT imply octal (base 8) - base 10 is always the default unless explicitly specified or the string begins with "0x" for hexadecimal.
The 'strict' parameter controls whether the entire string must be numeric:
Float-to-string conversion uses the Grisu2 algorithm for efficient and accurate representation. The output format is chosen automatically (plain, decimal, or scientific notation) based on the magnitude of the value.
Conversion functions return false on error and set cxerr:
| bool strFromFloat32 | ( | strhandle | out, |
| float32 | f | ||
| ) |
Converts a 32-bit floating-point value to a string
Formats the float using the Grisu2 algorithm for efficient and accurate conversion. The output format (plain decimal, scientific notation) is chosen automatically based on the magnitude. Special values are rendered as "inf", "-inf", or "nan".
| out | Output string (existing content destroyed) |
| f | Float value to convert |
Example:
| bool strFromFloat64 | ( | strhandle | out, |
| float64 | f | ||
| ) |
Converts a 64-bit floating-point value to a string
Like strFromFloat32(), but for double-precision values. Uses Grisu2 algorithm for accurate conversion with automatic format selection.
| out | Output string (existing content destroyed) |
| f | Double value to convert |
Example:
| bool strFromInt32 | ( | strhandle | out, |
| int32 | i, | ||
| uint16 | base | ||
| ) |
Converts a 32-bit signed integer to a string
Formats the integer in the specified base. Negative values are prefixed with '-'. For bases > 10, lowercase letters are used (a-z).
| out | Output string (existing content destroyed) |
| i | Integer value to convert |
| base | Numeric base (2-36), typically 10 or 16 |
Example:
| bool strFromInt64 | ( | strhandle | out, |
| int64 | i, | ||
| uint16 | base | ||
| ) |
Converts a 64-bit signed integer to a string
Like strFromInt32(), but for 64-bit values.
| out | Output string (existing content destroyed) |
| i | Integer value to convert |
| base | Numeric base (2-36), typically 10 or 16 |
| bool strFromUInt32 | ( | strhandle | out, |
| uint32 | i, | ||
| uint16 | base | ||
| ) |
Converts a 32-bit unsigned integer to a string
Formats the integer in the specified base. For bases > 10, lowercase letters are used (a-z).
| out | Output string (existing content destroyed) |
| i | Integer value to convert |
| base | Numeric base (2-36), typically 10 or 16 |
Example:
| bool strFromUInt64 | ( | strhandle | out, |
| uint64 | i, | ||
| uint16 | base | ||
| ) |
Converts a 64-bit unsigned integer to a string
Like strFromUInt32(), but for 64-bit values.
| out | Output string (existing content destroyed) |
| i | Integer value to convert |
| base | Numeric base (2-36), typically 10 or 16 |
| bool strToFloat32 | ( | float32 * | out, |
| strref | s, | ||
| bool | strict | ||
| ) |
Converts a string to a 32-bit floating-point value
Parses a string as a single-precision float. Supports standard decimal notation, scientific notation (e.g., "1.23e-4"), and special values ("inf", "nan"). Leading whitespace is skipped.
| out | Pointer to receive the parsed value |
| s | String to parse |
| strict | If true, entire string must be numeric; if false, trailing chars allowed |
Example:
| bool strToFloat64 | ( | float64 * | out, |
| strref | s, | ||
| bool | strict | ||
| ) |
Converts a string to a 64-bit floating-point value
Like strToFloat32(), but parses as double-precision. Supports decimal notation, scientific notation, and special values.
| out | Pointer to receive the parsed value |
| s | String to parse |
| strict | If true, entire string must be numeric; if false, trailing chars allowed |
Example:
| bool strToInt32 | ( | int32 * | out, |
| strref | s, | ||
| int | base, | ||
| bool | strict | ||
| ) |
Converts a string to a 32-bit signed integer
Parses a string as a signed integer in the specified base. Leading whitespace is skipped. An optional '+' or '-' sign is recognized. Hexadecimal strings may begin with "0x" or "0X".
Unlike strtol(), a leading '0' does NOT imply octal - base 10 is the default.
| out | Pointer to receive the parsed value |
| s | String to parse |
| base | Numeric base (2-36), or 0 for auto-detect (10 or 16) |
| strict | If true, entire string must be numeric; if false, trailing chars allowed |
Example:
| bool strToInt64 | ( | int64 * | out, |
| strref | s, | ||
| int | base, | ||
| bool | strict | ||
| ) |
Converts a string to a 64-bit signed integer
Like strToInt32(), but for 64-bit values.
| out | Pointer to receive the parsed value |
| s | String to parse |
| base | Numeric base (2-36), or 0 for auto-detect (10 or 16) |
| strict | If true, entire string must be numeric; if false, trailing chars allowed |
| bool strToUInt32 | ( | uint32 * | out, |
| strref | s, | ||
| int | base, | ||
| bool | strict | ||
| ) |
Converts a string to a 32-bit unsigned integer
Like strToInt32(), but parses as an unsigned value. A leading '-' sign is allowed and results in two's complement representation of the negative value.
| out | Pointer to receive the parsed value |
| s | String to parse |
| base | Numeric base (2-36), or 0 for auto-detect (10 or 16) |
| strict | If true, entire string must be numeric; if false, trailing chars allowed |
Example:
| bool strToUInt64 | ( | uint64 * | out, |
| strref | s, | ||
| int | base, | ||
| bool | strict | ||
| ) |
Converts a string to a 64-bit unsigned integer
Like strToUInt32(), but for 64-bit values.
| out | Pointer to receive the parsed value |
| s | String to parse |
| base | Numeric base (2-36), or 0 for auto-detect (10 or 16) |
| strict | If true, entire string must be numeric; if false, trailing chars allowed |