about summary refs log tree commit diff
path: root/sternenblog/stringutil.h
blob: 11c678ff1e59c4944096f1efc1638ba3a65d1521 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*!
 * @file
 * @brief Utilities for string construction
 */

#ifndef STERNENBLOG_STRINGUTIL_H
#define STERNENBLOG_STRINGUTIL_H

/*!
 * @brief Returns hex digit for given integer
 *
 * Will return appropriate `char` in range 0-F
 * for input in range 0-15. Can be abused to
 * return decimal digits for range 0-9.
 */
char nibble_hex(short h);

/*!
 * @brief Concatenate arbitrary number of strings into
 * dynamically allocated buffer
 *
 * catn_alloc() concats the `n` given strings into a
 * dynamically allocated and resized buffer and returns
 * it. This buffer must be cleaned up by `free()` before
 * it goes out of scope.
 *
 * @param n number of strings given as `va_args`
 * @return pointer to concatenated strings or `NULL` on error.
 */
char *catn_alloc(size_t n, ...);

#endif