/* date = June 19th 2023 9:15 pm */ #ifndef CORE_STRING_H #define CORE_STRING_H ///////////////////////////////////// //~ sixten: String types struct string { s64 Count; u8 *Data; }; typedef string buffer; struct string_node { string String; string_node *Next; string_node *Prev; }; struct string_list { string_node *First; string_node *Last; s64 TotalCount; }; //~ sixten: Char funcitons inline b32 IsWhitespace(char C); inline b32 IsDigit(char C); inline b32 IsLetter(char C); //~ sixten: String functions //- sixten: Basic constructors inline string MakeString(u8 *Data, s64 Count); inline string MakeString(char *CString); #define StrLit(String) MakeString((u8 *)String, ArrayCount(String) - 1) //- sixten: Equality static b32 AreEqual(string A, string B); //- sixten: Substring static string Substring(string String, range1_s64 Range); static string Prefix(string String, s64 Count); static string Suffix(string String, s64 Count); //- sixten: Hashing static u64 HashString(string String); //- sixten: Searching static s64 FirstIndexOf(string String, char Char); static s64 LastIndexOf(string String, char Char); static s64 FirstIndexOf(string String, string Sub); static s64 LastIndexOf(string String, string Sub); //- sixten: Allocation static string PushString(memory_arena *Arena, string String); static string PushFormatVariadic(memory_arena *Arena, char *Format, va_list Arguments); static string PushFormat(memory_arena *Arena, char *Format, ...); static string PushCString(memory_arena *Arena, char *String); //- sixten: Conversion static s64 ConvertStringToS64(string String); static string ConvertS64ToString(memory_arena *Arena, s64 Value); static string StringFromCodepoint(memory_arena *Arena, u32 Codepoint); //- sixten: "C Style" strings static s64 StringLength(char *String); //~ sixten: String list static void AppendString(string_list *List, string String, memory_arena *Arena); static string JoinStringList(string_list *List, memory_arena *Arena); //~ sixten: Unicode struct utf8_iterator { // sixten: Input string Data; s64 Index; // sixten: Output u32 Codepoint; }; static utf8_iterator IterateUTF8String(string String); static void Advance(utf8_iterator *Iter); static b32 IsValid(utf8_iterator *Iter); static s64 UTF8FromCodepoint(u8 *Out, u32 Codepoint); #endif //CORE_STRING_H