about summary refs log tree commit diff
path: root/sternenblog/stringutil.h
diff options
context:
space:
mode:
Diffstat (limited to 'sternenblog/stringutil.h')
-rw-r--r--sternenblog/stringutil.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/sternenblog/stringutil.h b/sternenblog/stringutil.h
new file mode 100644
index 0000000..c7cb40d
--- /dev/null
+++ b/sternenblog/stringutil.h
@@ -0,0 +1,27 @@
+/*!
+ * @file
+ * @brief Utilities for string construction
+ */
+
+/*!
+ * @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, ...);