feat: Experiments with csv parsing / printing, currently implemented in RoomTests only.
This commit is contained in:
@@ -156,24 +156,34 @@ struct RoomTests {
|
|||||||
@Test
|
@Test
|
||||||
func csvParsing() throws {
|
func csvParsing() throws {
|
||||||
let input = """
|
let input = """
|
||||||
Name,Heating Load,Cooling Total,Cooling Sensible, Register Count
|
Name,Heating Load,Cooling Total,Cooling Sensible,Register Count
|
||||||
Bed-1,12345,12345,,2
|
Bed-1,12345,12345,,2
|
||||||
Bed-2,1223,,1123,1
|
Bed-2,1223,,1123,1
|
||||||
"""[...].utf8
|
"""[...].utf8
|
||||||
|
|
||||||
|
let commaSeparator = ParsePrint {
|
||||||
|
OneOf {
|
||||||
|
",".utf8
|
||||||
|
", ".utf8
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let rowParser = ParsePrint {
|
let rowParser = ParsePrint {
|
||||||
Prefix { $0 != UInt8(ascii: ",") }.map(.string)
|
Prefix { $0 != UInt8(ascii: ",") }.map(.string)
|
||||||
",".utf8
|
",".utf8
|
||||||
Double.parser()
|
Double.parser()
|
||||||
",".utf8
|
Skip { commaSeparator }
|
||||||
|
// ",".utf8
|
||||||
Optionally {
|
Optionally {
|
||||||
Double.parser()
|
Double.parser()
|
||||||
}
|
}
|
||||||
",".utf8
|
Skip { commaSeparator }
|
||||||
|
// ",".utf8
|
||||||
Optionally {
|
Optionally {
|
||||||
Double.parser()
|
Double.parser()
|
||||||
}
|
}
|
||||||
",".utf8
|
Skip { commaSeparator }
|
||||||
|
// ",".utf8
|
||||||
Int.parser()
|
Int.parser()
|
||||||
}
|
}
|
||||||
.map(.memberwise(Row.init))
|
.map(.memberwise(Row.init))
|
||||||
|
|||||||
Reference in New Issue
Block a user