1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

strings: make builder implement io.Writer (#8914)

This commit is contained in:
zakuro
2021-02-23 16:42:48 +09:00
committed by GitHub
parent 5674d46965
commit c113abe1a4
2 changed files with 13 additions and 11 deletions

View File

@ -29,33 +29,33 @@ pub fn (mut w Writer) write(record []string) ?bool {
for n, field_ in record {
mut field := field_
if n > 0 {
w.sb.write(w.delimiter.ascii_str())
w.sb.write_string(w.delimiter.ascii_str())
}
if !w.field_needs_quotes(field) {
w.sb.write(field)
w.sb.write_string(field)
continue
}
w.sb.write('"')
w.sb.write_string('"')
for field.len > 0 {
mut i := field.index_any('"\r\n')
if i < 0 {
i = field.len
}
w.sb.write(field[..i])
w.sb.write_string(field[..i])
field = field[i..]
if field.len > 0 {
z := field[0]
match z {
`"` { w.sb.write('""') }
`\r`, `\n` { w.sb.write(le) }
`"` { w.sb.write_string('""') }
`\r`, `\n` { w.sb.write_string(le) }
else {}
}
field = field[1..]
}
}
w.sb.write('"')
w.sb.write_string('"')
}
w.sb.write(le)
w.sb.write_string(le)
return true
}