summaryrefslogtreecommitdiff
path: root/src/strops.cpp
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2025-10-19 20:03:22 +0200
committerAldrik Ramaekers <aldrikboy@gmail.com>2025-10-19 20:03:22 +0200
commit3e85a8e6db1a9c9a7fcf7974a1a0307b2cb145bd (patch)
tree16d611d9190bcf4939dd054909cb3a41a6d20fb7 /src/strops.cpp
parent7aea21f2a30e0aa3bc75a579bd01ff9746470c05 (diff)
strops and memops refactor
Diffstat (limited to 'src/strops.cpp')
-rw-r--r--src/strops.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/strops.cpp b/src/strops.cpp
index efa91e6..2dfbf16 100644
--- a/src/strops.cpp
+++ b/src/strops.cpp
@@ -24,14 +24,14 @@ namespace strops {
bool is_prefixed(const char *pre, const char *str)
{
- return strncmp(pre, str, strlen(pre)) == 0;
+ return strncmp(pre, str, strops::length(pre)) == 0;
}
size_t copy(char *dst, const char *src, size_t size)
{
size_t srclen;
size --;
- srclen = strlen(src);
+ srclen = strops::length(src);
if (srclen > size)
srclen = size;
@@ -47,6 +47,16 @@ namespace strops {
return strcmp(a, b) == 0;
}
+ size_t length(const char* str)
+ {
+ return strlen(str);
+ }
+
+ bool empty(const char* str)
+ {
+ return strlen(str) == 0;
+ }
+
char* contains(char* haystack, char* needle)
{
do {
@@ -85,8 +95,8 @@ namespace strops {
void 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);
+ size_t search_len = strops::length(search);
+ size_t replace_len = strops::length(replace);
char *r = buf; // read pointer
char *w = buf; // write pointer