From: hgn Date: Mon, 22 May 2023 05:02:36 +0000 (+0100) Subject: string ops X-Git-Url: https://harrygodden.com/git/?p=vg.git;a=commitdiff_plain;h=4fd349df690629d8404fd355154846eace921586 string ops --- diff --git a/vg_platform.h b/vg_platform.h index 98baef8..cb86194 100644 --- a/vg_platform.h +++ b/vg_platform.h @@ -39,6 +39,14 @@ struct vg_achievement #define vg_list_size( A ) (sizeof(A)/sizeof(A[0])) #define VG_MUST_USE_RESULT __attribute__((warn_unused_result)) +#include +#include +#include +#include +#include +#include +#include + enum strncpy_behaviour{ k_strncpy_always_add_null = 0, k_strncpy_allow_cutoff = 1, @@ -96,10 +104,18 @@ VG_STATIC int vg_strgood( vg_str *str ) if( str->buffer[str->i -1] == '\0' ) return 1; else return 0; } - else{ - str->buffer[ str->i ++ ] = '\0'; - return 1; + else return 1; +} + +VG_STATIC char *vg_strch( vg_str *str, char c ) +{ + char *ptr = NULL; + for( u32 i=0; ii; i++ ){ + if( str->buffer[i] == c ) + ptr = str->buffer+i; } + + return ptr; } VG_STATIC u32 vg_strdjb2( const char *str ) @@ -112,14 +128,6 @@ VG_STATIC u32 vg_strdjb2( const char *str ) return hash; } -#include -#include -#include -#include -#include -#include -#include - #define VG_MIN( A, B ) ((A)<(B)?(A):(B)) #define VG_MAX( A, B ) ((A)>(B)?(A):(B)) #endif