-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed a bug where nostr entities in URLs were parsed like quoted note…
… links #1429
- Loading branch information
1 parent
404d12a
commit 675fd3c
Showing
5 changed files
with
89 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Foundation | ||
|
||
extension NSRegularExpression { | ||
|
||
/// Helper function to perform replacements using NSRegularExpression. | ||
/// - Parameters: | ||
/// - string: The input string. | ||
/// - options: Matching options to use. | ||
/// - range: A range in which to perform replacements. | ||
/// - transform: A transformation function to perform on the match before replacement. | ||
/// - Returns: The input string with matches replaced. | ||
func stringByReplacingMatches( | ||
in string: String, | ||
options: NSRegularExpression.MatchingOptions = [], | ||
range: NSRange, | ||
transform: (NSTextCheckingResult) -> String | ||
) -> String { | ||
var result = "" | ||
var lastRangeEnd = string.startIndex | ||
|
||
for match in matches(in: string, options: options, range: range) { | ||
guard let matchRange = Range(match.range, in: string) else { continue } | ||
result += string[lastRangeEnd..<matchRange.lowerBound] | ||
result += transform(match) | ||
lastRangeEnd = matchRange.upperBound | ||
} | ||
|
||
result += string[lastRangeEnd..<string.endIndex] | ||
return result | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters