-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstr.h
48 lines (36 loc) · 1019 Bytes
/
str.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// (c) 2020 shdown
// This code is licensed under MIT license (see LICENSE.MIT for details)
#pragma once
#include "common.h"
#include "vm.h"
typedef struct {
GcHeader gc_hdr;
size_t size;
size_t capacity;
uint32_t hash;
char data[];
} String;
String *string_new_with_capacity(const char *x, size_t nx, size_t capacity);
String *string_hot_append_begin(String *s, size_t n);
char *string_hot_append_buf(String *s);
String *string_hot_append_end(String *s, size_t n);
UU_INHEADER String *string_new(const char *x, size_t nx)
{
return string_new_with_capacity(x, nx, nx);
}
UU_INHEADER String *string_append(String *s, const char *x, size_t nx)
{
s = string_hot_append_begin(s, nx);
if (nx) {
char *hot_buf = string_hot_append_buf(s);
memcpy(hot_buf, x, nx);
}
s = string_hot_append_end(s, nx);
return s;
}
int string_compare(String *s, String *t);
bool string_equal(String *s, String *t);
UU_INHEADER void string_destroy(String *s)
{
free(s);
}