Skip to content

Commit 42ec6c2

Browse files
committed
DOF files are ISO Latin-1, not UTF-8
1 parent 30ba31f commit 42ec6c2

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

Sources/SwiftDOF/Parser/ByteParsing.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ extension RandomAccessCollection where Element == UInt8, Index == Int {
122122
}
123123

124124
/// Convert to trimmed String (only when actually needed).
125-
/// - Throws: DOFError.invalidEncoding if bytes cannot be decoded as UTF-8.
125+
/// - Throws: DOFError.invalidEncoding if bytes cannot be decoded as Latin-1.
126126
@inlinable
127127
func toString() throws -> String {
128-
guard let string = String(bytes: Array(self), encoding: .utf8) else {
128+
guard let string = String(bytes: Array(self), encoding: .isoLatin1) else {
129129
throw DOFError.invalidEncoding
130130
}
131131
return string.trimmingCharacters(in: .whitespaces)

Sources/SwiftDOF/Parser/DOFError.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public enum DOFFormatError: Sendable {
2323

2424
/// Errors that can occur during DOF parsing.
2525
public enum DOFError: Error, LocalizedError, Sendable {
26-
/// The file data is not valid ASCII encoding.
26+
/// The file data is not valid Latin-1 encoding.
2727
case invalidEncoding
2828

2929
/// The file format is invalid.
@@ -61,7 +61,7 @@ public enum DOFError: Error, LocalizedError, Sendable {
6161
public var failureReason: String? {
6262
switch self {
6363
case .invalidEncoding:
64-
String(localized: "The file is not valid ASCII encoding.", bundle: .module)
64+
String(localized: "The file is not valid Latin-1 encoding.", bundle: .module)
6565
case .invalidFormat(let error):
6666
switch error {
6767
case .missingCurrencyDate:

Sources/SwiftDOF/Resources/Localizable.xcstrings

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@
105105
"The file at “%@” could not be found." : {
106106

107107
},
108-
"The file is not valid ASCII encoding." : {
109-
108+
"The file is not valid Latin-1 encoding." : {
109+
"comment" : "Error message when the file is not valid Latin-1 encoding.",
110+
"isCommentAutoGenerated" : true
110111
},
111112
"Verify that the file exists and has not been moved or deleted." : {
112113

0 commit comments

Comments
 (0)