Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: FavIcon/Utils.swift

Issue 29664569: Favicon: Issue 6245 - SwiftLinted project files (Closed)
Patch Set: Removed the sorted_imports rule and reversed the import calls to be sorted alphabetically Created Feb. 19, 2018, 10:38 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « FavIcon/URLRequestOperation.swift ('k') | FavIconTests/FavIconsTests.swift » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // 1 //
2 // FavIcon 2 // FavIcon
3 // Copyright © 2016 Leon Breedt 3 // Copyright © 2016 Leon Breedt
4 // 4 //
5 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License. 6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at 7 // You may obtain a copy of the License at
8 // 8 //
9 // http://www.apache.org/licenses/LICENSE-2.0 9 // http://www.apache.org/licenses/LICENSE-2.0
10 // 10 //
(...skipping 30 matching lines...) Expand all
41 } else { 41 } else {
42 return (mimeType: headerComponents[0], encoding: String.Encoding.utf 8) 42 return (mimeType: headerComponents[0], encoding: String.Encoding.utf 8)
43 } 43 }
44 } 44 }
45 45
46 /// - Returns: The Cocoa encoding identifier for the encoding name in this s tring, or `nil` 46 /// - Returns: The Cocoa encoding identifier for the encoding name in this s tring, or `nil`
47 /// if the encoding is not supported or known. 47 /// if the encoding is not supported or known.
48 //swiftlint:disable cyclomatic_complexity 48 //swiftlint:disable cyclomatic_complexity
49 func parseAsStringEncoding() -> String.Encoding? { 49 func parseAsStringEncoding() -> String.Encoding? {
50 switch lowercased() { 50 switch lowercased() {
51 case "iso-8859-1", "latin1": return String.Encoding.isoLatin1 51 case "iso-8859-1", "latin1":
52 case "iso-8859-2", "latin2": return String.Encoding.isoLatin2 52 return String.Encoding.isoLatin1
53 case "iso-2022-jp": return String.Encoding.iso2022JP 53 case "iso-8859-2", "latin2":
54 case "shift_jis": return String.Encoding.shiftJIS 54 return String.Encoding.isoLatin2
55 case "us-ascii": return String.Encoding.ascii 55 case "iso-2022-jp":
56 case "utf-8": return String.Encoding.utf8 56 return String.Encoding.iso2022JP
57 case "utf-16": return String.Encoding.utf16 57 case "shift_jis":
58 case "utf-32": return String.Encoding.utf32 58 return String.Encoding.shiftJIS
59 case "utf-32be": return String.Encoding.utf32BigEndian 59 case "us-ascii":
60 case "utf-32le": return String.Encoding.utf32LittleEndian 60 return String.Encoding.ascii
61 case "windows-1250": return String.Encoding.windowsCP1250 61 case "utf-8":
62 case "windows-1251": return String.Encoding.windowsCP1251 62 return String.Encoding.utf8
63 case "windows-1252": return String.Encoding.windowsCP1252 63 case "utf-16":
64 case "windows-1253": return String.Encoding.windowsCP1253 64 return String.Encoding.utf16
65 case "windows-1254": return String.Encoding.windowsCP1254 65 case "utf-32":
66 case "x-mac-roman": return String.Encoding.macOSRoman 66 return String.Encoding.utf32
67 case "utf-32be":
68 return String.Encoding.utf32BigEndian
69 case "utf-32le":
70 return String.Encoding.utf32LittleEndian
71 case "windows-1250":
72 return String.Encoding.windowsCP1250
73 case "windows-1251":
74 return String.Encoding.windowsCP1251
75 case "windows-1252":
76 return String.Encoding.windowsCP1252
77 case "windows-1253":
78 return String.Encoding.windowsCP1253
79 case "windows-1254":
80 return String.Encoding.windowsCP1254
81 case "x-mac-roman":
82 return String.Encoding.macOSRoman
67 default: 83 default:
68 return nil 84 return nil
69 } 85 }
70 } 86 }
71 //swiftlint:enable cyclomatic_complexity 87 //swiftlint:enable cyclomatic_complexity
72 } 88 }
73 89
74 extension HTTPURLResponse { 90 extension HTTPURLResponse {
75 /// Parses the `Content-Type` header in this response. 91 /// Parses the `Content-Type` header in this response.
76 /// - returns: A `(mimeType: String, encoding: String.Encoding)` tuple. 92 /// - returns: A `(mimeType: String, encoding: String.Encoding)` tuple.
(...skipping 13 matching lines...) Expand all
90 /// - returns: A dictionary having items of type `K` as keys, and type `V` a s values. 106 /// - returns: A dictionary having items of type `K` as keys, and type `V` a s values.
91 func toDictionary<K, V>(_ transform: (Element) -> (K, V)) -> [K: V] { 107 func toDictionary<K, V>(_ transform: (Element) -> (K, V)) -> [K: V] {
92 var dict: [K: V] = [:] 108 var dict: [K: V] = [:]
93 for item in self { 109 for item in self {
94 let (key, value) = transform(item) 110 let (key, value) = transform(item)
95 dict[key] = value 111 dict[key] = value
96 } 112 }
97 return dict 113 return dict
98 } 114 }
99 } 115 }
OLDNEW
« no previous file with comments | « FavIcon/URLRequestOperation.swift ('k') | FavIconTests/FavIconsTests.swift » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld