fmt.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Kaspar Schleiser <kaspar@schleiser.de>
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
34 #ifndef FMT_H
35 #define FMT_H
36 
37 #include <stdint.h>
38 #include <stddef.h>
39 
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43 
44 #ifndef FMT_USE_MEMMOVE
45 #define FMT_USE_MEMMOVE (1)
46 #endif
47 
62 size_t fmt_byte_hex(char *out, uint8_t byte);
63 
77 size_t fmt_bytes_hex(char *out, const uint8_t *ptr, size_t n);
78 
92 size_t fmt_bytes_hex_reverse(char *out, const uint8_t *ptr, size_t n);
93 
109 size_t fmt_hex_bytes(uint8_t *out, const char *hex);
110 
123 size_t fmt_u32_hex(char *out, uint32_t val);
124 
137 size_t fmt_u64_hex(char *out, uint64_t val);
138 
150 size_t fmt_u32_dec(char *out, uint32_t val);
151 
165 size_t fmt_u64_dec(char *out, uint64_t val);
166 
178 size_t fmt_u16_dec(char *out, uint16_t val);
179 
193 size_t fmt_s64_dec(char *out, int64_t val);
194 
208 size_t fmt_s32_dec(char *out, int32_t val);
209 
223 size_t fmt_s16_dec(char *out, int16_t val);
224 
237 size_t fmt_s16_dfp(char *out, int16_t val, int fp_digits);
238 
264 size_t fmt_s32_dfp(char *out, int32_t val, int fp_digits);
265 
286 size_t fmt_float(char *out, float f, unsigned precision);
287 
295 size_t fmt_strlen(const char *str);
296 
306 size_t fmt_strnlen(const char *str, size_t maxlen);
307 
319 size_t fmt_str(char *out, const char *str);
320 
331 uint32_t scn_u32_dec(const char *str, size_t n);
332 
341 void print(const char* s, size_t n);
342 
348 void print_u32_dec(uint32_t val);
349 
355 void print_s32_dec(int32_t val);
356 
362 void print_byte_hex(uint8_t byte);
363 
369 void print_u32_hex(uint32_t val);
370 
376 void print_u64_hex(uint64_t val);
377 
385 void print_u64_dec(uint64_t val);
386 
398 void print_float(float f, unsigned precision);
399 
405 void print_str(const char* str);
406 
430 size_t fmt_lpad(char *str, size_t in_len, size_t pad_len, char pad_char);
431 
432 #ifdef __cplusplus
433 }
434 #endif
435 
437 #endif /* FMT_H */
size_t fmt_s64_dec(char *out, int64_t val)
Convert a int64 value to decimal string.
void print(const char *s, size_t n)
Print string to stdout.
size_t fmt_s32_dec(char *out, int32_t val)
Convert a int32 value to decimal string.
size_t fmt_float(char *out, float f, unsigned precision)
Format float to string.
size_t fmt_lpad(char *str, size_t in_len, size_t pad_len, char pad_char)
Pad string to the left.
void print_str(const char *str)
Print null-terminated string to stdout.
size_t fmt_strnlen(const char *str, size_t maxlen)
Count at most maxlen characters until &#39;\0&#39; (exclusive) in str.
size_t fmt_s16_dec(char *out, int16_t val)
Convert a int16 value to decimal string.
size_t fmt_bytes_hex(char *out, const uint8_t *ptr, size_t n)
Formats a sequence of bytes as hex bytes.
void print_byte_hex(uint8_t byte)
Print byte value as hex to stdout.
size_t fmt_strlen(const char *str)
Count characters until &#39;\0&#39; (exclusive) in str.
void print_float(float f, unsigned precision)
Print float value.
size_t fmt_s16_dfp(char *out, int16_t val, int fp_digits)
Convert 16-bit fixed point number to a decimal string.
void print_u64_hex(uint64_t val)
Print uint64 value as hex to stdout.
size_t fmt_u32_dec(char *out, uint32_t val)
Convert a uint32 value to decimal string.
size_t fmt_bytes_hex_reverse(char *out, const uint8_t *ptr, size_t n)
Formats a sequence of bytes as hex bytes, starting with the last byte.
size_t fmt_u64_hex(char *out, uint64_t val)
Convert a uint64 value to hex string.
void print_u64_dec(uint64_t val)
Print uint64 value as decimal to stdout.
void print_u32_hex(uint32_t val)
Print uint32 value as hex to stdout.
size_t fmt_u32_hex(char *out, uint32_t val)
Convert a uint32 value to hex string.
size_t fmt_byte_hex(char *out, uint8_t byte)
Format a byte value as hex.
void print_u32_dec(uint32_t val)
Print uint32 value to stdout.
size_t fmt_u16_dec(char *out, uint16_t val)
Convert a uint16 value to decimal string.
size_t fmt_hex_bytes(uint8_t *out, const char *hex)
Converts a sequence of hex bytes to an array of bytes.
size_t fmt_u64_dec(char *out, uint64_t val)
Convert a uint64 value to decimal string.
size_t fmt_str(char *out, const char *str)
Copy null-terminated string (excluding terminating \0)
uint32_t scn_u32_dec(const char *str, size_t n)
Convert digits to uint32.
size_t fmt_s32_dfp(char *out, int32_t val, int fp_digits)
Convert 32-bit fixed point number to a decimal string.
void print_s32_dec(int32_t val)
Print int32 value to stdout.