File syn_fmt.h¶
FileList > src > syntropic > util > syn_fmt.h
Go to the source code of this file
Lightweight formatting — no libc printf dependency. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h>
Public Functions¶
| Type | Name |
|---|---|
| size_t | syn_fmt_concat (char * buf, size_t size, const char *const * parts, size_t n) Build a string from parts (like snprintf but simpler). |
| size_t | syn_fmt_fixed (char * buf, size_t size, int32_t val, uint8_t places) Format a value with a fixed number of decimal places. |
| size_t | syn_fmt_hex (char * buf, size_t size, uint32_t val, uint8_t min_digits) Format a value as hex. |
| size_t | syn_fmt_hex_parse (const char * hex_str, uint8_t * out_bin, size_t max_bytes) Parse a hex string into a binary byte array. |
| size_t | syn_fmt_hexdump (char * buf, size_t size, const uint8_t * data, size_t len) Format a hex dump of a byte array. |
| size_t | syn_fmt_int (char * buf, size_t size, int32_t val) Format a signed integer to decimal string. |
| size_t | syn_fmt_q16 (char * buf, size_t size, int32_t q16_val, uint8_t frac_digits) Format a Q16.16 fixed-point value. |
| size_t | syn_fmt_uint (char * buf, size_t size, uint32_t val) Format an unsigned integer to decimal string. |
Public Static Functions¶
| Type | Name |
|---|---|
| uint32_t | syn_fmt_parse_uint (const char * s) Parse a decimal integer from a string. |
| bool | syn_str_prefix_icase (const char * str, const char * prefix) Case-insensitive prefix match (ASCII). |
Detailed Description¶
Integer-to-string, hex, fixed-point, and hex dump. All functions write to a caller-provided buffer and return the number of chars written (excluding null terminator).
** **
char buf[16];
syn_fmt_int(buf, sizeof(buf), -1234); // "-1234"
syn_fmt_hex(buf, sizeof(buf), 0xDEAD, 4); // "DEAD"
syn_fmt_q16(buf, sizeof(buf), val, 3); // "3.141"
Public Functions Documentation¶
function syn_fmt_concat¶
Build a string from parts (like snprintf but simpler).
Concatenate up to n string fragments into buf.
Parameters:
bufOutput buffer.sizeBuffer capacity.partsArray of string pointers.nNumber of strings.
Returns:
Total characters written.
function syn_fmt_fixed¶
Format a value with a fixed number of decimal places.
E.g., syn_fmt_fixed(buf, 16, 12345, 3) → "12.345"
Parameters:
bufOutput buffer.sizeBuffer capacity in bytes.valInteger value.placesNumber of decimal places from the right.
Returns:
Number of characters written.
function syn_fmt_hex¶
Format a value as hex.
Parameters:
bufOutput buffer.sizeBuffer capacity in bytes.valValue to format.min_digitsMinimum hex digits (zero-padded).
Returns:
Number of characters written.
function syn_fmt_hex_parse¶
Parse a hex string into a binary byte array.
Supports both uppercase and lowercase hex characters.
Parameters:
hex_strInput hex string.out_bin[out] Output binary byte buffer.max_bytesCapacity of out_bin in bytes.
Returns:
Number of binary bytes parsed.
function syn_fmt_hexdump¶
Format a hex dump of a byte array.
Output: "DE AD BE EF" (space-separated hex bytes).
Parameters:
bufOutput buffer.sizeBuffer capacity.dataByte array.lenNumber of bytes.
Returns:
Number of characters written.
function syn_fmt_int¶
Format a signed integer to decimal string.
Parameters:
bufOutput buffer.sizeBuffer capacity.valValue to format.
Returns:
Number of characters written (excluding null).
function syn_fmt_q16¶
Format a Q16.16 fixed-point value.
Parameters:
bufOutput buffer.sizeBuffer capacity in bytes.q16_valQ16.16 value to format.frac_digitsNumber of fractional decimal digits (1–6).
Returns:
Number of characters written.
function syn_fmt_uint¶
Format an unsigned integer to decimal string.
Parameters:
bufOutput buffer.sizeBuffer capacity.valValue to format.
Returns:
Number of characters written (excluding null).
Public Static Functions Documentation¶
function syn_fmt_parse_uint¶
Parse a decimal integer from a string.
Parameters:
sNull-terminated decimal string.
Returns:
Parsed unsigned 32-bit integer.
function syn_str_prefix_icase¶
Case-insensitive prefix match (ASCII).
Parameters:
strString to test.prefixPrefix to match.
Returns:
true if str starts with prefix (case-insensitive).
The documentation for this class was generated from the following file src/syntropic/util/syn_fmt.h