Skip to content

Commit 3bf704c

Browse files
authored
Merge pull request #2 from nrgbodya/bugfix/macos-encoding-detection
Bugfix/macos encoding detection
2 parents b72e79c + b5f8512 commit 3bf704c

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

swift-csv/CSV.swift

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,20 +464,17 @@ public struct CSV {
464464

465465
var encoding: String.Encoding = .utf8
466466

467-
if length > 4 {
468-
if let bom = String.Encoding.BOM(bom0: buffer[0], bom1: buffer[1], bom2: buffer[2], bom3: buffer[3]) {
469-
encoding = bom.encoding
470-
if bom.length > 0 {
471-
buffer.removeFirst(bom.length)
472-
}
473-
}
467+
if length > 4, let bom = String.Encoding.BOM(bom0: buffer[0], bom1: buffer[1], bom2: buffer[2], bom3: buffer[3]) {
468+
encoding = bom.encoding
469+
buffer.removeFirst(bom.length)
474470
}
475471

476472
let string: String
477473
if let decoded = String(bytes: buffer, encoding: encoding) {
478474
string = decoded
479475
} else if let macOSRoman = String(bytes: buffer, encoding: .macOSRoman) {
480476
string = macOSRoman
477+
encoding = .macOSRoman
481478
} else {
482479
return nil
483480
}

0 commit comments

Comments
 (0)