@@ -112,7 +112,7 @@ final class Pattern {
112
112
// RegEx matches.
113
113
if patternStr. range ( of: " {{ " ) ? . lowerBound == patternStr. startIndex {
114
114
// 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 ) ... ] )
116
116
guard let end = self . findRegexVarEnd ( patternStr, brackets: ( open: " { " , close: " } " ) , terminator: " }} " ) else {
117
117
let loc = CheckLoc . inBuffer ( pattern. baseAddress!, buf)
118
118
diagnose ( . error, at: loc, with: " found start of regex string with no end '}}' " , options: options)
@@ -126,15 +126,15 @@ final class Pattern {
126
126
regExPattern += " ( "
127
127
curParen += 1
128
128
129
- let substr = patternStr. substring ( to : end)
129
+ let substr = patternStr [ ..< end]
130
130
let ( res, paren) = self . addRegExToRegEx ( substr, curParen)
131
131
curParen = paren
132
132
if res {
133
133
return nil
134
134
}
135
135
regExPattern += " ) "
136
136
137
- patternStr = patternStr . substring ( from : patternStr. index ( end, offsetBy: 2 ) )
137
+ patternStr = String ( patternStr [ patternStr . index ( end, offsetBy: 2 ) ... ] )
138
138
continue
139
139
}
140
140
@@ -146,23 +146,23 @@ final class Pattern {
146
146
if patternStr. hasPrefix ( " [[ " ) {
147
147
// Find the closing bracket pair ending the match. End is going to be an
148
148
// 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 ) ... ] )
150
150
guard let end = self . findRegexVarEnd ( regVar, brackets: ( open: " [ " , close: " ] " ) , terminator: " ]] " ) else {
151
151
let loc = CheckLoc . inBuffer ( pattern. baseAddress!, buf)
152
152
diagnose ( . error, at: loc, with: " invalid named regex reference, no ]] found " , options: options)
153
153
return nil
154
154
}
155
155
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 ) ... ] )
158
158
159
159
// Get the regex name (e.g. "foo").
160
160
let nameEnd = matchStr. range ( of: " : " )
161
161
let name : String
162
162
if let end = nameEnd? . lowerBound {
163
- name = matchStr. substring ( to : end)
163
+ name = String ( matchStr [ ..< end] )
164
164
} else {
165
- name = matchStr
165
+ name = String ( matchStr)
166
166
}
167
167
168
168
if name. isEmpty {
@@ -218,7 +218,7 @@ final class Pattern {
218
218
self . regExPattern += " ( "
219
219
curParen += 1
220
220
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)
222
222
curParen = paren
223
223
if res {
224
224
return nil
@@ -230,8 +230,8 @@ final class Pattern {
230
230
// Handle fixed string matches.
231
231
// Find the end, which is the start of the next regex.
232
232
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... ] )
235
235
} else {
236
236
// No more matches, time to quit.
237
237
self . regExPattern += NSRegularExpression . escapedPattern ( for: patternStr)
@@ -260,13 +260,13 @@ final class Pattern {
260
260
if !expr. hasPrefix ( " @LINE " ) {
261
261
return nil
262
262
}
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) ... ] )
264
264
guard let firstC = expr. characters. first else {
265
265
return " \( self . lineNumber) "
266
266
}
267
267
268
268
if firstC == " + " {
269
- expr = expr . substring ( from : expr. index ( after: expr. startIndex) )
269
+ expr = String ( expr [ expr . index ( after: expr. startIndex) ... ] )
270
270
} else if firstC != " - " {
271
271
return nil
272
272
}
@@ -350,19 +350,15 @@ final class Pattern {
350
350
var mutTable = variableTable
351
351
for (v, index) in self . variableDefs {
352
352
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 > (
360
356
uncheckedBounds: (
361
357
buffer. index ( buffer. startIndex, offsetBy: r. location) ,
362
358
buffer. index ( buffer. startIndex, offsetBy: NSMaxRange ( r) )
363
359
)
364
360
)
365
- )
361
+ ] )
366
362
}
367
363
368
364
return ( fullMatch. range, mutTable)
@@ -386,7 +382,7 @@ final class Pattern {
386
382
}
387
383
if firstChar == " \\ " {
388
384
// 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 ) ... ] )
390
386
offset = regVar. index ( offset, offsetBy: 2 )
391
387
} else {
392
388
switch firstChar {
@@ -405,17 +401,17 @@ final class Pattern {
405
401
default :
406
402
break
407
403
}
408
- string = string . substring ( from : string. index ( after: string. startIndex) )
404
+ string = String ( string [ string . index ( after: string. startIndex) ... ] )
409
405
offset = regVar. index ( after: offset)
410
406
}
411
407
}
412
408
413
409
return nil
414
410
}
415
411
416
- private func addRegExToRegEx( _ RS : String , _ cur : Int ) -> ( Bool , Int ) {
412
+ private func addRegExToRegEx( _ RS : Substring , _ cur : Int ) -> ( Bool , Int ) {
417
413
do {
418
- let r = try NSRegularExpression ( pattern: RS , options: [ ] )
414
+ let r = try NSRegularExpression ( pattern: String ( RS ) , options: [ ] )
419
415
self . regExPattern += RS
420
416
return ( false , cur + r. numberOfCaptureGroups)
421
417
} catch let e {
@@ -435,7 +431,7 @@ func countNumNewlinesBetween(_ r : String) -> (Int, String.Index?) {
435
431
guard let EOL = range. range ( of: " \n " ) ? . lowerBound ?? range. range ( of: " \r " ) ? . lowerBound else {
436
432
return ( NumNewLines, firstNewLine)
437
433
}
438
- range = range . substring ( from : EOL)
434
+ range = String ( range [ EOL... ] )
439
435
if range. isEmpty {
440
436
return ( NumNewLines, firstNewLine)
441
437
}
@@ -446,7 +442,7 @@ func countNumNewlinesBetween(_ r : String) -> (Int, String.Index?) {
446
442
// if Range.utf8.count > 1 && (Range.utf8[1] == '\n' || Range[1] == '\r') && (Range[0] != Range[1]) {
447
443
// Range = Range.substr(1)
448
444
// }
449
- range = range . substring ( from : range. index ( after: range. startIndex) )
445
+ range = String ( range [ range . index ( after: range. startIndex) ... ] )
450
446
451
447
if NumNewLines == 1 {
452
448
firstNewLine = range. startIndex
0 commit comments