summaryrefslogtreecommitdiff
path: root/src/strops.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/strops.cpp')
-rw-r--r--src/strops.cpp31
1 files changed, 30 insertions, 1 deletions
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 <string.h>
#include <ctype.h>
+#include <stdio.h>
#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