std json parser

This commit is contained in:
2026-07-05 15:22:50 +02:00
parent 873aa3e1cc
commit aea9ce911a
14 changed files with 275 additions and 84 deletions

View File

@@ -29,7 +29,7 @@ func u8.to_str[c: u8] : str
return s
func str.free[s: str] : void
mem.free(s)
(s as ptr)->free()
func str.len[s: str] : i64
i := 0
@@ -103,7 +103,7 @@ func str.format_into[..] : i64
n += 1
i += 1
else if s[0] == 'f'
// TODO: fix when we implement f64 params
// TODO: use arrow when we implement f64 params
f64.to_str_buf(_var_arg(i), tmp as ptr)
tmp_len := tmp->len()
remaining := size - n - 1
@@ -166,7 +166,7 @@ func str.find[haystack: str, needle: str] : i64
return i
return -1
func str.substr[s: str, start: i64, length: i64] : str
func str.substr_n[s: str, start: i64, length: i64] : str
out := mem.alloc(length + 1) as str
mem.copy(s as ptr + start, out as ptr, length)
out[length] = 0
@@ -188,7 +188,7 @@ func str.trim[s: str] : str
while end >= start && s[end]->is_whitespace()
end -= 1
return s->substr(start, end - start + 1)
return s->substr_n(start, end - start + 1)
func str.reverse[s: str] : str
len := s->len()
@@ -286,7 +286,12 @@ func str.Builder.build[b: str.Builder] : str
s[b->size] = 0
return s
func str.Builder.destroy[b: str.Builder] : void
func str.Builder.build_and_free_buffer[b: str.Builder] : str
s := b->build()
b->free_buffer()
return s
func str.Builder.free_buffer[b: str.Builder] : void
if b->data != 0
b->data->free()
b->size = 0