Banjo API 1.1.0-alpha
Low-level C99 game development API
Loading...
Searching...
No Matches
string.h
Go to the documentation of this file.
1
38#ifndef BJ_STRING_H
39#define BJ_STRING_H
40
41#include <banjo/api.h>
42
43#include <string.h>
44
57struct bj_str {
58 const char* data;
59 size_t len;
60};
61
72#ifdef __cplusplus
73# define BJ_STR(literal) (bj_str{ "" literal "", sizeof(literal) - 1 })
74#else
75# define BJ_STR(literal) ((struct bj_str){ "" literal "", sizeof(literal) - 1 })
76#endif
77
90 const char* c_string
91);
92
107 struct bj_str left,
108 struct bj_str right
109);
110
126 struct bj_str view,
127 size_t from,
128 size_t to
129);
130
147struct bj_string;
148
163 struct bj_str initial
164);
165
172 struct bj_string* string
173);
174
187 const struct bj_string* string
188);
189
203 const struct bj_string* string
204);
205
217 struct bj_string* string,
218 struct bj_str tail
219);
220
234#define bj_strlen strlen
235
252#define bj_strcmp strcmp
253
254#endif /* BJ_STRING_H */
General-purpose definitions for Banjo API.
#define BANJO_EXPORT
Definition api.h:179
uint32_t bj_bool
Boolean type used throughout the Banjo API.
Definition api.h:264
size_t len
Number of bytes in the view.
Definition string.h:59
const char * data
Pointer to the first byte, or NULL for an empty view.
Definition string.h:58
const char * bj_string_cstr(const struct bj_string *string)
Get a NUL-terminated pointer to an owning string.
bj_bool bj_str_eq(struct bj_str left, struct bj_str right)
Compare two views byte by byte.
struct bj_string * bj_create_string(struct bj_str initial)
Create an owning string from a byte view.
struct bj_str bj_string_view(const struct bj_string *string)
Get a borrowed view of an owning string.
struct bj_str bj_str_slice(struct bj_str view, size_t from, size_t to)
Create a view of a byte range within another view.
struct bj_str bj_str_from_cstr(const char *c_string)
Create a view from a NUL-terminated C string.
void bj_destroy_string(struct bj_string *string)
Destroy an owning string and release its memory.
void bj_append_string(struct bj_string *string, struct bj_str tail)
Append bytes to an owning string.
A borrowed view of a sequence of bytes.
Definition string.h:57
An owning string containing valid UTF-8.
UTF-8 string views and owning strings.