Add BasicString and StringView
This commit is contained in:
parent
3f5e3558b9
commit
b59aedad89
@ -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);
|
|
||||||
}
|
|
@ -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
|
|
34
src/strings/basic_strings/basic_strings.h
Normal file
34
src/strings/basic_strings/basic_strings.h
Normal 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
|
Loading…
Reference in New Issue
Block a user