Skip to content

Commit

Permalink
Merge pull request Carthage#2166 from Carthage/swift4-string-range-co…
Browse files Browse the repository at this point in the history
…nversion

[gardening] Utilize the conversion between Range<String.Index> and NSRange on Swift 4
  • Loading branch information
ikesyo authored Sep 21, 2017
2 parents 9bb18b9 + 16f3b2a commit 89a1133
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Source/CarthageKit/BuildSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public struct BuildSettings {
return
}

if let result = self.targetSettingsRegex.firstMatch(in: line, range: NSRange(location: 0, length: line.utf16.count)) {
let targetRange = result.range(at: 1)
if let result = self.targetSettingsRegex.firstMatch(in: line, range: NSRange(line.startIndex..., in: line)) {
let targetRange = Range(result.range(at: 1), in: line)!

flushTarget()
currentTarget = (line as NSString).substring(with: targetRange)
currentTarget = line.substring(with: targetRange)
return
}

Expand Down
6 changes: 3 additions & 3 deletions Source/CarthageKit/GitHub.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ extension Repository {
/// Enterprise instances.
public static func fromIdentifier(_ identifier: String) -> Result<(Server, Repository), ScannableError> {
// ‘owner/name’ → GitHub.com
let range = NSRange(location: 0, length: identifier.utf16.count)
let range = NSRange(identifier.startIndex..., in: identifier)
if let match = nwoRegex.firstMatch(in: identifier, range: range) {
let owner = (identifier as NSString).substring(with: match.range(at: 1))
let name = (identifier as NSString).substring(with: match.range(at: 2))
let owner = identifier.substring(with: Range(match.range(at: 1), in: identifier)!)
let name = identifier.substring(with: Range(match.range(at: 2), in: identifier)!)
return .success((.dotCom, self.init(owner: owner, name: strippingGitSuffix(name))))
}

Expand Down
11 changes: 6 additions & 5 deletions Source/CarthageKit/Xcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ private func parseSwiftVersionCommand(output: String?) -> String? {
guard
let output = output,
let regex = try? NSRegularExpression(pattern: "Apple Swift version ([0-9.]+) .*\\((.+)\\)", options: []),
let match = regex.firstMatch(in: output, options: [], range: NSRange(location: 0, length: output.characters.count))
let match = regex.firstMatch(in: output, options: [], range: NSRange(output.startIndex..., in: output))
else
{
return nil
}

guard match.numberOfRanges == 3 else { return nil }

let nsString = output as NSString
return "\(nsString.substring(with: match.range(at: 1))) (\(nsString.substring(with: match.range(at: 2))))"
let first = output.substring(with: Range(match.range(at: 1), in: output)!)
let second = output.substring(with: Range(match.range(at: 2), in: output)!)
return "\(first) (\(second))"
}

/// Determines the Swift version of a framework at a given `URL`.
Expand Down Expand Up @@ -581,10 +582,10 @@ private func build(sdk: SDK, with buildArgs: BuildArguments, in workingDirectory
pattern: "-- \(platformName) [0-9.]+ --\\n.*?\\(([0-9A-Z]{8}-([0-9A-Z]{4}-){3}[0-9A-Z]{12})\\)",
options: []
)
let lastDeviceResult = regex.matches(in: string, range: NSRange(location: 0, length: string.utf16.count)).last
let lastDeviceResult = regex.matches(in: string, range: NSRange(string.startIndex..., in: string)).last
return lastDeviceResult.map { result in
// We use the ID here instead of the name as it's guaranteed to be unique, the name isn't.
let deviceID = (string as NSString).substring(with: result.range(at: 1))
let deviceID = string.substring(with: Range(result.range(at: 1), in: string)!)
return "platform=\(platformName) Simulator,id=\(deviceID)"
}
}
Expand Down
7 changes: 3 additions & 4 deletions Source/XCDBLD/XcodeVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ public struct XcodeVersion {
}

internal init?(xcodebuildOutput: String) {
let range = NSRange(location: 0, length: xcodebuildOutput.utf16.count)
let range = NSRange(xcodebuildOutput.startIndex..., in: xcodebuildOutput)
guard let match = XcodeVersion.regex.firstMatch(in: xcodebuildOutput, range: range) else {
return nil
}

let nsString = xcodebuildOutput as NSString
let version = nsString.substring(with: match.range(at: 1))
let buildVersion = nsString.substring(with: match.range(at: 2))
let version = xcodebuildOutput.substring(with: Range(match.range(at: 1), in: xcodebuildOutput)!)
let buildVersion = xcodebuildOutput.substring(with: Range(match.range(at: 2), in: xcodebuildOutput)!)

self.init(version: version, buildVersion: buildVersion)
}
Expand Down

0 comments on commit 89a1133

Please sign in to comment.