From eece39c2ed7d1b1c7cdfa58f6d6f94959c5bbbe3 Mon Sep 17 00:00:00 2001 From: NukeBird Date: Mon, 1 Dec 2025 21:17:21 +0300 Subject: [PATCH] Better axl_strchr + handle finding '\0' --- axl_string.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/axl_string.c b/axl_string.c index 3eb6894..7fafcd0 100644 --- a/axl_string.c +++ b/axl_string.c @@ -82,12 +82,12 @@ i8* axl_strncat(i8* dst, const i8* src, u32 n) //n actually means "not more than i32 axl_strcmp(const i8* s1, const i8* s2) { - if (!s1 || !s2) + if(!s1 || !s2) { return (s1 == s2) ? 0 : (!s1 ? -1 : 1); } - for (;; s1++, s2++) + for(;; s1++, s2++) { u8 c1 = *(const u8*)s1; u8 c2 = *(const u8*)s2; @@ -103,17 +103,17 @@ i32 axl_strcmp(const i8* s1, const i8* s2) i32 axl_strncmp(const i8* s1, const i8* s2, u32 n) { - if (!s1 || !s2) + if(!s1 || !s2) { return (s1 == s2) ? 0 : (!s1 ? -1 : 1); } - for (u32 i = 0; i < n; s1++, s2++, i++) + for(u32 i = 0; i < n; s1++, s2++, i++) { u8 c1 = *(const u8*)s1; u8 c2 = *(const u8*)s2; - if (c1 != c2 || c1 == '\0' || c2 == '\0') + if(c1 != c2 || c1 == '\0' || c2 == '\0') { return c1 - c2; } @@ -124,21 +124,18 @@ i32 axl_strncmp(const i8* s1, const i8* s2, u32 n) const i8* axl_strchr(const i8* str, i8 c) { - if(!str) + if(!str) { return NULL; } - - u32 i = 0; - - while(str[i] != '\0') + + for(; *str != '\0'; ++str) { - if(str[i] == c) + if(*str == c) { - return str + i; + return str; } - i++; } - return NULL; + return (c == '\0') ? str : NULL; }