<commit_before>//
//  XcodeProj+Serialization.swift
//  XcodeProjKit
//
//  Created by phimage on 30/07/2017.
//  Copyright © 2017 phimage (<NAME>). All rights reserved.
//

import Foundation

extension XcodeProj {

    public func write(to url: URL, format: PropertyListSerialization.PropertyListFormat? = nil,
                      projectName: String? = nil, lineEnding: String? = nil, atomic: Bool = true) throws {
        let pbxprojURL: URL
        let name: String
        if url.isDirectoryURL {
            pbxprojURL = url.appendingPathComponent(XcodeProj.pbxprojFileName, isDirectory: false)
            let subpaths = url.pathComponents
            if let projectName = projectName {
                name = projectName
            } else {
                // Find in project
                if let last = subpaths.last, let range = last.range(of: ".xcodeproj") {
                    name = String(last[...range.lowerBound])
                } else {
                    name = self.projectName // default
                }
            }
        } else {
            pbxprojURL = url
            name = projectName ?? self.projectName
        }
        let lineEnding = lineEnding ?? self.lineEnding
        let format = format ?? self.format
        if format == .openStep {
            let serializer = OpenStepSerializer(projectName: name, lineEnding: lineEnding, projectFile: self)
            try serializer.serialize().write(to: pbxprojURL, atomically: atomic, encoding: .utf8)
        } else {
            let data = try PropertyListSerialization.data(fromPropertyList: dict, format: format, options: 0)
            try data.write(to: pbxprojURL, options: atomic ? [.atomicWrite] : [])
        }
    }

    public func data(projectName: String? = nil) throws -> Data {
        if format == .openStep {
            let projectName = projectName ?? self.projectName
            let serializer = OpenStepSerializer(projectName: projectName, projectFile: self)
            return try serializer.serialize().data(using: .utf8) ?? Data()
        } else {
            return try PropertyListSerialization.data(fromPropertyList: dict, format: format, options: 0)
        }
    }

}<commit_msg>Linux compatibility<commit_after>//
//  XcodeProj+Serialization.swift
//  XcodeProjKit
//
//  Created by phimage on 30/07/2017.
//  Copyright © 2017 phimage (<NAME>). All rights reserved.
//

import Foundation

extension XcodeProj {

    public func write(to url: URL, format: PropertyListSerialization.PropertyListFormat? = nil,
                      projectName: String? = nil, lineEnding: String? = nil, atomic: Bool = true) throws {
        let pbxprojURL: URL
        let name: String
        if url.isDirectoryURL {
            pbxprojURL = url.appendingPathComponent(XcodeProj.pbxprojFileName, isDirectory: false)
            let subpaths = url.pathComponents
            if let projectName = projectName {
                name = projectName
            } else {
                // Find in project
                if let last = subpaths.last, let range = last.range(of: ".xcodeproj") {
                    name = String(last[...range.lowerBound])
                } else {
                    name = self.projectName // default
                }
            }
        } else {
            pbxprojURL = url
            name = projectName ?? self.projectName
        }
        let lineEnding = lineEnding ?? self.lineEnding
        let format = format ?? self.format
        if format == .openStep {
            let serializer = OpenStepSerializer(projectName: name, lineEnding: lineEnding, projectFile: self)
            try serializer.serialize().write(to: pbxprojURL, atomically: atomic, encoding: .utf8)
        } else {
            let data = try PropertyListSerialization.data(fromPropertyList: dict, format: format, options: 0)
            #if os(Linux)
            try data.write(to: pbxprojURL, options: []) // error no attomic on linux
            #else
            try data.write(to: pbxprojURL, options: atomic ? [.atomicWrite] : [])
            #endif
        }
    }

    public func data(projectName: String? = nil) throws -> Data {
        if format == .openStep {
            let projectName = projectName ?? self.projectName
            let serializer = OpenStepSerializer(projectName: projectName, projectFile: self)
            return try serializer.serialize().data(using: .utf8) ?? Data()
        } else {
            return try PropertyListSerialization.data(fromPropertyList: dict, format: format, options: 0)
        }
    }

}
{'fraction_non_alphanumeric': 0.09631417288284336, 'fraction_numerical': 0.007020623080298377, 'mean_word_length': 1.9875491480996068, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '3936518', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1203, 'n_words': 332}