<commit_before>import Foundation
#if SWIFT_PACKAGE
    import CSQLite
#elseif GRDBCIPHER
    import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
    import SQLite3
#endif

/// A Collation is a string comparison function used by SQLite.
public final class DatabaseCollation {
    public let name: String
    let function: (Int32, UnsafeRawPointer?, Int32, UnsafeRawPointer?) -> ComparisonResult
    
    /// Creates a collation.
    ///
    ///     let collation = DatabaseCollation("localized_standard") { (string1, string2) in
    ///         return (string1 as NSString).localizedStandardCompare(string2)
    ///     }
    ///     db.add(collation: collation)
    ///     try db.execute(sql: "CREATE TABLE file (name TEXT COLLATE localized_standard")
    ///
    /// - parameters:
    ///     - name: The function name.
    ///     - function: A function that compares two strings.
    public init(_ name: String, function: @escaping (String, String) -> ComparisonResult) {
        self.name = name
        self.function = { (length1, buffer1, length2, buffer2) in
            // Buffers are not C strings: they do not end with \0.
            let string1 = String(bytesNoCopy: UnsafeMutableRawPointer(mutating: buffer1.unsafelyUnwrapped), length: Int(length1), encoding: .utf8, freeWhenDone: false)!
            let string2 = String(bytesNoCopy: UnsafeMutableRawPointer(mutating: buffer2.unsafelyUnwrapped), length: Int(length2), encoding: .utf8, freeWhenDone: false)!
            return function(string1, string2)
        }
    }
}

extension DatabaseCollation: Hashable {
    // Collation equality is based on the sqlite3_strnicmp SQLite function.
    // (see https://www.sqlite.org/c3ref/create_collation.html). Computing
    // a hash value that honors the Swift Hashable contract (value equality
    // implies hash equality) is thus non trivial. But it's not that
    // important, since this hashValue is only used when one adds
    // or removes a collation from a database connection.
    /// :nodoc:
    public func hash(into hasher: inout Hasher) {
        hasher.combine(0)
    }
    
    /// Two collations are equal if they share the same name (case insensitive)
    /// :nodoc:
    public static func == (lhs: DatabaseCollation, rhs: DatabaseCollation) -> Bool {
        // See https://www.sqlite.org/c3ref/create_collation.html
        return sqlite3_stricmp(lhs.name, lhs.name) == 0
    }
}<commit_msg>Fix failing test for #561<commit_after>import Foundation
#if SWIFT_PACKAGE
    import CSQLite
#elseif GRDBCIPHER
    import SQLCipher
#elseif !GRDBCUSTOMSQLITE && !GRDBCIPHER
    import SQLite3
#endif

/// A Collation is a string comparison function used by SQLite.
public final class DatabaseCollation {
    public let name: String
    let function: (Int32, UnsafeRawPointer?, Int32, UnsafeRawPointer?) -> ComparisonResult
    
    /// Creates a collation.
    ///
    ///     let collation = DatabaseCollation("localized_standard") { (string1, string2) in
    ///         return (string1 as NSString).localizedStandardCompare(string2)
    ///     }
    ///     db.add(collation: collation)
    ///     try db.execute(sql: "CREATE TABLE file (name TEXT COLLATE localized_standard")
    ///
    /// - parameters:
    ///     - name: The function name.
    ///     - function: A function that compares two strings.
    public init(_ name: String, function: @escaping (String, String) -> ComparisonResult) {
        self.name = name
        self.function = { (length1, buffer1, length2, buffer2) in
            // Buffers are not C strings: they do not end with \0.
            let string1 = String(bytesNoCopy: UnsafeMutableRawPointer(mutating: buffer1.unsafelyUnwrapped), length: Int(length1), encoding: .utf8, freeWhenDone: false)!
            let string2 = String(bytesNoCopy: UnsafeMutableRawPointer(mutating: buffer2.unsafelyUnwrapped), length: Int(length2), encoding: .utf8, freeWhenDone: false)!
            return function(string1, string2)
        }
    }
}

extension DatabaseCollation: Hashable {
    // Collation equality is based on the sqlite3_strnicmp SQLite function.
    // (see https://www.sqlite.org/c3ref/create_collation.html). Computing
    // a hash value that honors the Swift Hashable contract (value equality
    // implies hash equality) is thus non trivial. But it's not that
    // important, since this hashValue is only used when one adds
    // or removes a collation from a database connection.
    /// :nodoc:
    public func hash(into hasher: inout Hasher) {
        hasher.combine(0)
    }
    
    /// Two collations are equal if they share the same name (case insensitive)
    /// :nodoc:
    public static func == (lhs: DatabaseCollation, rhs: DatabaseCollation) -> Bool {
        // See https://www.sqlite.org/c3ref/create_collation.html
        return sqlite3_stricmp(lhs.name, rhs.name) == 0
    }
}
{'fraction_non_alphanumeric': 0.10209531635168446, 'fraction_numerical': 0.012941659819227609, 'mean_word_length': 2.806880375293198, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3607464', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1405, 'n_words': 444}