File syn_fmt.c¶
FileList > src > syntropic > util > syn_fmt.c
Go to the source code of this file
Lightweight formatting — no libc printf dependency.
#include "syn_fmt.h"
Public Static Attributes¶
| Type | Name |
|---|---|
| const char | hex_chars = "0123456789ABCDEF"Hex digit lookup table. |
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 |
|---|---|
| int | hex_char_to_nibble (char c) |
| size_t | write_char (char * buf, size_t size, size_t pos, char c) Write a single char to the output buffer. |
| size_t | write_str (char * buf, size_t size, size_t pos, const char * s) Write a null-terminated string to the output buffer. |
Public Static Attributes Documentation¶
variable hex_chars¶
Hex digit lookup table.
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 hex_char_to_nibble¶
function write_char¶
Write a single char to the output buffer.
Parameters:
bufOutput buffer.sizeBuffer capacity.posCurrent write position.cCharacter to write.
Returns:
New position (may exceed size if truncated).
function write_str¶
Write a null-terminated string to the output buffer.
Parameters:
bufOutput buffer.sizeBuffer capacity.posCurrent write position.sString to write.
Returns:
New position.
The documentation for this class was generated from the following file src/syntropic/util/syn_fmt.c