From b970907ef53f1b8367285cbe7c2dc2a7fa47967f Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Sun, 31 Aug 2025 12:49:59 +0200 Subject: invoice templateing work --- src/strops.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/strops.cpp') diff --git a/src/strops.cpp b/src/strops.cpp index 116eec4..3389eb1 100644 --- a/src/strops.cpp +++ b/src/strops.cpp @@ -32,4 +32,29 @@ char* strops_stristr(char* haystack, char* needle) } } while (*haystack++); return 0; +} + +void strops_replace(char *buf, size_t buf_size, const char *search, const char *replace) +{ + size_t search_len = strlen(search); + size_t replace_len = strlen(replace); + + char *r = buf; // read pointer + char *w = buf; // write pointer + + while (*r && (w - buf) < (signed int)(buf_size - 1)) { + if (strncmp(r, search, search_len) == 0) { + // Ensure space + size_t remaining = buf_size - (w - buf) - 1; + size_t copy_len = (replace_len < remaining) ? replace_len : remaining; + + memcpy(w, replace, copy_len); + w += copy_len; + r += search_len; + } else { + *w++ = *r++; + } + } + + *w = '\0'; // terminate } \ No newline at end of file -- cgit v1.2.3-70-g09d2