Added: ASCII string api
This commit is contained in:
parent
98ee2b701f
commit
2a1cbea209
|
@ -1,3 +1,7 @@
|
|||
27-04-2024 René Huiberts <rhuibertsjr@gmail.com>
|
||||
|
||||
Added: ASCII string api
|
||||
|
||||
27-04-2024 René Huiberts <rhuibertsjr@gmail.com>
|
||||
|
||||
Added: project layout
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
internal String8
|
||||
str8_initialize(u8 *cstring, u64 length)
|
||||
{
|
||||
String8 result = { cstring, length };
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_range(u8 *first, u8 *opl) {
|
||||
String8 result = { first, (u64)(opl - first) };
|
||||
return result;
|
||||
}
|
||||
|
||||
internal String8
|
||||
str8_from_cstring(u8 *cstring) {
|
||||
u8 *ptr = cstring;
|
||||
for (;*ptr != 0; ptr += 1);
|
||||
String8 result = str8_range(cstring, ptr);
|
||||
return result;
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
#ifndef STRING_H
|
||||
#define STRING_H 1
|
||||
|
||||
typedef struct String8 String8;
|
||||
struct String8
|
||||
{
|
||||
u8 *str;
|
||||
u64 length;
|
||||
};
|
||||
|
||||
internal String8 str8_initialize(u8 *cstring, u64 length);
|
||||
#define str8_lit(cstring) \
|
||||
str8_initialize((u8*)(cstring), sizeof(cstring) - 1)
|
||||
|
||||
#define str8_lit_comp(cstring) \
|
||||
{(u8*)(cstring), sizeof(cstring) - 1}
|
||||
|
||||
//= rhjr: helper macros
|
||||
|
||||
#define print_str8(str8) \
|
||||
printf("%.*s\n", (i32) str8.length, str8.str)
|
||||
|
||||
#endif // STRING_H
|
Loading…
Reference in New Issue
Block a user