21 int cnvParse(
const char * input, uint32_t * output,
CnvParams p)
29 while (p.
len > 0 && ch !=
'\0')
32 if (ch >=
'0' && ch <=
'9') {
35 else if (ch >=
'A' && ch <=
'Z') {
36 v = ( ch -
'A' ) + 10;
38 else if (ch >=
'a' && ch <=
'z') {
39 v = ( ch -
'a' ) + 10;
63 if (p.
len == 0) p.
len = 12;
67 while (isblank(*input))
72 if (p.
len == 0)
return 0;
80 if (p.
len == 0)
return 0;
83 t = cnvParse(input, output, p);
97 if (p.
len == 0) p.
len = 13;
99 while (isspace(*input))
104 if (p.
len == 0)
return 0;
113 if (p.
len == 0)
return 0;
116 t = cnvParse(input, &v, p);
117 if (t == 0)
return 0;
120 *output = minus ? -v : v;
125 static uint32_t cnvFindDiv(uint32_t input,
CnvParams p)
129 while (input / div >= p.
base)
139 uint32_t div = cnvFindDiv(input, p);
144 digit = (input / div) % p.
base;
147 *output =
'0' + digit;
149 *output = (p.
uppercase ?
'A' :
'a') + (digit - 10);
181 int l = strlen(input);
185 memcpy(output, input, p.
len);
186 output[p.
len] =
'\0';
191 memcpy(output, input, l);
206 memcpy(output, input, l);
int cnvFormatU(int32_t input, char *output, CnvParams params)
Formats an unsigned integer into a character buffer.
bool alignleft
Aligning left instead of right (default)
int cnvParseI(const char *input, int32_t *output, CnvParams params)
Parse a signed integer.
int cnvParseU(const char *input, uint32_t *output, CnvParams params)
Parse an unsigned integer.
int cnvFormatI(int32_t input, char *output, CnvParams params)
Formats a signed integer into a character buffer.
bool uppercase
Format >10 base values with uppercase.
This structure provides information about formatting and parsing.
uint8_t base
Base of the number to format or parse.
void cnvFill(const char *input, char *output, CnvParams params)
Pads a string into a bigger buffer either prepending or postpending a padding character.
uint8_t len
Lenght of the buffer to format into or parse from.
This module implements parsing and formating of strings and integers.