platform_string.h (2437B)
1 ////////////////////////////////////////////////////////////////// 2 // platform_string.h 3 4 5 ////////////////////////////////////////////////////////////////// 6 // char 7 8 9 RV_GLOBAL bool32 rv_char_is_space(u8 c); 10 RV_GLOBAL bool32 rv_char_is_upper(u8 c); 11 RV_GLOBAL bool32 rv_char_is_lower(u8 c); 12 RV_GLOBAL bool32 rv_char_is_alpha(u8 c); 13 RV_GLOBAL bool32 rv_char_is_slash(u8 c); 14 RV_GLOBAL bool32 rv_char_is_digit(u8 c, s32 base); 15 RV_GLOBAL u8 rv_char_to_lower(u8 c); 16 RV_GLOBAL u8 rv_char_to_upper(u8 c); 17 RV_GLOBAL u8 rv_char_to_correct_slash(u8 c); 18 19 ////////////////////////////////////////////////////////////////// 20 // c strings 21 22 RV_GLOBAL s64 rv_cstrlen(const char* c_str); 23 24 ////////////////////////////////////////////////////////////////// 25 // constructors 26 27 #define S(str) (rv_str8){(u8*)("" str ""), sizeof("" str "")-1} 28 #define rv_s8(str, size) (rv_str8){str, size} 29 #define rv_str8_from_cstr(cstr) rv_s8((u8*)cstr, rv_cstrlen((char*)cstr)) 30 #define rv_str8ify(...) S(#__VA_ARGS__) 31 RV_GLOBAL rv_str8 rv_str8_range(u8* first, u8* one_past_last); 32 33 // adds 0 terminator, use this to convert to c string 34 RV_GLOBAL rv_str8 rv_str8_copy(rv_arena* arena, rv_str8 s); 35 36 ////////////////////////////////////////////////////////////////// 37 // conversions 38 39 #define rv_s8v(S) (int)((S).len), ((S).str) 40 41 RV_GLOBAL s64 rv_sign_from_str8(rv_str8 string, rv_str8* string_tail); 42 RV_GLOBAL u64 rv_u64_from_str8(rv_str8 string, u32 radix); 43 RV_GLOBAL s64 rv_s64_from_str8(rv_str8 string, s32 radix); 44 RV_GLOBAL rv_str8 rv_str8_from_s64(rv_arena* arena, s64 integer, s32 radix, u8 min_digits, u8 digit_group_separator); 45 46 ////////////////////////////////////////////////////////////////// 47 // matching 48 49 RV_GLOBAL bool32 rv_str8_match(rv_str8 a, rv_str8 b, rv_str8_match_flags flags); 50 RV_GLOBAL s64 rv_str8_find_needle(rv_str8 string, s64 start_pos, rv_str8 needle, rv_str8_match_flags flags); 51 52 ////////////////////////////////////////////////////////////////// 53 // slicing 54 55 RV_GLOBAL rv_str8 rv_str8_substr(rv_str8 str, rv_range range); 56 RV_GLOBAL rv_str8 rv_str8_prefix(rv_str8 str, s64 size); 57 RV_GLOBAL rv_str8 rv_str8_skip(rv_str8 str, s64 amt); 58 RV_GLOBAL rv_str8 rv_str8_postfix(rv_str8 str, s64 size); 59 RV_GLOBAL rv_str8 rv_str8_chop(rv_str8 str, s64 amt); 60 RV_GLOBAL rv_str8 rv_str8_skip_chop_whitespace(rv_str8 string); 61 62 ////////////////////////////////////////////////////////////////// 63 // misc 64 65 RV_GLOBAL rv_str8 rv_read_file(rv_arena* arena, rv_str8 filename);