Skip to content

Commit 4ff161a

Browse files
committed
Update to Swift 4.0
1 parent cb3d355 commit 4ff161a

File tree

5 files changed

+59
-47
lines changed

5 files changed

+59
-47
lines changed

.travis.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ matrix:
55
include:
66
- os: osx
77
language: objective-c
8-
osx_image: xcode8.3
8+
osx_image: xcode9
99
script:
1010
- swift test
1111
- os: linux
@@ -15,9 +15,9 @@ matrix:
1515
env:
1616
before_install:
1717
- wget -q -O - https://swift.org/keys/all-keys.asc | gpg --import -
18-
- wget https://swift.org/builds/swift-3.1-release/ubuntu1404/swift-3.1-RELEASE/swift-3.1-RELEASE-ubuntu14.04.tar.gz
19-
- tar xzf swift-3.1-RELEASE-ubuntu14.04.tar.gz
20-
- export PATH=${PWD}/swift-3.1-RELEASE-ubuntu14.04/usr/bin:"${PATH}"
18+
- wget https://swift.org/builds/swift-4.0-release/ubuntu1404/swift-4.0-RELEASE/swift-4.0-RELEASE-ubuntu14.04.tar.gz
19+
- tar xzf swift-4.0-RELEASE-ubuntu14.04.tar.gz
20+
- export PATH=${PWD}/swift-4.0-RELEASE-ubuntu14.04/usr/bin:"${PATH}"
2121
script:
2222
- swift test
2323
notifications:

Package.swift

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
// swift-tools-version:4.0
2+
13
import PackageDescription
24

3-
let package = Package(name: "FileCheck")
5+
let package = Package(
6+
name: "FileCheck",
7+
products: [
8+
.library(
9+
name: "FileCheck",
10+
targets: ["FileCheck"]),
11+
],
12+
targets: [
13+
.target(
14+
name: "FileCheck"),
15+
.testTarget(
16+
name: "FileCheckTests",
17+
dependencies: ["FileCheck"]),
18+
]
19+
)

Sources/FileCheck/CheckString.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ struct CheckString {
7878
}
7979

8080
// Match itself from the last position after matching CHECK-DAG.
81-
let matchBuffer = buffer.substring(from: buffer.index(buffer.startIndex, offsetBy: lastPos))
81+
let matchBuffer = String(buffer[buffer.index(buffer.startIndex, offsetBy: lastPos)...])
8282
guard let (range, mutVariableTable) = self.pattern.match(matchBuffer, initialTable) else {
8383
diagnoseFailedCheck(self.pattern, self.loc, self.prefix, variableTable, options, buffer)
8484
return nil
@@ -90,15 +90,15 @@ struct CheckString {
9090
let finalTable : [String:String]
9191
if !isLabelScanMode {
9292
let startIdx = buffer.index(buffer.startIndex, offsetBy: lastPos)
93-
let skippedRegion = buffer.substring(
94-
with: Range<String.Index>(
93+
let skippedRegion = String(buffer[
94+
Range<String.Index>(
9595
uncheckedBounds: (
9696
startIdx,
9797
buffer.index(startIdx, offsetBy: matchPos)
9898
)
9999
)
100-
)
101-
let rest = buffer.substring(from: buffer.index(buffer.startIndex, offsetBy: matchPos))
100+
])
101+
let rest = String(buffer[buffer.index(buffer.startIndex, offsetBy: matchPos)...])
102102

103103
// If this check is a "CHECK-NEXT", verify that the previous match was on
104104
// the previous line (i.e. that there is one newline between them).
@@ -247,7 +247,7 @@ struct CheckString {
247247
assert((pattern.type == .dag), "Expect CHECK-DAG!")
248248

249249
// CHECK-DAG always matches from the start.
250-
let matchBuffer = buffer.substring(from: buffer.index(buffer.startIndex, offsetBy: startPos))
250+
let matchBuffer = String(buffer[buffer.index(buffer.startIndex, offsetBy: startPos)...])
251251
// With a group of CHECK-DAGs, a single mismatching means the match on
252252
// that group of CHECK-DAGs fails immediately.
253253
guard let (range, variableTable) = pattern.match(matchBuffer, finalTable) else {
@@ -277,14 +277,14 @@ struct CheckString {
277277
// If there's CHECK-NOTs between two CHECK-DAGs or from CHECK to
278278
// CHECK-DAG, verify that there's no 'not' strings occurred in that
279279
// region.
280-
let skippedRegion = buffer.substring(
281-
with: Range<String.Index>(
280+
let skippedRegion = String(buffer[
281+
Range<String.Index>(
282282
uncheckedBounds: (
283283
buffer.index(buffer.startIndex, offsetBy: lastPos),
284284
buffer.index(buffer.startIndex, offsetBy: matchPos)
285285
)
286286
)
287-
)
287+
])
288288
let (cond, mutVarTable) = self.checkNot(skippedRegion, notStrings, finalTable, options)
289289
if cond {
290290
return nil

Sources/FileCheck/FileCheck.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,14 +283,14 @@ private func findFirstMatch(in inbuffer : UnsafeBufferPointer<CChar>, among pref
283283
return ("", .none, lineNumber, buffer)
284284
}
285285
let skippedPrefix = substring(in: buffer, with: NSMakeRange(0, prefix.range.location))
286-
let prefixStr = str.substring(
287-
with: Range(
286+
let prefixStr = String(str[
287+
Range(
288288
uncheckedBounds: (
289289
str.index(str.startIndex, offsetBy: prefix.range.location),
290290
str.index(str.startIndex, offsetBy: NSMaxRange(prefix.range))
291291
)
292292
)
293-
)
293+
])
294294

295295
// HACK: Conversion between the buffer and `String` causes index
296296
// mismatches when searching for strings. We're instead going to do
@@ -480,8 +480,8 @@ private func check(input b : String, against checkStrings : [CheckString], optio
480480
}
481481

482482
variableTable = mutVariableTable
483-
checkRegion = buffer.substring(to: buffer.index(buffer.startIndex, offsetBy: NSMaxRange(range)))
484-
buffer = buffer.substring(from: buffer.index(buffer.startIndex, offsetBy: NSMaxRange(range)))
483+
checkRegion = String(buffer[..<buffer.index(buffer.startIndex, offsetBy: NSMaxRange(range))])
484+
buffer = String(buffer[buffer.index(buffer.startIndex, offsetBy: NSMaxRange(range))...])
485485
j += 1
486486
}
487487

@@ -496,7 +496,7 @@ private func check(input b : String, against checkStrings : [CheckString], optio
496496
break
497497
}
498498
variableTable = mutVarTable
499-
checkRegion = checkRegion.substring(from: checkRegion.index(checkRegion.startIndex, offsetBy: NSMaxRange(range)))
499+
checkRegion = String(checkRegion[checkRegion.index(checkRegion.startIndex, offsetBy: NSMaxRange(range))...])
500500
}
501501

502502
if j == checkStrings.count {

Sources/FileCheck/Pattern.swift

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ final class Pattern {
112112
// RegEx matches.
113113
if patternStr.range(of: "{{")?.lowerBound == patternStr.startIndex {
114114
// This is the start of a regex match. Scan for the }}.
115-
patternStr = patternStr.substring(from: patternStr.index(patternStr.startIndex, offsetBy: 2))
115+
patternStr = String(patternStr[patternStr.index(patternStr.startIndex, offsetBy: 2)...])
116116
guard let end = self.findRegexVarEnd(patternStr, brackets: (open: "{", close: "}"), terminator: "}}") else {
117117
let loc = CheckLoc.inBuffer(pattern.baseAddress!, buf)
118118
diagnose(.error, at: loc, with: "found start of regex string with no end '}}'", options: options)
@@ -126,15 +126,15 @@ final class Pattern {
126126
regExPattern += "("
127127
curParen += 1
128128

129-
let substr = patternStr.substring(to: end)
129+
let substr = patternStr[..<end]
130130
let (res, paren) = self.addRegExToRegEx(substr, curParen)
131131
curParen = paren
132132
if res {
133133
return nil
134134
}
135135
regExPattern += ")"
136136

137-
patternStr = patternStr.substring(from: patternStr.index(end, offsetBy: 2))
137+
patternStr = String(patternStr[patternStr.index(end, offsetBy: 2)...])
138138
continue
139139
}
140140

@@ -146,23 +146,23 @@ final class Pattern {
146146
if patternStr.hasPrefix("[[") {
147147
// Find the closing bracket pair ending the match. End is going to be an
148148
// offset relative to the beginning of the match string.
149-
let regVar = patternStr.substring(from: patternStr.index(patternStr.startIndex, offsetBy: 2))
149+
let regVar = String(patternStr[patternStr.index(patternStr.startIndex, offsetBy: 2)...])
150150
guard let end = self.findRegexVarEnd(regVar, brackets: (open: "[", close: "]"), terminator: "]]") else {
151151
let loc = CheckLoc.inBuffer(pattern.baseAddress!, buf)
152152
diagnose(.error, at: loc, with: "invalid named regex reference, no ]] found", options: options)
153153
return nil
154154
}
155155

156-
let matchStr = regVar.substring(to: end)
157-
patternStr = patternStr.substring(from: patternStr.index(end, offsetBy: 4))
156+
let matchStr = regVar[..<end]
157+
patternStr = String(patternStr[patternStr.index(end, offsetBy: 4)...])
158158

159159
// Get the regex name (e.g. "foo").
160160
let nameEnd = matchStr.range(of: ":")
161161
let name : String
162162
if let end = nameEnd?.lowerBound {
163-
name = matchStr.substring(to: end)
163+
name = String(matchStr[..<end])
164164
} else {
165-
name = matchStr
165+
name = String(matchStr)
166166
}
167167

168168
if name.isEmpty {
@@ -218,7 +218,7 @@ final class Pattern {
218218
self.regExPattern += "("
219219
curParen += 1
220220

221-
let (res, paren) = self.addRegExToRegEx(matchStr.substring(from: matchStr.index(after: ne.lowerBound)), curParen)
221+
let (res, paren) = self.addRegExToRegEx(matchStr[matchStr.index(after: ne.lowerBound)...], curParen)
222222
curParen = paren
223223
if res {
224224
return nil
@@ -230,8 +230,8 @@ final class Pattern {
230230
// Handle fixed string matches.
231231
// Find the end, which is the start of the next regex.
232232
if let fixedMatchEnd = mino(patternStr.range(of: "{{")?.lowerBound, patternStr.range(of: "[[")?.lowerBound) {
233-
self.regExPattern += NSRegularExpression.escapedPattern(for: patternStr.substring(to: fixedMatchEnd))
234-
patternStr = patternStr.substring(from: fixedMatchEnd)
233+
self.regExPattern += NSRegularExpression.escapedPattern(for: String(patternStr[..<fixedMatchEnd]))
234+
patternStr = String(patternStr[fixedMatchEnd...])
235235
} else {
236236
// No more matches, time to quit.
237237
self.regExPattern += NSRegularExpression.escapedPattern(for: patternStr)
@@ -260,13 +260,13 @@ final class Pattern {
260260
if !expr.hasPrefix("@LINE") {
261261
return nil
262262
}
263-
expr = expr.substring(from: expr.index(expr.startIndex, offsetBy: "@LINE".utf8.count))
263+
expr = String(expr[expr.index(expr.startIndex, offsetBy: "@LINE".utf8.count)...])
264264
guard let firstC = expr.characters.first else {
265265
return "\(self.lineNumber)"
266266
}
267267

268268
if firstC == "+" {
269-
expr = expr.substring(from: expr.index(after: expr.startIndex))
269+
expr = String(expr[expr.index(after: expr.startIndex)...])
270270
} else if firstC != "-" {
271271
return nil
272272
}
@@ -350,19 +350,15 @@ final class Pattern {
350350
var mutTable = variableTable
351351
for (v, index) in self.variableDefs {
352352
assert(index < fullMatch.numberOfRanges, "Internal paren error")
353-
#if os(macOS)
354-
let r = fullMatch.rangeAt(index)
355-
#else
356-
let r = fullMatch.range(at: index)
357-
#endif
358-
mutTable[v] = buffer.substring(
359-
with: Range<String.Index>(
353+
let r = fullMatch.range(at: index)
354+
mutTable[v] = String(buffer[
355+
Range<String.Index>(
360356
uncheckedBounds: (
361357
buffer.index(buffer.startIndex, offsetBy: r.location),
362358
buffer.index(buffer.startIndex, offsetBy: NSMaxRange(r))
363359
)
364360
)
365-
)
361+
])
366362
}
367363

368364
return (fullMatch.range, mutTable)
@@ -386,7 +382,7 @@ final class Pattern {
386382
}
387383
if firstChar == "\\" {
388384
// Backslash escapes the next char within regexes, so skip them both.
389-
string = string.substring(from: string.index(string.startIndex, offsetBy: 2))
385+
string = String(string[string.index(string.startIndex, offsetBy: 2)...])
390386
offset = regVar.index(offset, offsetBy: 2)
391387
} else {
392388
switch firstChar {
@@ -405,17 +401,17 @@ final class Pattern {
405401
default:
406402
break
407403
}
408-
string = string.substring(from: string.index(after: string.startIndex))
404+
string = String(string[string.index(after: string.startIndex)...])
409405
offset = regVar.index(after: offset)
410406
}
411407
}
412408

413409
return nil
414410
}
415411

416-
private func addRegExToRegEx(_ RS : String, _ cur : Int) -> (Bool, Int) {
412+
private func addRegExToRegEx(_ RS : Substring, _ cur : Int) -> (Bool, Int) {
417413
do {
418-
let r = try NSRegularExpression(pattern: RS, options: [])
414+
let r = try NSRegularExpression(pattern: String(RS), options: [])
419415
self.regExPattern += RS
420416
return (false, cur + r.numberOfCaptureGroups)
421417
} catch let e {
@@ -435,7 +431,7 @@ func countNumNewlinesBetween(_ r : String) -> (Int, String.Index?) {
435431
guard let EOL = range.range(of: "\n")?.lowerBound ?? range.range(of: "\r")?.lowerBound else {
436432
return (NumNewLines, firstNewLine)
437433
}
438-
range = range.substring(from: EOL)
434+
range = String(range[EOL...])
439435
if range.isEmpty {
440436
return (NumNewLines, firstNewLine)
441437
}
@@ -446,7 +442,7 @@ func countNumNewlinesBetween(_ r : String) -> (Int, String.Index?) {
446442
// if Range.utf8.count > 1 && (Range.utf8[1] == '\n' || Range[1] == '\r') && (Range[0] != Range[1]) {
447443
// Range = Range.substr(1)
448444
// }
449-
range = range.substring(from: range.index(after: range.startIndex))
445+
range = String(range[range.index(after: range.startIndex)...])
450446

451447
if NumNewLines == 1 {
452448
firstNewLine = range.startIndex

0 commit comments

Comments
 (0)