Add BasicString and StringView

This commit is contained in:
Abdelrahman Said 2024-04-29 23:22:59 +01:00
parent 3f5e3558b9
commit b59aedad89
3 changed files with 34 additions and 35 deletions

View File

@ -1,10 +0,0 @@
#include "basic_string.h"
#include <stdio.h>
void wapp_bstr_print(const BasicString *str) {
if (!str) {
return;
}
printf("%.*s\n", (i32)str->size, str->buf);
}

View File

@ -1,25 +0,0 @@
#ifndef BASIC_STRING_H
#define BASIC_STRING_H
#include "aliases.h"
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
typedef struct bstr BasicString;
struct bstr {
u64 size;
const char *buf;
};
#define wapp_bstr_new(STR) \
(BasicString) { .size = strlen(STR), .str = STR }
void wapp_bstr_print(const BasicString *str);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // !BASIC_STRING_H

View File

@ -0,0 +1,34 @@
#ifndef BASIC_STRING_H
#define BASIC_STRING_H
#include "aliases.h"
#include <stdio.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
typedef struct bstr BasicString;
struct bstr {
u64 size;
const char *buf;
};
typedef struct strvw StringView;
struct strvw {
const u64 size;
const char *buf;
};
#define new_string(STR) \
{ .size = strlen(STR), .buf = STR }
#define wapp_bstr_new(STR) ((BasicString)new_string(STR))
#define wapp_strvw_new(STR) ((StringView)new_string(STR))
#define wapp_string_print(STR) (printf("%.*s\n", (i32)STR.size, STR.buf))
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // !BASIC_STRING_H