Skip to content

Commit 493eeda

Browse files
committed
Update for Swift 2.2
1 parent 0ae87f8 commit 493eeda

File tree

3 files changed

+25
-19
lines changed

3 files changed

+25
-19
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: objective-c
2-
osx_image: xcode7.1
2+
osx_image: xcode7.3
33
script:
44
- set pipefail
55
- xcodebuild -project WebLinking.xcodeproj -scheme WebLinking test -sdk macosx | xcpretty

Sources/WebLinking.swift

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -156,23 +156,27 @@ func ~=(lhs: [String: String], rhs: [String: String]) -> Bool {
156156
}
157157

158158
/// Separate a trim a string by a separator
159-
func separateBy(separator: String)(_ input: String) -> [String] {
160-
return input.componentsSeparatedByString(separator).map {
161-
$0.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
159+
func separateBy(separator: String) -> (String) -> [String] {
160+
return { input in
161+
return input.componentsSeparatedByString(separator).map {
162+
$0.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
163+
}
162164
}
163165
}
164166

165167
/// Split a string by a separator into two components
166-
func split(separator: String)(_ input: String) -> (String, String) {
167-
let range = input.rangeOfString(separator, options: NSStringCompareOptions(rawValue: 0), range: nil, locale: nil)
168+
func split(separator: String) -> (String) -> (String, String) {
169+
return { input in
170+
let range = input.rangeOfString(separator, options: NSStringCompareOptions(rawValue: 0), range: nil, locale: nil)
171+
172+
if let range = range {
173+
let lhs = input.substringToIndex(range.startIndex)
174+
let rhs = input.substringFromIndex(range.endIndex)
175+
return (lhs, rhs)
176+
}
168177

169-
if let range = range {
170-
let lhs = input.substringToIndex(range.startIndex)
171-
let rhs = input.substringFromIndex(range.endIndex)
172-
return (lhs, rhs)
178+
return (input, "")
173179
}
174-
175-
return (input, "")
176180
}
177181

178182
/// Separate the first element in an array from the rest
@@ -186,10 +190,12 @@ func takeFirst(input: [String]) -> (String, ArraySlice<String>) {
186190
}
187191

188192
/// Trim a prefix and suffix from a string
189-
func trim(lhs: Character, _ rhs: Character)(_ input: String) -> String {
190-
if input.hasPrefix("\(lhs)") && input.hasSuffix("\(rhs)") {
191-
return input[input.startIndex.successor()..<input.endIndex.predecessor()]
192-
}
193+
func trim(lhs: Character, _ rhs: Character) -> (String) -> String {
194+
return { input in
195+
if input.hasPrefix("\(lhs)") && input.hasSuffix("\(rhs)") {
196+
return input[input.startIndex.successor()..<input.endIndex.predecessor()]
197+
}
193198

194-
return input
199+
return input
200+
}
195201
}

Tests/WebLinkingTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class LinkHeaderTests: XCTestCase {
5454
}
5555

5656
func testConversionToHeader() {
57-
XCTAssertEqual(link.header, "</style.css>; rel=\"stylesheet\"; type=\"text/css\"")
57+
XCTAssertEqual(link.header, "</style.css>; type=\"text/css\"; rel=\"stylesheet\"")
5858
}
5959

6060
func testParsingHeader() {
@@ -113,7 +113,7 @@ class LinkHTMLTests: XCTestCase {
113113
}
114114

115115
func testConversionToHTML() {
116-
let html = "<link rel=\"stylesheet\" type=\"text/css\" href=\"/style.css\" />"
116+
let html = "<link type=\"text/css\" rel=\"stylesheet\" href=\"/style.css\" />"
117117
XCTAssertEqual(link.html, html)
118118
}
119119
}

0 commit comments

Comments
 (0)