Skip to content

Commit f2971d5

Browse files
authored
Merge pull request apple#678 from thomasvl/swift4
Update some plugin code for Swift 4.
2 parents 3c0fcc9 + 2150044 commit f2971d5

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

Sources/PluginLibrary/NamingUtils.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,11 @@ fileprivate func sanitizeTypeName(_ s: String, disambiguator: String) -> String
190190
// the disambiguator, sanitizing the root, then re-adding the
191191
// disambiguator:
192192
let e = s.index(s.endIndex, offsetBy: -disambiguator.characters.count)
193-
let truncated = s.substring(to: e)
193+
#if swift(>=4.0)
194+
let truncated = String(s[..<e])
195+
#else
196+
let truncated = s.substring(to: e)
197+
#endif
194198
return sanitizeTypeName(truncated, disambiguator: disambiguator) + disambiguator
195199
} else {
196200
return s
@@ -366,7 +370,11 @@ public enum NamingUtils {
366370

367371
let count = fromChars.distance(from: fromChars.startIndex, to: fromIndex)
368372
let idx = from.index(from.startIndex, offsetBy: count)
369-
return from[idx..<from.endIndex]
373+
#if swift(>=4.0)
374+
return String(from[idx..<from.endIndex])
375+
#else
376+
return from[idx..<from.endIndex]
377+
#endif
370378
}
371379
}
372380

Sources/protoc-gen-swift/StringUtils.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,12 @@ func partition(string: String, atFirstOccurrenceOf substring: String) -> (String
3838
guard let index = string.range(of: substring)?.lowerBound else {
3939
return (string, "")
4040
}
41-
return (string.substring(to: index), string.substring(from: string.index(after: index)))
41+
#if swift(>=4.0)
42+
return (String(string[..<index]),
43+
String(string[string.index(after: index)...]))
44+
#else
45+
return (string.substring(to: index), string.substring(from: string.index(after: index)))
46+
#endif
4247
}
4348

4449
func parseParameter(string: String?) -> [(key:String, value:String)] {

0 commit comments

Comments
 (0)