From 68d0ef1586a90ddef6d0cef7ebd593828282c76a Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sat, 6 Sep 2025 11:58:12 +0200 Subject: working on invoice templates --- src/strops.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'src/strops.cpp') diff --git a/src/strops.cpp b/src/strops.cpp index 3389eb1..208aaed 100644 --- a/src/strops.cpp +++ b/src/strops.cpp @@ -1,5 +1,6 @@ #include #include +#include #include "strops.hpp" @@ -47,14 +48,42 @@ void strops_replace(char *buf, size_t buf_size, const char *search, const char * // Ensure space size_t remaining = buf_size - (w - buf) - 1; size_t copy_len = (replace_len < remaining) ? replace_len : remaining; + size_t skip_size = search_len; + + if (replace_len > search_len) + { + memmove(w+replace_len, w+search_len, remaining - replace_len); + skip_size = replace_len; + } memcpy(w, replace, copy_len); w += copy_len; - r += search_len; + r += skip_size; } else { *w++ = *r++; } } *w = '\0'; // terminate +} + +void strops_replace_int32(char *buf, size_t buf_size, const char *search, int32_t number) +{ + char num_buf[200]; + snprintf(num_buf, 200, "%d", number); + strops_replace(buf, buf_size, search, num_buf); +} + +void strops_replace_int64(char *buf, size_t buf_size, const char *search, int64_t number) +{ + char num_buf[200]; + snprintf(num_buf, 200, "%lld", number); + strops_replace(buf, buf_size, search, num_buf); +} + +void strops_replace_float(char *buf, size_t buf_size, const char *search, float number, int decimals) +{ + char num_buf[200]; + snprintf(num_buf, 200, "%.*f", decimals, number); + strops_replace(buf, buf_size, search, num_buf); } \ No newline at end of file -- cgit v1.2.3-70-g09d2