Skip to content

Commit

Permalink
BOM handling
Browse files Browse the repository at this point in the history
  • Loading branch information
xjru committed Nov 16, 2023
1 parent ebea401 commit e7193c9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Sources/CSVaquita/BufferedStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public final class BufferedStream {
let available = min(n, end - pos)
if available > 0 {
pos += available
return Array(buf[pos..<(pos + available)])
return Array(buf[(pos - available)..<pos])
}
return []
}
Expand Down
18 changes: 12 additions & 6 deletions Tests/CSVaquitaTests/CSVReaderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -319,14 +319,20 @@ final class csvaquitaTests: XCTestCase {

XCTAssertEqual(expected, rows)
}

func testBOM() throws {
let s = "\u{FEFF}abc"
let reader = try CSVReader(makeStream(s), header: .none)
if let row = try reader.readRow() {
XCTAssertEqual("abc", row[0])
} else {
XCTFail("No rows read")
}
}

func testAdHoc() throws {
let s = """
one,two
"abc",xyz
"""

let rdr = try CSVReader(makeStream(s))
let s = "\u{FEFF}abc"
let rdr = try CSVReader(makeStream(s), header: .none)
while let row = try rdr.readRow() {
print("\(row)")
}
Expand Down

0 comments on commit e7193c9

Please sign in to comment.