1
0
Fork 0

Added: ASCII string api

Browse Source
This commit is contained in:
rhuibertsjr 2024-04-27 12:29:46 +02:00
parent 98ee2b701f
commit 2a1cbea209
3 changed files with 47 additions and 0 deletions

View File

@ -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

20
src/string.c Normal file
View File

@ -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;
}

23
src/string.h Normal file
View File

@ -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