Implement very basic Str8 type
This commit is contained in:
parent
1108ed686e
commit
751192173f
27
src/core/strings/str8/str8.c
Normal file
27
src/core/strings/str8/str8.c
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "str8.h"
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
Str8 wapp_str8_lit(char *str) {
|
||||||
|
if (!str) {
|
||||||
|
return (Str8){.capacity = 0, .size = 0, .buf = (u8 *)""};
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 size = strlen(str);
|
||||||
|
return (Str8){.capacity = size, .size = size, .buf = (u8 *)str};
|
||||||
|
}
|
||||||
|
|
||||||
|
char wapp_str8_get(const Str8 *str, u64 index) {
|
||||||
|
if (index >= str->size) {
|
||||||
|
return '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return (char)(str->buf[index]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void wapp_str8_set(Str8 *str, u64 index, char c) {
|
||||||
|
if (index >= str->size) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
str->buf[index] = (u8)c;
|
||||||
|
}
|
25
src/core/strings/str8/str8.h
Normal file
25
src/core/strings/str8/str8.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef STR8_H
|
||||||
|
#define STR8_H
|
||||||
|
|
||||||
|
#include "aliases.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
BEGIN_C_LINKAGE
|
||||||
|
#endif // !__cplusplus
|
||||||
|
|
||||||
|
typedef struct str8 Str8;
|
||||||
|
struct str8 {
|
||||||
|
u64 capacity;
|
||||||
|
u64 size;
|
||||||
|
u8 *buf;
|
||||||
|
};
|
||||||
|
|
||||||
|
Str8 wapp_str8_lit(char *str);
|
||||||
|
char wapp_str8_get(const Str8 *str, u64 index);
|
||||||
|
void wapp_str8_set(Str8 *str, u64 index, char c);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
END_C_LINKAGE
|
||||||
|
#endif // !__cplusplus
|
||||||
|
|
||||||
|
#endif // !STR8_H
|
Loading…
Reference in New Issue
Block a user