summaryrefslogtreecommitdiff
path: root/project-base/src/string_utils.h
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrikboy@gmail.com>2024-11-23 22:33:43 +0100
committerAldrik Ramaekers <aldrikboy@gmail.com>2024-11-23 22:33:43 +0100
commitb1e857cf1471d1871a9396696b22fa531da98249 (patch)
tree3923008a8653057698cb339faf6dcfa92e18364b /project-base/src/string_utils.h
parent106bb7fcadf637cec883648916cc8d19529d6199 (diff)
add projbase to repo
Diffstat (limited to 'project-base/src/string_utils.h')
-rw-r--r--project-base/src/string_utils.h109
1 files changed, 109 insertions, 0 deletions
diff --git a/project-base/src/string_utils.h b/project-base/src/string_utils.h
new file mode 100644
index 0000000..d59acda
--- /dev/null
+++ b/project-base/src/string_utils.h
@@ -0,0 +1,109 @@
+/*
+* BSD 2-Clause “Simplified” License
+* Copyright (c) 2019, Aldrik Ramaekers, aldrik.ramaekers@protonmail.com
+* All rights reserved.
+*/
+
+#ifndef INCLUDE_STRING_UTILS
+#define INCLUDE_STRING_UTILS
+
+#if 0
+printf("[lll][llll*] : %d\n", string_contains("lll", "llll*"));
+printf("[lllll][l*lop] : %d\n", string_contains("lllll", "l*lop"));
+printf("[22lllll][l*l] : %d\n", string_contains("22lllll", "l*l"));
+
+printf("[hello world][h?lo] : %d\n", string_contains("hello world", "h?lo"));
+printf("[\"hello sailor\"][sailor] : %d\n", string_contains(" wsdf asd \"hello sailor\" asdf asdf ", "sailor"));
+printf("[\"hello sailor\"][*sailor] : %d\n", string_contains(" wsdf asd \"hello sailor\" asdf asdf ", "*sailor"));
+printf("\n");
+
+printf("[\"hello sailor\"][*sailor\"] : %d\n", string_contains(" wsdf asd \"hello sailor\" asdf asdf ", "*sailor\""));
+printf("[\"hello sailor\"][*sailor*] : %d\n", string_contains(" wsdf asd \"hello sailor\" asdf asdf ", "*sailor*"));
+printf("[\"hello sailor\"][sailor*] : %d\n", string_contains(" wsdf asd \"hello sailor\" asdf asdf ", "sailor*"));
+printf("[22lllll pi23hjp rbksje LSKJDh l][LS*] : %d\n",
+ string_contains("22lllll pi23hjp rbksje LSKJDh l", "LS*"));
+printf("[22lllll lal][l*l] : %d\n", string_contains("22lllll lal", "l*l"));
+printf("[22lllll][*l*l] : %d\n", string_contains("lllll", "*l*l"));
+printf("[hello world][hello] : %d\n", string_contains("hello world", "hello"));
+printf("[hello world][h?llo] : %d\n", string_contains("hello world", "h?llo"));
+printf("[hello world][h????] : %d\n", string_contains("hello world", "h????"));
+printf("[hello world][h*lo] : %d\n", string_contains("hello world", "h*lo"));
+printf("[hello world][*] : %d\n", string_contains("hello world", "*"));
+printf("[hello world][h*] : %d\n", string_contains("hello world", "h*"));
+printf("[hello world][*o] : %d\n", string_contains("hello world", "*o"));
+printf("[hello world][h*o] : %d\n", string_contains("hello world", "h*o"));
+printf("[hello world][*lo] : %d\n", string_contains("hello world", "*lo"));
+printf("[hello world][hel*lo] : %d\n", string_contains("hello world", "hel*lo"));
+
+printf("[lllll][l*l] : %d\n", string_contains("lllll", "l*l"));
+printf("[llllllll][l*llll] : %d\n", string_contains("lllll", "l*llll"));
+printf("[llllllll][l*lll] : %d\n", string_contains("lllll", "l*lll"));
+printf("[llllllll][llll*l] : %d\n", string_contains("lllll", "llll*l"));
+printf("[llllllll][*] : %d\n", string_contains("lllll", "*"));
+printf("[lllll][l?lll] : %d\n", string_contains("lllll", "l?lll"));
+
+printf("[lllll][lllll] : %d\n", string_contains("lllll", "lllll"));
+printf("[lllll][*llll] : %d\n", string_contains("lllll", "*llll"));
+printf("[lllll][llll*] : %d\n", string_contains("lllll", "llll*"));
+printf("[lllll][*llll*] : %d\n", string_contains("lllll", "*llll*"));
+printf("[lllll][*lllll*] : %d\n", string_contains("lllll", "*lllll*"));
+printf("[lllll][*ll*] : %d\n", string_contains("lllll", "*ll*"));
+#endif
+
+typedef struct t_text_match
+{
+ u32 line_nr;
+ s32 word_offset;
+ s32 word_match_len;
+ char *line_start;
+ char *line_info;
+} text_match;
+
+#define string_contains(big, small) string_contains_ex(big, small, 0, 0)
+
+bool string_match(char *first, char *second);
+bool string_equals(char *first, char *second);
+bool string_contains_ex(char *big, char *sml, array *text_matches, bool *cancel_search);
+
+s32 string_length(char *buffer);
+array string_split(char *text);
+void string_copyn(char *buffer, char *text, s32 bufferlen);
+
+void string_trim(char *string);
+void string_append(char *buffer, char *text);
+void string_appendn(char *buffer, char *text, s32 bufferlen);
+void string_appendf(char *buffer, char *text);
+bool string_remove(char **buffer, char *text);
+void string_convert_crlf_to_lf(char *buffer);
+
+char* string_get_json_literal(char **buffer, char *tmp); // @Unused
+s32 string_get_json_number(char **buffer); // @Unused
+s32 string_get_json_ulong_number(char **buffer); // @Unused
+char* string_get_next(char *list, char *buffer, char seperator); // @Unused
+
+bool string_is_asteriks(char *text);
+bool string_is_whitespace(char *text);
+bool string_is_numeric(char *str);
+
+utf8_int32_t utf8_str_at(char *str, s32 index);
+void utf8_str_remove_at(char *str, s32 at);
+void utf8_str_remove_range(char *str, s32 from, s32 to);
+void utf8_str_insert_at(char *str, s32 at, utf8_int32_t newval);
+void utf8_str_insert_utf8str(char *str, s32 at, char *toinsert);
+void utf8_str_replace_at(char *str, s32 at, utf8_int32_t newval);
+char* utf8_str_upto(char *str, s32 index);
+char* utf8_str_copy_upto(char *str, s32 roof, char *buffer);
+char* utf8_str_copy_range(char *str, s32 floor, s32 roof, char *buffer);
+
+u64 string_to_u64(char *str);
+u32 string_to_u32(char *str);
+u16 string_to_u16(char *str);
+u8 string_to_u8(char *str);
+s64 string_to_s64(char *str);
+s32 string_to_s32(char *str);
+s16 string_to_s16(char *str);
+s8 string_to_s8(char *str);
+f32 string_to_f32(char *str);
+f64 string_to_f64(char *str);
+
+#endif \ No newline at end of file