<commit_before>/*
 This source file is part of the Swift.org open source project

 Copyright 2015 - 2016 Apple Inc. and the Swift project authors
 Licensed under Apache License v2.0 with Runtime Library Exception

 See http://swift.org/LICENSE.txt for license information
 See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

protocol YAMLRepresentable {
    var YAML: String { get }
}

extension String: YAMLRepresentable {
    var YAML: String {
        if self == "" { return "\"\"" }
        return self
    }
}

extension Bool: YAMLRepresentable {
    var YAML: String {
        if self { return "true" }
        return "false"
    }
}

extension Array where Element: YAMLRepresentable {
    var YAML: String {
        func quote(_ input: String) -> String {
            for c in input.characters {
                if c == "@" || c == " " || c == "-" || c == "&" {
                    return "\"\(input)\""
                }
            }
            return input
        }
        let stringArray = self.flatMap { String($0) }
        return "[" + stringArray.map(quote).joined(separator: ", ") + "]"
    }
}<commit_msg>[Build] Optimize YAML quoting for strings.<commit_after>/*
 This source file is part of the Swift.org open source project

 Copyright 2015 - 2016 Apple Inc. and the Swift project authors
 Licensed under Apache License v2.0 with Runtime Library Exception

 See http://swift.org/LICENSE.txt for license information
 See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

protocol YAMLRepresentable {
    var YAML: String { get }
}

extension String: YAMLRepresentable {
    var YAML: String {
        if self == "" { return "\"\"" }
        for c in utf8 {
            switch c {
            case UInt8(ascii: "@"), UInt8(ascii: " "), UInt8(ascii: "-"), UInt8(ascii: "&"):
                return "\"\(self)\""
            default:
                continue
            }
        }
        return self
    }
}

extension Bool: YAMLRepresentable {
    var YAML: String {
        if self { return "true" }
        return "false"
    }
}

extension Array where Element: YAMLRepresentable {
    var YAML: String {
        return "[" + map{$0.YAML}.joined(separator: ", ") + "]"
    }
}
{'fraction_non_alphanumeric': 0.11743612729717616, 'fraction_numerical': 0.012102196324518153, 'mean_word_length': 2.1260504201680672, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '1425984', 'n_tokens_mistral': 700, 'n_tokens_neox': 620, 'n_words': 204}