encoding.csv: re-encapsulate fields in Writer/Reader (fix #15558) (#15570)

This commit is contained in:
ChAoS_UnItY 2022-08-28 16:13:43 +08:00 committed by GitHub
parent 797bdd5e98
commit 258ff73efd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 10 deletions

View file

@ -6,18 +6,24 @@ module csv
import strings
struct Writer {
mut:
sb strings.Builder
pub mut:
use_crlf bool
delimiter u8
mut:
sb strings.Builder
}
[params]
pub struct WriterConfig {
use_crlf bool = false
delimiter u8 = `,`
}
// new_writer returns a reference to a Writer
pub fn new_writer() &Writer {
pub fn new_writer(config WriterConfig) &Writer {
return &Writer{
delimiter: `,`
sb: strings.new_builder(200)
use_crlf: config.use_crlf
delimiter: config.delimiter
}
}