Skip to content

Commit

Permalink
Use extended string delimiters on regex literals to make them more re…
Browse files Browse the repository at this point in the history
…adable.
  • Loading branch information
GetToSet committed Jun 6, 2021
1 parent 073a398 commit 26b5b06
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion MacSymbolicator/DSYM Search/FileSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private class InternalFileSearch: FileSearchResults, FileSearchQuery {

guard let dwarfDumpOutput = commandResult.output?.trimmed else { return nil }

let foundUUIDs = dwarfDumpOutput.scan(pattern: "UUID: (.*) \\(").flatMap({ $0 })
let foundUUIDs = dwarfDumpOutput.scan(pattern: #"UUID: (.*) \("#).flatMap({ $0 })
for foundUUID in foundUUIDs {
if uuids.contains(foundUUID) {
return FileSearchResult(path: file, matchedUUID: foundUUID)
Expand Down
4 changes: 2 additions & 2 deletions MacSymbolicator/Models/BinaryImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ struct BinaryImage {
let uuid: BinaryUUID
let loadAddress: String

private static let binaryImagesSectionRegex = "Binary Images:.*"
private static let binaryImagesLineRegex = "(0x.*?)\\s.*?<(.*?)>"
private static let binaryImagesSectionRegex = #"Binary Images:.*"#
private static let binaryImagesLineRegex = #"(0x.*?)\s.*?<(.*?)>"#

static func find(in content: String) -> [BinaryImage] {
let binaryImagesSection = content.scan(
Expand Down
4 changes: 2 additions & 2 deletions MacSymbolicator/Models/CrashFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ public class CrashFile {
self.path = path
self.filename = path.lastPathComponent

self.architecture = content.scan(pattern: "^Code Type:(.*?)(\\(.*\\))?$").first?.first?.trimmed
self.architecture = content.scan(pattern: #"^Code Type:(.*?)(\(.*\))?$"#).first?.first?.trimmed
.components(separatedBy: " ").first.flatMap(Architecture.init)

// In the case of "ARM" the actual architecture is on the first line of Binary Images
if self.architecture?.isIncomplete == true {
self.architecture = (content.scan(
pattern: "Binary Images:.*\\s+([^\\s]+)\\s+<",
pattern: #"Binary Images:.*\s+([^\s]+)\s+<"#,
options: [.caseInsensitive, .anchorsMatchLines, .dotMatchesLineSeparators]
).first?.first?.trimmed).flatMap(Architecture.init)
}
Expand Down
2 changes: 1 addition & 1 deletion MacSymbolicator/Models/DSYMFile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public struct DSYMFile: Equatable {

output?.components(separatedBy: .newlines).forEach { line in
guard
let match = line.scan(pattern: "UUID: (.*) \\((.*)\\)").first, match.count == 2,
let match = line.scan(pattern: #"UUID: (.*) \((.*)\)"#).first, match.count == 2,
let uuid = match.first.flatMap(BinaryUUID.init),
let architecture = match.last.flatMap(Architecture.init)
else { return }
Expand Down
12 changes: 6 additions & 6 deletions MacSymbolicator/Models/StackTraceCall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ struct StackTraceCall {
let address: String
let loadAddress: String

private static let crashLineRegex = "^\\d+\\s+.*?0x.*?\\s0x.*?\\s"
private static let crashAddressRegex = "^\\d+\\s+.*?(0x.*?)\\s(0x.*?)\\s"
private static let crashLineRegex = #"^\d+\s+.*?0x.*?\s0x.*?\s"#
private static let crashAddressRegex = #"^\d+\s+.*?(0x.*?)\s(0x.*?)\s"#

static func crashReplacementRegex(address: String) -> String {
"\(address)\\s0x.*?$"
#"\#(address)\s0x.*?$"#
}

private static let sampleLineRegex = "\\?{3}\\s+\\(in\\s.*?\\)\\s+load\\saddress.*?\\[0x.*?\\]"
private static let sampleAddressRegex = "\\?{3}\\s+\\(in\\s.*?\\)\\s+load\\saddress\\s*(0x.*?)\\s.*?\\[(0x.*?)\\]"
private static let sampleLineRegex = #"\?{3}\s+\(in\s.*?\)\s+load\saddress.*?\[0x.*?\]"#
private static let sampleAddressRegex = #"\?{3}\s+\(in\s.*?\)\s+load\saddress\s*(0x.*?)\s.*?\[(0x.*?)\]"#

static func sampleReplacementRegex(address: String) -> String {
"\\?{3}.*?\\[\(address)\\]"
#"\?{3}.*?\[\#(address)\]"#
}

static func find(in content: String) -> [StackTraceCall] {
Expand Down

0 comments on commit 26b5b06

Please sign in to comment.