aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils.c')
-rw-r--r--src/utils.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/utils.c b/src/utils.c
index 855b503..d7362a6 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -287,6 +287,27 @@ sb_str_replace(const char *str, const char search, const char *replace)
}
+char*
+sb_str_find(const char *str, char c)
+{
+ // this is somewhat similar to strchr, but respects '\' escaping.
+ if (str == NULL)
+ return NULL;
+ if (c == '\0')
+ return (char*) str + strlen(str);
+ for (size_t i = 0; str[i] != '\0'; i++) {
+ if (str[i] == '\\') {
+ i++;
+ continue;
+ }
+ if (str[i] == c) {
+ return (char*) str + i;
+ }
+ }
+ return NULL;
+}
+
+
void
sb_strv_free(char **strv)
{
@@ -425,6 +446,26 @@ sb_string_append_printf(sb_string_t *str, const char *format, ...)
}
+sb_string_t*
+sb_string_append_escaped(sb_string_t *str, const char *suffix)
+{
+ if (str == NULL)
+ return NULL;
+ if (suffix == NULL)
+ return str;
+ bool escaped = false;
+ for (size_t i = 0; suffix[i] != '\0'; i++) {
+ if (suffix[i] == '\\' && !escaped) {
+ escaped = true;
+ continue;
+ }
+ escaped = false;
+ str = sb_string_append_c(str, suffix[i]);
+ }
+ return str;
+}
+
+
sb_trie_t*
sb_trie_new(sb_free_func_t free_func)
{