diff --git a/kernel/inc/utils/string.h b/kernel/inc/utils/string.h index 8d3a215..185df78 100644 --- a/kernel/inc/utils/string.h +++ b/kernel/inc/utils/string.h @@ -23,6 +23,7 @@ typedef const char* string_t; uint32_t string_length (string_t string); bool string_compare (string_t a, string_t b); +uint32_t string_find_next (string_t string, char chr); uint64_t variadic_format_size (string_t string, va_list args); uint64_t format_size (string_t string, ...); diff --git a/kernel/src/utils/string.c b/kernel/src/utils/string.c index 34fe63a..3a0a113 100644 --- a/kernel/src/utils/string.c +++ b/kernel/src/utils/string.c @@ -20,15 +20,7 @@ const char g_hex_chars[16] = "0123456789ABCDEF"; uint32_t string_length(string_t string) { - uint32_t n = 0; - char* c = (char*)string; - - while(*c != '\0') { - c++; - n++; - } - - return n; + return string_find_next(string, '\0'); } bool string_compare(string_t a, string_t b) { @@ -40,6 +32,17 @@ bool string_compare(string_t a, string_t b) { return memory_compare(a, b, a_len); } +uint32_t string_find_next(string_t string, char chr) { + uint32_t n = 0; + + while(*string != chr) { + string++; + n++; + } + + return n; +} + uint64_t variadic_format_size(string_t string, va_list args) { const char* buffer_in = (const char*)string;