         ///
         /// If the range ends before the actual end of the string,
         /// an ellipsis is added at the end.
-        func windowSubstring(_ s: NSString, _ range: NSRange, isPrefix: Bool = false, isSuffix: Bool = false) -> String {
-            let validRange = NSMakeRange(range.location, min(range.length, s.length - range.location))
-            let substring = s.substring(with: validRange)
+        func windowSubstring(
+          _ s: String,
+          _ range: (location: Int, length: Int),
+          isPrefix: Bool = false,
+          isSuffix: Bool = false
+        ) -> String {
+            let minLen = min(range.length, s.count - range.location)
+            let startIndex = s.index(s.startIndex, offsetBy: range.location)
+            let endIndex = s.index(startIndex, offsetBy: minLen)
+            let substring = String(s[startIndex..<endIndex])
 
             let prefix = isPrefix && range.location > 0 ? ellipsis : ""
-            let suffix = isSuffix && (s.length - range.location > range.length) ? ellipsis : ""
+            let suffix = isSuffix && (s.count - range.location > range.length) ? ellipsis : ""
 
             return "\(prefix)\(substring)\(suffix)"
         }


    if translate != expected {
        //Find text difference
        let difference = prettyFirstDifferenceBetweenStrings(translate as NSString, expected as NSString)
        XCTFail(difference)
    }
}

/// :param: s1 First String
/// :param: s2 Second String
///
/// :returns: .differenceAtIndex(i) or .noDifference
public func firstDifferenceBetweenStrings(_ s1: String, _ s2: String) -> FirstDifferenceResult {
    let len1 = s1.count
    let len2 = s2.count

    let lenMin = min(len1, len2)

    for i in 0..<lenMin {
        let i1 = s1.index(s1.startIndex, offsetBy: i)
        let i2 = s2.index(s2.startIndex, offsetBy: i)
        if s1[i1] != s2[i2] {
            return .differenceAtIndex(i)
        }
    }

    if len1 < len2 {
        return .differenceAtIndex(len1)
    }

    if len2 < len1 {
        return .differenceAtIndex(len2)
    }

    return .noDifference
}


