feature (kernel): Implemented function to find the last matching char in a string

This commit is contained in:
antifallobst 2023-02-26 15:06:44 +01:00
parent b89825b589
commit b607c9280b
2 changed files with 13 additions and 0 deletions

View File

@ -24,6 +24,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);
uint32_t string_find_last (string_t string, char chr);
uint64_t variadic_format_size (string_t string, va_list args);
uint64_t format_size (string_t string, ...);

View File

@ -43,6 +43,18 @@ uint32_t string_find_next(string_t string, char chr) {
return n;
}
uint32_t string_find_last(string_t string, char chr) {
uint32_t n = string_length(string);
string += n;
while(*string != chr && n != 0) {
string--;
n--;
}
return n;
}
uint64_t variadic_format_size(string_t string, va_list args) {
const char* buffer_in = (const char*)string;