Skip to content

Commit 9722796

Browse files
committed
Migrate AutoLatexCommand to regex literals (partially)
1 parent 38e0756 commit 9722796

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Diff for: Sources/D2Commands/math/AutoLatexCommand.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import Logging
77
fileprivate let log = Logger(label: "D2Commands.AutoLatexCommand")
88

99
/// A simple heuristic for detecting "formulas" in messages. Matches a single character.
10-
fileprivate let formulaPattern = try! LegacyRegex(from: "[0-9{}\\+\\-*\\/\\[\\]\\\\|]")
10+
fileprivate let formulaPattern = #/[0-9{}\+\-*\/\[\]\\|]/#
1111
/// Matches text that should be "escaped" when rendering the message as LaTeX.
12-
fileprivate let textPattern = try! LegacyRegex(from: "(?<!\\\\)\\b\\s*\\p{L}[\\p{L}\\s]*")
12+
fileprivate let textPattern = try! LegacyRegex(from: "(?<!\\\\)\\b\\s*\\p{L}[\\p{L}\\s]*") // TODO: Migrate to Swift regex once lookbehind is supported
1313

1414
public class AutoLatexCommand: StringCommand {
1515
public let info = CommandInfo(
@@ -39,7 +39,7 @@ public class AutoLatexCommand: StringCommand {
3939
return
4040
}
4141

42-
if formulaPattern.matchCount(in: content) > 0 {
42+
if !content.matches(of: formulaPattern).isEmpty {
4343
let formula = escapeText(in: content)
4444
latexRenderer.renderImage(from: formula, scale: 1.5).listenOrLogError {
4545
do {

0 commit comments

Comments
 (0)