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_reverse(char *out, const uint8_t *ptr, size_t n);
78 
91 size_t fmt_u32_hex(char *out, uint32_t val);
92 
105 size_t fmt_u64_hex(char *out, uint64_t val);
106 
118 size_t fmt_u32_dec(char *out, uint32_t val);
119 
133 size_t fmt_u64_dec(char *out, uint64_t val);
134 
146 size_t fmt_u16_dec(char *out, uint16_t val);
147 
161 size_t fmt_s32_dec(char *out, int32_t val);
162 
176 size_t fmt_s16_dec(char *out, int16_t val);
177 
204 size_t fmt_s16_dfp(char *out, int16_t val, unsigned fp_digits);
205 
232 size_t fmt_s32_dfp(char *out, int32_t val, unsigned fp_digits);
233 
250 size_t fmt_float(char *out, float f, unsigned precision);
251 
259 size_t fmt_strlen(const char *str);
260 
272 size_t fmt_str(char *out, const char *str);
273 
284 uint32_t scn_u32_dec(const char *str, size_t n);
285 
294 void print(const char* s, size_t n);
295 
301 void print_u32_dec(uint32_t val);
302 
308 void print_s32_dec(int32_t val);
309 
315 void print_byte_hex(uint8_t byte);
316 
322 void print_u32_hex(uint32_t val);
323 
329 void print_u64_hex(uint64_t val);
330 
338 void print_u64_dec(uint64_t val);
339 
348 void print_float(float f, unsigned precision);
349 
357 void print_str(const char* str);
358 
382 size_t fmt_lpad(char *str, size_t in_len, size_t pad_len, char pad_char);
383 
384 #ifdef __cplusplus
385 }
386 #endif
387 
389 #endif /* FMT_H */
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.
size_t fmt_s16_dfp(char *out, int16_t val, unsigned fp_digits)
Convert 16-bit fixed point number to a decimal string.
void print_str(const char *str)
Print null-terminated string to stdout.
size_t fmt_s16_dec(char *out, int16_t val)
Convert a int16 value to decimal string.
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.
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_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, unsigned fp_digits)
Convert 32-bit fixed point number to a decimal string.
void print_s32_dec(int32_t val)
Print int32 value to stdout.