KM3NeT CLB  2.0
KM3NeT CLB v2 Embedded Software
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
convert.h File Reference

This module implements parsing and formating of strings and integers. More...

#include <stdint.h>
#include <stdbool.h>

Go to the source code of this file.

Data Structures

struct  CnvParams
 This structure provides information about formatting and parsing. More...
 

Macros

#define CONVERT_H_
 
#define CNV_BASE_DEC   10
 Base for decimal numbers.
 
#define CNV_BASE_BIN   2
 Base for binary numbers.
 
#define CNV_BASE_HEX   16
 Base of hex numbers.
 
#define CNV_DEFAULT
 Default conversion/formatting parameters (base 10). More...
 
#define CNV_DEFAULT_HEX
 

Functions

int cnvParseI (const char *input, int32_t *output, CnvParams params)
 Parse a signed integer. More...
 
int cnvParseU (const char *input, uint32_t *output, CnvParams params)
 Parse an unsigned integer. More...
 
int cnvFormatI (int32_t input, char *output, CnvParams params)
 Formats a signed integer into a character buffer. More...
 
int cnvFormatU (int32_t input, char *output, CnvParams params)
 Formats an unsigned integer into a character buffer. More...
 
void cnvFill (const char *input, char *output, CnvParams params)
 Pads a string into a bigger buffer either prepending or postpending a padding character. More...
 

Detailed Description

This module implements parsing and formating of strings and integers.

Definition in file convert.h.

Macro Definition Documentation

#define CNV_DEFAULT
Value:
{ \
.base = 10, \
.len = 0, \
.fill = ' ', \
.uppercase = false, \
.alignleft = false \
}

Default conversion/formatting parameters (base 10).

Definition at line 47 of file convert.h.

#define CNV_DEFAULT_HEX
Value:
{ \
.base = 16, \
.len = 0, \
.fill = '0', \
.uppercase = false, \
.alignleft = false \
}

Definition at line 56 of file convert.h.

Function Documentation

void cnvFill ( const char *  input,
char *  output,
CnvParams  params 
)

Pads a string into a bigger buffer either prepending or postpending a padding character.

Parameters
inputThe input string to pad
outputThe output buffer in which the padding is done
paramsThe conversion parameters.

Definition at line 179 of file convert.c.

int cnvFormatI ( int32_t  input,
char *  output,
CnvParams  params 
)

Formats a signed integer into a character buffer.

Parameters
inputThe value to format
outputThe output buffer to write into
paramsThe conversino parameters
Returns
The number of characters formatted

Definition at line 160 of file convert.c.

int cnvFormatU ( int32_t  input,
char *  output,
CnvParams  params 
)

Formats an unsigned integer into a character buffer.

Parameters
inputThe value to format
outputThe output buffer to write into
paramsThe conversion parameters
Returns
The number of characters formatted

Definition at line 137 of file convert.c.

int cnvParseI ( const char *  input,
int32_t *  output,
CnvParams  params 
)

Parse a signed integer.

Parameters
inputThe input buffer
outputA pointer to the variable to write the parsed value into.
paramsThe conversion parameters
Returns
The number of characters processed.

Definition at line 90 of file convert.c.

int cnvParseU ( const char *  input,
uint32_t *  output,
CnvParams  params 
)

Parse an unsigned integer.

Parameters
inputThe input buffer
outputA pointer to the variable to write the parsed value into.
paramsThe conversion parameters
Returns
The number of characters processed.

Definition at line 61 of file convert.c.