<commit_before>public struct Cookies {
    private var cookies = Set<Cookie>()

    public init() { }

    public init<Cookies: Sequence where Cookies.Iterator.Element == Cookie>(cookies: Cookies) {
        for cookie in cookies {
            self.cookies.insert(cookie)
        }
    }

    public mutating func insert(_ cookie: Cookie) {
        cookies.insert(cookie)
    }

    public mutating func remove(_ cookie: Cookie) {
        cookies.remove(cookie)
    }

    public mutating func removeAll() {
        cookies.removeAll()
    }

    public func contains(_ cookie: Cookie) -> Bool {
        return cookies.contains(cookie)
    }

    public subscript(name: String) -> String? {
        get {
            guard let index = index(ofCookieNamed: name) else {
                return nil
            }

            return cookies[index].value
        }

        set {
            guard let value = newValue else {
                if let index = index(ofCookieNamed: name) {
                    cookies.remove(at: index)
                }

                return
            }

            cookies.insert(Cookie(name: name, value: value))
        }
    }

    private func index(ofCookieNamed name: String) -> SetIndex<Cookie>? {
        return cookies.index(where: { $0.name == name })
    }
}

extension Cookies: ArrayLiteralConvertible {
    public init(arrayLiteral cookies: Cookie...) {
        self.init(cookies: cookies)
    }
}

extension Cookies: Sequence {
    public typealias Iterator = SetIterator<Cookie>

    public func makeIterator() -> Iterator {
        return cookies.makeIterator()
    }
}

// MARK: Parsing

extension Cookies {
    init(_ cookieString: String) {
        var cookies: Cookies = []

        let tokens = cookieString.utf8.split(separator: .semicolon)

        for token in tokens {
            let cookieTokens = token.split(separator: .equals, maxSplits: 1)

            guard cookieTokens.count == 2 else {
                continue
            }

            let name = cookieTokens[0].string ?? ""
            let value = cookieTokens[1].string ?? ""

            cookies[name] = value
        }

        self = cookies
    }
}

// MARK: Serialization

extension Cookies {
    func serialize() -> String? {
        guard !cookies.isEmpty else { return nil }
        return map({ $0.serialize() }).joined(separator: ";")
    }
}<commit_msg>multiline cookies<commit_after>public struct Cookies {
    private var cookies = Set<Cookie>()

    public init() { }

    public init<Cookies: Sequence where Cookies.Iterator.Element == Cookie>(cookies: Cookies) {
        for cookie in cookies {
            self.cookies.insert(cookie)
        }
    }

    public mutating func insert(_ cookie: Cookie) {
        cookies.insert(cookie)
    }

    public mutating func remove(_ cookie: Cookie) {
        cookies.remove(cookie)
    }

    public mutating func removeAll() {
        cookies.removeAll()
    }

    public func contains(_ cookie: Cookie) -> Bool {
        return cookies.contains(cookie)
    }

    public subscript(name: String) -> String? {
        get {
            guard let index = index(ofCookieNamed: name) else {
                return nil
            }

            return cookies[index].value
        }

        set {
            guard let value = newValue else {
                if let index = index(ofCookieNamed: name) {
                    cookies.remove(at: index)
                }

                return
            }

            cookies.insert(Cookie(name: name, value: value))
        }
    }

    private func index(ofCookieNamed name: String) -> SetIndex<Cookie>? {
        return cookies.index(where: { $0.name == name })
    }
}

extension Cookies: ArrayLiteralConvertible {
    public init(arrayLiteral cookies: Cookie...) {
        self.init(cookies: cookies)
    }
}

extension Cookies: Sequence {
    public typealias Iterator = SetIterator<Cookie>

    public func makeIterator() -> Iterator {
        return cookies.makeIterator()
    }
}

// MARK: Parsing

extension Cookies {
    init(_ cookieString: String) {
        var cookies: Cookies = []

        let tokens = cookieString.utf8.split(separator: .semicolon)

        for token in tokens {
            let cookieTokens = token.split(separator: .equals, maxSplits: 1)

            guard cookieTokens.count == 2 else {
                continue
            }

            let name = cookieTokens[0].string ?? ""
            let value = cookieTokens[1].string ?? ""

            cookies[name] = value
        }

        self = cookies
    }
}

// MARK: Serialization

extension Cookies {
    func serialize() -> String? {
        guard !cookies.isEmpty else { return nil }
        return map { $0.serialize() } .joined(separator: "\r\nSet-Cookie: ")
    }
}
{'fraction_non_alphanumeric': 0.10210899979118813, 'fraction_numerical': 0.0029233660471914805, 'mean_word_length': 1.8786057692307692, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2867394', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1263, 'n_words': 338}