-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString.swift
More file actions
43 lines (36 loc) · 1.01 KB
/
Copy pathString.swift
File metadata and controls
43 lines (36 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// String.swift
// DevLog
//
// Created by opfic on 5/19/25.
//
import Foundation
extension String {
private static let todoReferencePattern = #"^([ \t]*)-[ \t]+refs[ \t]+#(\d+)[ \t]*$"#
var todoReferenceNumbers: [Int] {
guard
let expression = try? NSRegularExpression(
pattern: Self.todoReferencePattern,
options: [.anchorsMatchLines]
)
else {
return []
}
let range = NSRange(startIndex..., in: self)
let matches = expression.matches(in: self, options: [], range: range)
var numbers = [Int]()
var seen = Set<Int>()
for match in matches {
guard
let numberRange = Range(match.range(at: 2), in: self),
let number = Int(self[numberRange]),
!seen.contains(number)
else {
continue
}
seen.insert(number)
numbers.append(number)
}
return numbers
}
}