@@ -37,20 +37,20 @@ func help() -> Int32 {
3737}
3838
3939enum ExecutionMode {
40- case Help
41- case Lint
42- case Convert
43- case Print
40+ case help
41+ case lint
42+ case convert
43+ case print
4444}
4545
4646enum ConversionFormat {
47- case XML1
48- case Binary1
49- case JSON
47+ case xml1
48+ case binary1
49+ case json
5050}
5151
5252struct Options {
53- var mode : ExecutionMode = . Lint
53+ var mode : ExecutionMode = . lint
5454 var silent : Bool = false
5555 var output : String ?
5656 var fileExtension : String ?
@@ -60,9 +60,9 @@ struct Options {
6060}
6161
6262enum OptionParseError : Swift . Error {
63- case UnrecognizedArgument ( String )
64- case MissingArgument ( String )
65- case InvalidFormat ( String )
63+ case unrecognizedArgument ( String )
64+ case missingArgument ( String )
65+ case invalidFormat ( String )
6666}
6767
6868func parseArguments( _ args: [ String ] ) throws -> Options {
@@ -74,57 +74,46 @@ func parseArguments(_ args: [String]) throws -> Options {
7474 while let path = iterator. next ( ) {
7575 opts. inputs. append ( path)
7676 }
77- break
7877 case " -s " :
7978 opts. silent = true
80- break
8179 case " -o " :
8280 if let path = iterator. next ( ) {
8381 opts. output = path
8482 } else {
85- throw OptionParseError . MissingArgument ( " -o requires a path argument " )
83+ throw OptionParseError . missingArgument ( " -o requires a path argument " )
8684 }
87- break
8885 case " -convert " :
89- opts. mode = ExecutionMode . Convert
86+ opts. mode = . convert
9087 if let format = iterator. next ( ) {
9188 switch format {
9289 case " xml1 " :
93- opts. conversionFormat = ConversionFormat . XML1
94- break
90+ opts. conversionFormat = . xml1
9591 case " binary1 " :
96- opts. conversionFormat = ConversionFormat . Binary1
97- break
92+ opts. conversionFormat = . binary1
9893 case " json " :
99- opts. conversionFormat = ConversionFormat . JSON
100- break
94+ opts. conversionFormat = . json
10195 default :
102- throw OptionParseError . InvalidFormat ( format)
96+ throw OptionParseError . invalidFormat ( format)
10397 }
10498 } else {
105- throw OptionParseError . MissingArgument ( " -convert requires a format argument of xml1 binary1 json " )
99+ throw OptionParseError . missingArgument ( " -convert requires a format argument of xml1 binary1 json " )
106100 }
107- break
108101 case " -e " :
109102 if let ext = iterator. next ( ) {
110103 opts. fileExtension = ext
111104 } else {
112- throw OptionParseError . MissingArgument ( " -e requires an extension argument " )
105+ throw OptionParseError . missingArgument ( " -e requires an extension argument " )
113106 }
114107 case " -help " :
115- opts. mode = ExecutionMode . Help
116- break
108+ opts. mode = . help
117109 case " -lint " :
118- opts. mode = ExecutionMode . Lint
119- break
110+ opts. mode = . lint
120111 case " -p " :
121- opts. mode = ExecutionMode . Print
122- break
112+ opts. mode = . print
123113 default :
124114 if arg. hasPrefix ( " - " ) && arg. utf8. count > 1 {
125- throw OptionParseError . UnrecognizedArgument ( arg)
115+ throw OptionParseError . unrecognizedArgument ( arg)
126116 }
127- break
128117 }
129118 }
130119
@@ -194,109 +183,111 @@ func convert(_ options: Options) -> Int32 {
194183}
195184
196185enum DisplayType {
197- case Primary
198- case Key
199- case Value
186+ case primary
187+ case key
188+ case value
200189}
201190
202191extension Dictionary {
203- func display( _ indent: Int = 0 , type: DisplayType = . Primary ) {
192+ func display( _ indent: Int = 0 , type: DisplayType = . primary ) {
204193 let indentation = String ( repeating: " " , count: indent * 2 )
205- if type == . Primary || type == . Key {
194+ switch type {
195+ case . primary, . key:
206196 print ( " \( indentation) [ \n " , terminator: " " )
207- } else {
197+ case . value :
208198 print ( " [ \n " , terminator: " " )
209199 }
210-
200+
211201 forEach ( ) {
212202 if let key = $0. 0 as? String {
213- key. display ( indent + 1 , type: . Key )
203+ key. display ( indent + 1 , type: . key )
214204 } else {
215205 fatalError ( " plists should have strings as keys but got a \( type ( of: $0. 0 ) ) " )
216206 }
217207 print ( " => " , terminator: " " )
218- displayPlist ( $0. 1 , indent: indent + 1 , type: . Value )
208+ displayPlist ( $0. 1 , indent: indent + 1 , type: . value )
219209 }
220210
221211 print ( " \( indentation) ] \n " , terminator: " " )
222212 }
223213}
224214
225215extension Array {
226- func display( _ indent: Int = 0 , type: DisplayType = . Primary ) {
216+ func display( _ indent: Int = 0 , type: DisplayType = . primary ) {
227217 let indentation = String ( repeating: " " , count: indent * 2 )
228- if type == . Primary || type == . Key {
218+ switch type {
219+ case . primary, . key:
229220 print ( " \( indentation) [ \n " , terminator: " " )
230- } else {
221+ case . value :
231222 print ( " [ \n " , terminator: " " )
232223 }
233-
224+
234225 for idx in 0 ..< count {
235226 print ( " \( indentation) \( idx) => " , terminator: " " )
236- displayPlist ( self [ idx] , indent: indent + 1 , type: . Value )
227+ displayPlist ( self [ idx] , indent: indent + 1 , type: . value )
237228 }
238229
239230 print ( " \( indentation) ] \n " , terminator: " " )
240231 }
241232}
242233
243234extension String {
244- func display( _ indent: Int = 0 , type: DisplayType = . Primary ) {
235+ func display( _ indent: Int = 0 , type: DisplayType = . primary ) {
245236 let indentation = String ( repeating: " " , count: indent * 2 )
246- if type == . Primary {
237+ switch type {
238+ case . primary:
247239 print ( " \( indentation) \" \( self ) \" \n " , terminator: " " )
248- }
249- else if type == . Key {
240+ case . key:
250241 print ( " \( indentation) \" \( self ) \" " , terminator: " " )
251- } else {
242+ case . value :
252243 print ( " \" \( self ) \" \n " , terminator: " " )
253244 }
254245 }
255246}
256247
257248extension Bool {
258- func display( _ indent: Int = 0 , type: DisplayType = . Primary ) {
249+ func display( _ indent: Int = 0 , type: DisplayType = . primary ) {
259250 let indentation = String ( repeating: " " , count: indent * 2 )
260- if type == . Primary {
251+ switch type {
252+ case . primary:
261253 print ( " \( indentation) \" \( self ? " 1 " : " 0 " ) \" \n " , terminator: " " )
262- }
263- else if type == . Key {
254+ case . key:
264255 print ( " \( indentation) \" \( self ? " 1 " : " 0 " ) \" " , terminator: " " )
265- } else {
256+ case . value :
266257 print ( " \" \( self ? " 1 " : " 0 " ) \" \n " , terminator: " " )
267258 }
268259 }
269260}
270261
271262extension NSNumber {
272- func display( _ indent: Int = 0 , type: DisplayType = . Primary ) {
263+ func display( _ indent: Int = 0 , type: DisplayType = . primary ) {
273264 let indentation = String ( repeating: " " , count: indent * 2 )
274- if type == . Primary {
265+ switch type {
266+ case . primary:
275267 print ( " \( indentation) \" \( self ) \" \n " , terminator: " " )
276- }
277- else if type == . Key {
268+ case . key:
278269 print ( " \( indentation) \" \( self ) \" " , terminator: " " )
279- } else {
270+ case . value :
280271 print ( " \" \( self ) \" \n " , terminator: " " )
281272 }
282273 }
283274}
284275
285276extension NSData {
286- func display( _ indent: Int = 0 , type: DisplayType = . Primary ) {
277+ func display( _ indent: Int = 0 , type: DisplayType = . primary ) {
287278 let indentation = String ( repeating: " " , count: indent * 2 )
288- if type == . Primary {
279+ switch type {
280+ case . primary:
289281 print ( " \( indentation) \" \( self ) \" \n " , terminator: " " )
290- }
291- else if type == . Key {
282+ case . key:
292283 print ( " \( indentation) \" \( self ) \" " , terminator: " " )
293- } else {
284+ case . value :
294285 print ( " \" \( self ) \" \n " , terminator: " " )
295286 }
296287 }
297288}
298289
299- func displayPlist( _ plist: Any , indent: Int = 0 , type: DisplayType = . Primary ) {
290+ func displayPlist( _ plist: Any , indent: Int = 0 , type: DisplayType = . primary ) {
300291 if let val = plist as? Dictionary < String , Any > {
301292 val. display ( indent, type: type)
302293 } else if let val = plist as? Array < Any > {
@@ -366,27 +357,24 @@ func main() -> Int32 {
366357 do {
367358 let opts = try parseArguments ( args)
368359 switch opts. mode {
369- case . Lint :
360+ case . lint :
370361 return lint ( opts)
371- case . Convert :
362+ case . convert :
372363 return convert ( opts)
373- case . Print :
364+ case . print :
374365 return display ( opts)
375- case . Help :
366+ case . help :
376367 return help ( )
377368 }
378369 } catch let err {
379370 switch err as! OptionParseError {
380- case . UnrecognizedArgument ( let arg) :
371+ case . unrecognizedArgument ( let arg) :
381372 print ( " unrecognized option: \( arg) " )
382373 let _ = help ( )
383- break
384- case . InvalidFormat( let format) :
374+ case . invalidFormat( let format) :
385375 print ( " unrecognized format \( format) \n format should be one of: xml1 binary1 json " )
386- break
387- case . MissingArgument( let errorStr) :
376+ case . missingArgument( let errorStr) :
388377 print ( errorStr)
389- break
390378 }
391379 return EXIT_FAILURE
392380 }
0 commit comments