GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_strconv.h File Reference

Simple function to convert integers to ascii strings and back. More...

#include <stdbool.h>
#include <stdint.h>
#include <limits.h>
#include <core/gp_common.h>

Go to the source code of this file.

Functions

static size_t gp_u32toa (char *dst, uint32_t val, bool null_terminate)
 Converts an unsigned 32bit integer into an ascii representation.
 
static size_t gp_u64toa (char *dst, uint64_t val, bool null_terminate)
 Converts an unsigned 64bit integer into an ascii representation.
 
static size_t gp_utoa (char *dst, unsigned int val, bool null_terminate)
 Converts an unsigned integer into an ascii representation.
 
static size_t gp_lutoa (char *dst, unsigned long val, bool null_terminate)
 Converts an unsigned long into an ascii representation.
 
static size_t gp_llutoa (char *dst, unsigned long long val, bool null_terminate)
 Converts an unsigned long long into an ascii representation.
 
static ssize_t gp_atou32 (const char *src, size_t src_len, uint32_t *dst)
 Converts an ASCII string into an unsigned 32bit integer.
 
static ssize_t gp_atou64 (const char *src, size_t src_len, uint64_t *dst)
 Converts an ASCII string into an unsigned 64bit integer.
 
static ssize_t gp_atou (const char *src, size_t src_len, unsigned int *dst)
 Converts an ASCII string into an unsigned integer.
 
static ssize_t gp_atolu (const char *src, size_t src_len, unsigned long *dst)
 Converts an ASCII string into an unsigned long.
 
static ssize_t gp_atollu (const char *src, size_t src_len, unsigned long long *dst)
 Converts an ASCII string into an unsigned long long.
 

Detailed Description

Simple function to convert integers to ascii strings and back.

Definition in file gp_strconv.h.

Function Documentation

◆ gp_atollu()

static ssize_t gp_atollu ( const char * src,
size_t src_len,
unsigned long long * dst )
inlinestatic

Converts an ASCII string into an unsigned long long.

Converts start of the string into an unsigned long long. The conversion stop either at the end of the string or at first non-numeric character.

Parameters
srcA source string. The string must be either nul byte terminated or non-zero src_len has to be passed.
src_lenA number of bytes in src, if zero the string is expected to be nul byte terminated.
dstA pointer to an unsigned long long.
Returns
A number of bytes converted, -1 on overflow.

Definition at line 320 of file gp_strconv.h.

References gp_atou32(), and gp_atou64().

◆ gp_atolu()

static ssize_t gp_atolu ( const char * src,
size_t src_len,
unsigned long * dst )
inlinestatic

Converts an ASCII string into an unsigned long.

Converts start of the string into an unsigned long. The conversion stop either at the end of the string or at first non-numeric character.

Parameters
srcA source string. The string must be either nul byte terminated or non-zero src_len has to be passed.
src_lenA number of bytes in src, if zero the string is expected to be nul byte terminated.
dstA pointer to an unsigned long.
Returns
A number of bytes converted, -1 on overflow.

Definition at line 296 of file gp_strconv.h.

References gp_atou32(), and gp_atou64().

◆ gp_atou()

static ssize_t gp_atou ( const char * src,
size_t src_len,
unsigned int * dst )
inlinestatic

Converts an ASCII string into an unsigned integer.

Converts start of the string into an unsigned integer. The conversion stop either at the end of the string or at first non-numeric character.

Parameters
srcA source string. The string must be either nul byte terminated or non-zero src_len has to be passed.
src_lenA number of bytes in src, if zero the string is expected to be nul byte terminated.
dstA pointer to an unsigned integer.
Returns
A number of bytes converted, -1 on overflow.

Definition at line 272 of file gp_strconv.h.

References gp_atou32(), and gp_atou64().

◆ gp_atou32()

static ssize_t gp_atou32 ( const char * src,
size_t src_len,
uint32_t * dst )
inlinestatic

Converts an ASCII string into an unsigned 32bit integer.

Converts start of the string into an unsigned 32bit integer. The conversion stop either at the end of the string or at first non-numeric character.

Parameters
srcA source string. The string must be either nul byte terminated or non-zero src_len has to be passed.
src_lenA number of bytes in src, if zero the string is expected to be nul byte terminated.
dstA pointer to an unsigned 32bit integer.
Returns
A number of bytes converted, -1 on overflow.

Definition at line 196 of file gp_strconv.h.

Referenced by gp_atollu(), gp_atolu(), and gp_atou().

◆ gp_atou64()

static ssize_t gp_atou64 ( const char * src,
size_t src_len,
uint64_t * dst )
inlinestatic

Converts an ASCII string into an unsigned 64bit integer.

Converts start of the string into an unsigned 64bit integer. The conversion stop either at the end of the string or at first non-numeric character.

Parameters
srcA source string. The string must be either nul byte terminated or non-zero src_len has to be passed.
src_lenA number of bytes in src, if zero the string is expected to be nul byte terminated.
dstA pointer to an unsigned 64bit integer.
Returns
A number of bytes converted, -1 on overflow.

Definition at line 234 of file gp_strconv.h.

Referenced by gp_atollu(), gp_atolu(), and gp_atou().

◆ gp_llutoa()

static size_t gp_llutoa ( char * dst,
unsigned long long val,
bool null_terminate )
inlinestatic

Converts an unsigned long long into an ascii representation.

The buffer must be large enough to fit the value. You can run the function with NULL dst to get the exact buffer size for the conversion.

Parameters
dstA buffer to write the bytes into. If NULL no bytes are written.
valAn unsigned integer value to be converted to ascii.
null_terminateIf set the string is null terminated.
Returns
A number of bytes written.

Definition at line 169 of file gp_strconv.h.

References gp_u32toa(), and gp_u64toa().

◆ gp_lutoa()

static size_t gp_lutoa ( char * dst,
unsigned long val,
bool null_terminate )
inlinestatic

Converts an unsigned long into an ascii representation.

The buffer must be large enough to fit the value. You can run the function with NULL dst to get the exact buffer size for the conversion.

Parameters
dstA buffer to write the bytes into. If NULL no bytes are written.
valAn unsigned integer value to be converted to ascii.
null_terminateIf set the string is null terminated.
Returns
A number of bytes written.

Definition at line 147 of file gp_strconv.h.

References gp_u32toa(), and gp_u64toa().

◆ gp_u32toa()

static size_t gp_u32toa ( char * dst,
uint32_t val,
bool null_terminate )
inlinestatic

Converts an unsigned 32bit integer into an ascii representation.

The buffer must be large enough to fit the value. Maximal number of digits for unsigned 32bit integer is 10 not including the terminating nul character.

You can run the function with NULL dst to get the exact buffer size for the conversion.

Parameters
dstA buffer to write the bytes into. If NULL no bytes are written.
valAn unsigned integer value to be converted to ascii.
null_terminateIf set the string is null terminated.
Returns
A number of bytes written.

Definition at line 53 of file gp_strconv.h.

Referenced by gp_llutoa(), gp_lutoa(), and gp_utoa().

◆ gp_u64toa()

static size_t gp_u64toa ( char * dst,
uint64_t val,
bool null_terminate )
inlinestatic

Converts an unsigned 64bit integer into an ascii representation.

The buffer must be large enough to fit the value. Maximal number of digits for unsigned 64bit integer is 20 not including the terminating nul character.

You can run the function with NULL dst to get the exact buffer size for the conversion.

Parameters
dstA buffer to write the bytes into. If NULL no bytes are written.
valAn unsigned integer value to be converted to ascii.
null_terminateIf set the string is null terminated.
Returns
A number of bytes written.

Definition at line 91 of file gp_strconv.h.

Referenced by gp_llutoa(), gp_lutoa(), and gp_utoa().

◆ gp_utoa()

static size_t gp_utoa ( char * dst,
unsigned int val,
bool null_terminate )
inlinestatic

Converts an unsigned integer into an ascii representation.

The buffer must be large enough to fit the value. You can run the function with NULL dst to get the exact buffer size for the conversion.

Parameters
dstA buffer to write the bytes into. If NULL no bytes are written.
valAn unsigned integer value to be converted to ascii.
null_terminateIf set the string is null terminated.
Returns
A number of bytes written.

Definition at line 125 of file gp_strconv.h.

References gp_u32toa(), and gp_u64toa().