@@ -14,27 +14,14 @@ import Markdown
1414
1515@main
1616struct MarkdownCommand : ParsableCommand {
17- enum Error : LocalizedError {
18- case couldntDecodeInputAsUTF8
19-
20- var errorDescription : String ? {
21- switch self {
22- case . couldntDecodeInputAsUTF8:
23- return " Couldn't decode input as UTF-8 "
24- }
25- }
26- }
27-
2817 static let configuration = CommandConfiguration ( commandName: " markdown " , shouldDisplay: false , subcommands: [
2918 DumpTree . self,
3019 Format . self,
3120 ] )
3221
3322 static func parseFile( at path: String , options: ParseOptions ) throws -> ( source: String , parsed: Document ) {
3423 let data = try Data ( contentsOf: URL ( fileURLWithPath: path) )
35- guard let inputString = String ( data: data, encoding: . utf8) else {
36- throw Error . couldntDecodeInputAsUTF8
37- }
24+ let inputString = String ( decoding: data, as: UTF8 . self)
3825 return ( inputString, Document ( parsing: inputString, options: options) )
3926 }
4027
@@ -45,9 +32,7 @@ struct MarkdownCommand: ParsableCommand {
4532 } else {
4633 stdinData = FileHandle . standardInput. readDataToEndOfFile ( )
4734 }
48- guard let stdinString = String ( data: stdinData, encoding: . utf8) else {
49- throw Error . couldntDecodeInputAsUTF8
50- }
35+ let stdinString = String ( decoding: stdinData, as: UTF8 . self)
5136 return ( stdinString, Document ( parsing: stdinString, options: options) )
5237 }
5338}
0 commit comments