mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
797bdd5e98
commit
258ff73efd
@ -38,14 +38,14 @@ fn (err InvalidLineEndingError) msg() string {
|
||||
return 'encoding.csv: could not find any valid line endings'
|
||||
}
|
||||
|
||||
pub struct Reader {
|
||||
struct Reader {
|
||||
// not used yet
|
||||
// has_header bool
|
||||
// headings []string
|
||||
data string
|
||||
pub mut:
|
||||
delimiter u8
|
||||
comment u8
|
||||
data string
|
||||
delimiter u8
|
||||
comment u8
|
||||
mut:
|
||||
is_mac_pre_osx_le bool
|
||||
row_pos int
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,3 +9,13 @@ fn test_encoding_csv_writer() {
|
||||
|
||||
assert csv_writer.str() == 'name,email,phone,other\njoe,joe@blow.com,0400000000,test\nsam,sam@likesham.com,0433000000,"needs, quoting"\n'
|
||||
}
|
||||
|
||||
fn test_encoding_csv_writer_delimiter() {
|
||||
mut csv_writer := csv.new_writer(delimiter: ` `)
|
||||
|
||||
csv_writer.write(['name', 'email', 'phone', 'other']) or {}
|
||||
csv_writer.write(['joe', 'joe@blow.com', '0400000000', 'test']) or {}
|
||||
csv_writer.write(['sam', 'sam@likesham.com', '0433000000', 'needs, quoting']) or {}
|
||||
|
||||
assert csv_writer.str() == 'name email phone other\njoe joe@blow.com 0400000000 test\nsam sam@likesham.com 0433000000 "needs, quoting"\n'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user