 
 // MARK: Private Functions
 
-/** Remove duplicated coloring ranges.
- 
- This sanitization will reduce performance time of `applyHighlights:highlights:layoutManager:` significantly.
- Adding temporary attribute to a layoutManager is quite sluggish,
- so we want to remove useless highlighting ranges as many as possible beforehand.
- */
+private extension String {
+    
+    /// find and return ranges of passed-in substring with the given range of receiver.
+    func ranges(of substring: String, range searchRange: NSRange) -> [NSRange] {
+        
+        var ranges = [NSRange]()
+        
+        var location = searchRange.location
+        while location != NSNotFound {
+            let range = (self as NSString).range(of: substring, options: .literal, range: NSRange(location..<searchRange.upperBound))
+            location = range.upperBound
+            
+            guard range.location != NSNotFound else { break }
+            guard !self.isCharacterEscaped(at: range.location) else { continue }
+            
+            ranges.append(range)
+        }
+        
+        return ranges
+    }
+    
+}
+
+
+
+/// Remove duplicated coloring ranges.
+///
+/// This sanitization will reduce performance time of `applyHighlights:highlights:layoutManager:` significantly.
+/// Adding temporary attribute to a layoutManager is quite sluggish,
+/// so we want to remove useless highlighting ranges as many as possible beforehand.
 private func sanitize(highlights: [SyntaxType: [NSRange]]) -> [SyntaxType: [NSRange]] {
     
     var sanitizedHighlights = [SyntaxType: [NSRange]]()

        }
        
        for quote in self.pairedQuoteTypes.keys {
            for range in self.ranges(string: quote) {
                positions.append(QuoteCommentItem(kind: quote, role: [.begin, .end], range: range))
            }
        }

        var sanitizedRanges = [NSRange]()
        
        for range in ranges {
            guard !highlightedIndexes.contains(in: range) else { continue }
            
            sanitizedRanges.append(range)
            highlightedIndexes.add(in: range)
        }
        
        guard !sanitizedRanges.isEmpty else { continue }
        
        sanitizedHighlights[type] = sanitizedRanges
    }
    
    return sanitizedHighlights
