From cde3a785ebe6a9d0a402e61934745e33215a930b Mon Sep 17 00:00:00 2001 From: Keith Smiley Date: Wed, 5 Apr 2023 11:41:46 -0700 Subject: [PATCH] Regex --- Sources/unused-imports/main.swift | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Sources/unused-imports/main.swift b/Sources/unused-imports/main.swift index 157f626..e8cfcd8 100644 --- a/Sources/unused-imports/main.swift +++ b/Sources/unused-imports/main.swift @@ -3,8 +3,7 @@ import Darwin import Foundation private typealias References = (usrs: Set, typealiases: Set) -private let identifierRegex = try NSRegularExpression( - pattern: "([a-zA-Z_][a-zA-Z0-9_]*)", options: []) +private let identifierRegex = try Regex("([a-zA-Z_][a-zA-Z0-9_]*)") private let ignoreRegex = try Regex(#"// *ignore-import$"#) private var cachedLines = [String: [String.SubSequence]]() @@ -37,15 +36,14 @@ private func getReferences(unitReader: UnitReader, recordReader: RecordReader) - if occurrence.symbol.subkind == .swiftExtensionOfStruct { usrs.insert(occurrence.symbol.usr) let lines = cachedLines[unitReader.mainFile]! - let line = String(lines[occurrence.location.line - 1]) - let indexes = line.index(line.startIndex, offsetBy: occurrence.location.column - 1)..