solidc
Robust collection of general-purpose cross-platform C libraries and data structures designed for rapid and safe development in C
Loading...
Searching...
No Matches
Functions
str_to_num.h File Reference

String to number conversion utilities. More...

#include <stdbool.h>
#include <stdint.h>
Include dependency graph for str_to_num.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

StoError str_to_u8 (const char *str, uint8_t *result)
 Converts a string to a uint8_t.
 
StoError str_to_i8 (const char *str, int8_t *result)
 Converts a string to an int8_t.
 
StoError str_to_u16 (const char *str, uint16_t *result)
 Converts a string to a uint16_t.
 
StoError str_to_i16 (const char *str, int16_t *result)
 Converts a string to an int16_t.
 
StoError str_to_u32 (const char *str, uint32_t *result)
 Converts a string to a uint32_t.
 
StoError str_to_i32 (const char *str, int32_t *result)
 Converts a string to an int32_t.
 
StoError str_to_u64 (const char *str, uint64_t *result)
 Converts a string to a uint64_t.
 
StoError str_to_i64 (const char *str, int64_t *result)
 Converts a string to an int64_t.
 
StoError str_to_ulong (const char *str, unsigned long *result)
 Converts a string to an unsigned long.
 
StoError str_to_long (const char *str, long *result)
 Converts a string to a long.
 
StoError str_to_double (const char *str, double *result)
 Converts a string to a double.
 
StoError str_to_float (const char *str, float *result)
 Converts a string to a float.
 
StoError str_to_uint (const char *str, unsigned int *result)
 Converts a string to an unsigned int.
 
StoError str_to_uintptr (const char *str, uintptr_t *result)
 Converts a string to a uintptr_t.
 
StoError str_to_int (const char *str, int *result)
 Converts a string to an int.
 
StoError str_to_ulong_base (const char *str, int base, unsigned long *result)
 Converts a string to an unsigned long with a specified base.
 
StoError str_to_long_base (const char *str, int base, long *result)
 Converts a string to a long with a specified base.
 
StoError str_to_int_base (const char *str, int base, int *result)
 Converts a string to an int with a specified base.
 
StoError str_to_bool (const char *str, bool *result)
 Converts a string to a boolean. Valid inputs are "true", "false", "yes", "no", "1", "0", "on", "off".
 
const char * sto_error_string (StoError code)
 

Detailed Description

String to number conversion utilities.

Definition in file str_to_num.h.

Function Documentation

◆ sto_error_string()

const char * sto_error_string ( StoError  code)

Report the numerical conversion error from code.

Definition at line 273 of file str_to_num.c.

References sto_error_string().

Referenced by sto_error_string().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ str_to_bool()

StoError str_to_bool ( const char *  str,
bool *  result 
)

Converts a string to a boolean. Valid inputs are "true", "false", "yes", "no", "1", "0", "on", "off".

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_INVALID if invalid input.

Definition at line 257 of file str_to_num.c.

References str_to_bool().

Referenced by str_to_bool().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ str_to_double()

StoError str_to_double ( const char *  str,
double *  result 
)

Converts a string to a double.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

Definition at line 229 of file str_to_num.c.

References str_to_double().

Referenced by str_to_double().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ str_to_float()

StoError str_to_float ( const char *  str,
float *  result 
)

Converts a string to a float.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

Definition at line 213 of file str_to_num.c.

References str_to_float().

Referenced by str_to_float().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ str_to_i16()

StoError str_to_i16 ( const char *  str,
int16_t *  result 
)

Converts a string to an int16_t.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_i32()

StoError str_to_i32 ( const char *  str,
int32_t *  result 
)

Converts a string to an int32_t.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_i64()

StoError str_to_i64 ( const char *  str,
int64_t *  result 
)

Converts a string to an int64_t.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_i8()

StoError str_to_i8 ( const char *  str,
int8_t *  result 
)

Converts a string to an int8_t.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_int()

StoError str_to_int ( const char *  str,
int *  result 
)

Converts a string to an int.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_int_base()

StoError str_to_int_base ( const char *  str,
int  base,
int *  result 
)

Converts a string to an int with a specified base.

Parameters
strThe input string.
baseThe base for conversion.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_long()

StoError str_to_long ( const char *  str,
long *  result 
)

Converts a string to a long.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_long_base()

StoError str_to_long_base ( const char *  str,
int  base,
long *  result 
)

Converts a string to a long with a specified base.

Parameters
strThe input string.
baseThe base for conversion.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_u16()

StoError str_to_u16 ( const char *  str,
uint16_t *  result 
)

Converts a string to a uint16_t.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_u32()

StoError str_to_u32 ( const char *  str,
uint32_t *  result 
)

Converts a string to a uint32_t.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_u64()

StoError str_to_u64 ( const char *  str,
uint64_t *  result 
)

Converts a string to a uint64_t.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_u8()

StoError str_to_u8 ( const char *  str,
uint8_t *  result 
)

Converts a string to a uint8_t.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_uint()

StoError str_to_uint ( const char *  str,
unsigned int *  result 
)

Converts a string to an unsigned int.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_uintptr()

StoError str_to_uintptr ( const char *  str,
uintptr_t *  result 
)

Converts a string to a uintptr_t.

uintptr_t is an unsigned integer type that is capable of storing a data pointer.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_INVALID if invalid input.

Definition at line 196 of file str_to_num.c.

◆ str_to_ulong()

StoError str_to_ulong ( const char *  str,
unsigned long *  result 
)

Converts a string to an unsigned long.

Parameters
strThe input string.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.

◆ str_to_ulong_base()

StoError str_to_ulong_base ( const char *  str,
int  base,
unsigned long *  result 
)

Converts a string to an unsigned long with a specified base.

Parameters
strThe input string.
baseThe base for conversion.
resultPointer to the result variable.
Returns
StoError STO_SUCCESS on success, STO_OVERFLOW if out of range, STO_INVALID if invalid input.