<commit_before>import Foundation

public protocol PStringParsible {
    init?(parsing: String)
    init(parseOrThrow value: String) throws
}

extension PStringParsible {
    public init?(parsing: String) {
        do {
            self = try Self.init(parseOrThrow: parsing)
        } catch {
            return nil
        }
    }
}

extension Int: PStringParsible {
    public init(parseOrThrow value: String) throws {
        let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
        guard let tmp = Int(trimmed) else {
            throw PError.unparseable(value: value, type: "Int")
        }
        self = tmp
    }
}

extension Float: PStringParsible {
    public init(parseOrThrow value: String) throws {
        let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
        guard let tmp = Float(trimmed) else {
            throw PError.unparseable(value: value, type: "Float")
        }
        self = tmp
    }
}

extension Double: PStringParsible {
    public init(parseOrThrow value: String) throws {
        let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
        guard let tmp = Double(trimmed) else {
            throw PError.unparseable(value: value, type: "Double")
        }
        self = tmp
    }
}

extension Bool: PStringParsible {
    public init(parseOrThrow value: String) throws {
        let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
        if let tmp = Bool(trimmed) {
            self = tmp
            return
        }
        if trimmed == "t" || trimmed == "true" {
            self = true
            return
        }
        if trimmed == "f" || trimmed == "false" {
            self = false
            return
        }
        if let asInt = Int(trimmed) {
            if asInt == 0 {
                self = false
                return
            }
            if asInt == 1 {
                self = true
                return
            }
            throw PError.unparseable(value: value, type: "Bool")
        }
        throw PError.unparseable(value: value, type: "Bool")
    }
}
<commit_msg>Add String to PStringParsible.<commit_after>import Foundation

public protocol PStringParsible {
    init?(parsing: String)
    init(parseOrThrow value: String) throws
}

extension PStringParsible {
    public init?(parsing: String) {
        do {
            self = try Self.init(parseOrThrow: parsing)
        } catch {
            return nil
        }
    }
}

extension String: PStringParsible {
    public init(parseOrThrow value: String) {
        self = value
    }
}

extension Int: PStringParsible {
    public init(parseOrThrow value: String) throws {
        let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
        guard let tmp = Int(trimmed) else {
            throw PError.unparseable(value: value, type: "Int")
        }
        self = tmp
    }
}

extension Float: PStringParsible {
    public init(parseOrThrow value: String) throws {
        let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
        guard let tmp = Float(trimmed) else {
            throw PError.unparseable(value: value, type: "Float")
        }
        self = tmp
    }
}

extension Double: PStringParsible {
    public init(parseOrThrow value: String) throws {
        let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines)
        guard let tmp = Double(trimmed) else {
            throw PError.unparseable(value: value, type: "Double")
        }
        self = tmp
    }
}

extension Bool: PStringParsible {
    public init(parseOrThrow value: String) throws {
        let trimmed = value.trimmingCharacters(in: .whitespacesAndNewlines).lowercased()
        if let tmp = Bool(trimmed) {
            self = tmp
            return
        }
        if trimmed == "t" || trimmed == "true" {
            self = true
            return
        }
        if trimmed == "f" || trimmed == "false" {
            self = false
            return
        }
        if let asInt = Int(trimmed) {
            if asInt == 0 {
                self = false
                return
            }
            if asInt == 1 {
                self = true
                return
            }
            throw PError.unparseable(value: value, type: "Bool")
        }
        throw PError.unparseable(value: value, type: "Bool")
    }
}

{'fraction_non_alphanumeric': 0.09039032184432778, 'fraction_numerical': 0.0009130335539831089, 'mean_word_length': 1.8454545454545455, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1063761', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1229, 'n_words': 326}