summaryrefslogtreecommitdiff
path: root/src/strops.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-08-31 12:49:59 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-08-31 12:49:59 +0200
commitb970907ef53f1b8367285cbe7c2dc2a7fa47967f (patch)
tree73ec8747346393263e21ea72cffb6aa27d921c4a /src/strops.cpp
parent9fcfc3215a4caaa32872abc9cfc6deeb86b9765c (diff)
invoice templateing work
Diffstat (limited to 'src/strops.cpp')
-rw-r--r--src/strops.cpp25
1 files changed, 25 insertions, 0 deletions
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