@@ -40,24 +40,22 @@ enum ChatMarkdownPreprocessor {
4040 if matches. isEmpty { return Result ( cleaned: self . normalize ( withoutTimestamps) , images: [ ] ) }
4141
4242 var images : [ InlineImage ] = [ ]
43- var cleaned = withoutTimestamps
43+ let cleaned = NSMutableString ( string : withoutTimestamps)
4444
4545 for match in matches. reversed ( ) {
4646 guard match. numberOfRanges >= 3 else { continue }
4747 let label = ns. substring ( with: match. range ( at: 1 ) )
4848 let source = ns. substring ( with: match. range ( at: 2 ) )
4949
50- let start = cleaned. index ( cleaned. startIndex, offsetBy: match. range. location)
51- let end = cleaned. index ( start, offsetBy: match. range. length)
5250 if let inlineImage = self . inlineImage ( label: label, source: source) {
5351 images. append ( inlineImage)
54- cleaned. replaceSubrange ( start ..< end , with: " " )
52+ cleaned. replaceCharacters ( in : match . range , with: " " )
5553 } else {
56- cleaned. replaceSubrange ( start ..< end , with: self . fallbackImageLabel ( label) )
54+ cleaned. replaceCharacters ( in : match . range , with: self . fallbackImageLabel ( label) )
5755 }
5856 }
5957
60- return Result ( cleaned: self . normalize ( cleaned) , images: images. reversed ( ) )
58+ return Result ( cleaned: self . normalize ( cleaned as String ) , images: images. reversed ( ) )
6159 }
6260
6361 private static func inlineImage( label: String , source: String ) -> InlineImage ? {
0 commit comments