mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 22:28:46 +00:00
Simplify strings.write_byte and strings.write_bytes
This commit is contained in:
@@ -128,29 +128,17 @@ builder_space :: proc(b: Builder) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
write_byte :: proc(b: ^Builder, x: byte) -> (n: int) {
|
write_byte :: proc(b: ^Builder, x: byte) -> (n: int) {
|
||||||
if builder_space(b^) > 0 {
|
n0 := len(b.buf)
|
||||||
append(&b.buf, x)
|
append(&b.buf, x)
|
||||||
n += 1
|
n1 := len(b.buf)
|
||||||
}
|
return n1-n0
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
write_bytes :: proc(b: ^Builder, x: []byte) -> (n: int) {
|
write_bytes :: proc(b: ^Builder, x: []byte) -> (n: int) {
|
||||||
x := x
|
n0 := len(b.buf)
|
||||||
for len(x) != 0 {
|
append(&b.buf, ..x)
|
||||||
space := builder_space(b^)
|
n1 := len(b.buf)
|
||||||
if space == 0 {
|
return n1-n0
|
||||||
break // No need to append
|
|
||||||
}
|
|
||||||
i := min(space, len(x))
|
|
||||||
n += i
|
|
||||||
append(&b.buf, ..x[:i])
|
|
||||||
if len(x) <= i {
|
|
||||||
break // No more data to append
|
|
||||||
}
|
|
||||||
x = x[i:]
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
write_rune_builder :: proc(b: ^Builder, r: rune) -> (int, io.Error) {
|
write_rune_builder :: proc(b: ^Builder, r: rune) -> (int, io.Error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user