diff options
author | WormHeamer | 2025-03-10 15:15:41 -0400 |
---|---|---|
committer | WormHeamer | 2025-03-10 15:16:42 -0400 |
commit | 5560bd06cd3eaeb5739690cd34354985bc948a96 (patch) | |
tree | ae505c6ddb3b6e4e37ef5a2eea1166de367b05e8 | |
parent | e6e0d5a53eeb969e9e04051559993db69b98cc85 (diff) |
move str_replace_end to str.h
-rw-r--r-- | main.c | 8 | ||||
-rw-r--r-- | str.h | 38 |
2 files changed, 23 insertions, 23 deletions
diff --git a/main.c b/main.c index d9cbd44..8336728 100644 --- a/main.c +++ b/main.c @@ -201,14 +201,6 @@ BlockList blk_gather(Str src, Arena *perm) { #define Ot(a, s, b) Os(a), O(s), Os(b) #define Otl(a, f, b) for (Line *l = blk->lines; l; l = l->next) Ot(a, f, b) -Str str_replace_end(Str s, Str a, Str b, Arena *m) { - if (!str_ends(s, a)) return s; - char *p = new_arr(m, char, s.n + b.n - a.n); - memcpy(p, s.s, s.n - a.n); - memcpy(p + s.n - a.n, b.s, b.n); - return (Str) { p, s.n + b.n - a.n }; -} - void str_cat_blk(Str *out, Block *blk, Arena *perm, Arena *scratch) { switch (blk->type) { case LN_CODE: diff --git a/str.h b/str.h index 3cc3f38..9b1aafc 100644 --- a/str.h +++ b/str.h @@ -14,21 +14,6 @@ typedef struct { #define S(s) (Str){s,sizeof(s)-1} -/* allocating */ - -Str str_dup(Str a, Arena *m) { - char *s = new_arr(m, char, a.n); - memcpy(s, a.s, a.n); - a.s = s; - return a; -} - -static inline void str_cat(Str *a, Str b, Arena *m) { - a->s = resize(m, a->s, a->n, a->n + b.n); - memcpy(&a->s[a->n], b.s, b.n); - a->n += b.n; -} - /* conversions */ static inline char *str_to_cstr(Str s, Arena *a) { @@ -119,4 +104,27 @@ static inline int str_contains(Str a, Str b) { return str_find(a, b).n > 0; } +/* allocating */ + +static inline Str str_dup(Str a, Arena *m) { + char *s = new_arr(m, char, a.n); + memcpy(s, a.s, a.n); + a.s = s; + return a; +} + +static inline void str_cat(Str *a, Str b, Arena *m) { + a->s = resize(m, a->s, a->n, a->n + b.n); + memcpy(&a->s[a->n], b.s, b.n); + a->n += b.n; +} + +static inline Str str_replace_end(Str s, Str a, Str b, Arena *m) { + if (!str_ends(s, a)) return s; + char *p = new_arr(m, char, s.n + b.n - a.n); + memcpy(p, s.s, s.n - a.n); + memcpy(p + s.n - a.n, b.s, b.n); + return (Str) { p, s.n + b.n - a.n }; +} + #endif |