<commit_before>import Foundation
import LoggerAPI

struct LicensePlistHolder {
    let root: Data
    let items: [(LicenseInfo, Data)]
    static func load(licenses: [LicenseInfo], options: Options) -> LicensePlistHolder {
        let rootItems: [[String: String]] = {
            guard !licenses.isEmpty else { return [] }
            return [["Type": "PSGroupSpecifier", "Title": "Licenses"]] + licenses.map { license in
                return ["Type": "PSChildPaneSpecifier",
                        "Title": license.name(withVersion: options.config.addVersionNumbers),
                        "File": "\(options.prefix)/\(license.name)"]
            }
        }()
        let root = try! PropertyListSerialization.data(fromPropertyList: ["PreferenceSpecifiers": rootItems],
                                                       format: .xml,
                                                       options: 0)
        let items: [(LicenseInfo, Data)] = licenses.map { license in
            let item = ["PreferenceSpecifiers":
                license.body.components(separatedBy: "\n\n").map { (paragraph) -> [String: String] in
                    ["Type": "PSGroupSpecifier", "FooterText": paragraph.split(separator: "\n").joined(separator: " ")]
                }
            ]
            let value = try! PropertyListSerialization.data(fromPropertyList: item, format: .xml, options: 0)
            return (license, value)
        }
        return LicensePlistHolder(root: root, items: items)
    }

    static func loadAllToRoot(licenses: [LicenseInfo]) -> LicensePlistHolder {
        let rootItem: [[String: String]] = {
            guard !licenses.isEmpty else { return [] }
            let body = licenses
                .compactMap { lincense in
                    return ["Type": "PSGroupSpecifier",
                            "Title": lincense.name,
                            "FooterText": lincense.body
                            ]
                }
            return body
        }()
        let root = try! PropertyListSerialization.data(fromPropertyList: ["PreferenceSpecifiers": rootItem],
                                                       format: .xml,
                                                       options: 0)
        return LicensePlistHolder(root: root, items: [])
    }

    func deserialized() -> (root: [String: [[String: String]]], items: [(LicenseInfo, [String: [[String: String]]])]) {
        let root = try! PropertyListSerialization.propertyList(from: self.root, options: [], format: nil) as! [String: [[String: String]]]
        let items: [(LicenseInfo, [String: [[String: String]]])] = self.items.map { license, data in
            let value = try! PropertyListSerialization.propertyList(from: data, options: [], format: nil) as! [String: [[String: String]]]
            return (license, value)
        }
        return (root: root, items: items)
    }
    func write(to rootPath: URL, itemsPath: URL) {
        do {
            try root.write(to: rootPath)
            try items.forEach {
                try $0.1.write(to: itemsPath.appendingPathComponent("\($0.0.name).plist"))
            }
        } catch let e {
            Log.error("Failed to write to (rootPath: \(rootPath), itemsPath: \(itemsPath)).\nerror: \(e)")
        }

    }
}
<commit_msg>don't convert newline to space<commit_after>import Foundation
import LoggerAPI

struct LicensePlistHolder {
    let root: Data
    let items: [(LicenseInfo, Data)]
    static func load(licenses: [LicenseInfo], options: Options) -> LicensePlistHolder {
        let rootItems: [[String: String]] = {
            guard !licenses.isEmpty else { return [] }
            return [["Type": "PSGroupSpecifier", "Title": "Licenses"]] + licenses.map { license in
                return ["Type": "PSChildPaneSpecifier",
                        "Title": license.name(withVersion: options.config.addVersionNumbers),
                        "File": "\(options.prefix)/\(license.name)"]
            }
        }()
        let root = try! PropertyListSerialization.data(fromPropertyList: ["PreferenceSpecifiers": rootItems],
                                                       format: .xml,
                                                       options: 0)
        let items: [(LicenseInfo, Data)] = licenses.map { license in
            let item = ["PreferenceSpecifiers":
                license.body.components(separatedBy: "\n\n").map { (paragraph) -> [String: String] in
                    ["Type": "PSGroupSpecifier", "FooterText": paragraph]
                }
            ]
            let value = try! PropertyListSerialization.data(fromPropertyList: item, format: .xml, options: 0)
            return (license, value)
        }
        return LicensePlistHolder(root: root, items: items)
    }

    static func loadAllToRoot(licenses: [LicenseInfo]) -> LicensePlistHolder {
        let rootItem: [[String: String]] = {
            guard !licenses.isEmpty else { return [] }
            let body = licenses
                .compactMap { lincense in
                    return ["Type": "PSGroupSpecifier",
                            "Title": lincense.name,
                            "FooterText": lincense.body
                            ]
                }
            return body
        }()
        let root = try! PropertyListSerialization.data(fromPropertyList: ["PreferenceSpecifiers": rootItem],
                                                       format: .xml,
                                                       options: 0)
        return LicensePlistHolder(root: root, items: [])
    }

    func deserialized() -> (root: [String: [[String: String]]], items: [(LicenseInfo, [String: [[String: String]]])]) {
        let root = try! PropertyListSerialization.propertyList(from: self.root, options: [], format: nil) as! [String: [[String: String]]]
        let items: [(LicenseInfo, [String: [[String: String]]])] = self.items.map { license, data in
            let value = try! PropertyListSerialization.propertyList(from: data, options: [], format: nil) as! [String: [[String: String]]]
            return (license, value)
        }
        return (root: root, items: items)
    }
    func write(to rootPath: URL, itemsPath: URL) {
        do {
            try root.write(to: rootPath)
            try items.forEach {
                try $0.1.write(to: itemsPath.appendingPathComponent("\($0.0.name).plist"))
            }
        } catch let e {
            Log.error("Failed to write to (rootPath: \(rootPath), itemsPath: \(itemsPath)).\nerror: \(e)")
        }

    }
}

{'fraction_non_alphanumeric': 0.12422360248447205, 'fraction_numerical': 0.0021208907741251328, 'mean_word_length': 1.7844791227330241, 'pattern_counts': {'":': 26, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1458756', 'n_tokens_mistral': 1687, 'n_tokens_neox': 1641, 'n_words': 431}