Add bt_common_sep_digits()
[babeltrace.git] / src / common / common.h
index d5f2d096e89dd8f1b48754c9205ef7c9b636bd38..ef9a715fed9871aeb8c4310eb713f41993c0dc8f 100644 (file)
@@ -311,6 +311,22 @@ void bt_common_custom_snprintf(char *buf, size_t buf_size,
 BT_HIDDEN
 size_t bt_common_get_page_size(void);
 
+/*
+ * Adds the digit separator `sep` as many times as needed to form groups
+ * of `digits_per_group` digits within `str`. `str` must have enough
+ * room to accomodate the new separators, that is:
+ *
+ *     strlen(str) + (strlen(str) / digits_per_group) + 1
+ *
+ * Example: with `str` `1983198398213`, `digits_per_group` 3, and `sep`
+ * `,`, `str` becomes `1,983,198,398,213`.
+ *
+ * `strlen(str)` must not be 0. `digits_per_group` must not be 0. `sep`
+ * must not be `\0`.
+ */
+BT_HIDDEN
+void bt_common_sep_digits(char *str, unsigned int digits_per_group, char sep);
+
 /*
  * Wraps read() function to handle EINTR and partial reads.
  * On success, it returns `count` received as parameter. On error, it returns a
@@ -643,4 +659,5 @@ enum bt_self_message_iterator_status bt_common_message_iterator_status_to_self(
 {
        return (int) status;
 }
+
 #endif /* BABELTRACE_COMMON_INTERNAL_H */
This page took 0.024881 seconds and 4 git commands to generate.