<commit_before>//
//  Base32.swift
//  Bases
//
//  Created by <NAME> on 3/29/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

private let quantumSize = 5

public func base32<S: Sequence where S.Iterator.Element == UInt8>(bytes: S) -> String {
    return stringForData(bytes: ArraySlice(bytes))
}

private func stringForData(bytes: ArraySlice<Byte>) -> String {
    let s = stringForNextQuantum(bytes: bytes)
    if bytes.count <= quantumSize {
        return s
    } else {
        // There's more data to encode
        let remainingBytes = bytes[(bytes.startIndex + quantumSize)..<(bytes.endIndex)]
        return s + stringForData(bytes: remainingBytes)
    }
}

private func stringForNextQuantum(bytes: ArraySlice<Byte>) -> String {
    switch bytes.count {
    case 0:
        return ""
    case 1:
        return stringForBytes(bytes[bytes.startIndex],
                              nil, nil, nil, nil)
    case 2:
        return stringForBytes(bytes[bytes.startIndex],
                              bytes[bytes.startIndex + 1],
                              nil, nil, nil)
    case 3:
        return stringForBytes(bytes[bytes.startIndex],
                              bytes[bytes.startIndex + 1],
                              bytes[bytes.startIndex + 2],
                              nil, nil)
    case 4:
        return stringForBytes(bytes[bytes.startIndex],
                              bytes[bytes.startIndex + 1],
                              bytes[bytes.startIndex + 2],
                              bytes[bytes.startIndex + 3],
                              nil)
    default:
        return stringForBytes(bytes[bytes.startIndex],
                              bytes[bytes.startIndex + 1],
                              bytes[bytes.startIndex + 2],
                              bytes[bytes.startIndex + 3],
                              bytes[bytes.startIndex + 4])
    }
}

private func stringForBytes(_ b0: Byte, _ b1: Byte?, _ b2: Byte?, _ b3: Byte?, _ b4: Byte?) -> String
{
    let q = quintetsFromBytes(b0, b1, b2, b3, b4)
    let c0 = characterForValue(q.0)
    let c1 = characterForValue(q.1)
    let c2 = characterOrPaddingForValue(q.2)
    let c3 = characterOrPaddingForValue(q.3)
    let c4 = characterOrPaddingForValue(q.4)
    let c5 = characterOrPaddingForValue(q.5)
    let c6 = characterOrPaddingForValue(q.6)
    let c7 = characterOrPaddingForValue(q.7)
    return String([c0, c1, c2, c3, c4, c5, c6, c7])
}<commit_msg>Overload stringForBytes(...) for different byte counts<commit_after>//
//  Base32.swift
//  Bases
//
//  Created by <NAME> on 3/29/15.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

private let quantumSize = 5

public func base32<S: Sequence where S.Iterator.Element == UInt8>(bytes: S) -> String {
    return stringForData(bytes: ArraySlice(bytes))
}

private func stringForData(bytes: ArraySlice<Byte>) -> String {
    let s = stringForNextQuantum(bytes: bytes)
    if bytes.count <= quantumSize {
        return s
    } else {
        // There's more data to encode
        let remainingBytes = bytes[(bytes.startIndex + quantumSize)..<(bytes.endIndex)]
        return s + stringForData(bytes: remainingBytes)
    }
}

private func stringForNextQuantum(bytes: ArraySlice<Byte>) -> String {
    switch bytes.count {
    case 0:
        return ""
    case 1:
        return stringForBytes(bytes[bytes.startIndex])
    case 2:
        return stringForBytes(bytes[bytes.startIndex],
                              bytes[bytes.startIndex + 1])
    case 3:
        return stringForBytes(bytes[bytes.startIndex],
                              bytes[bytes.startIndex + 1],
                              bytes[bytes.startIndex + 2])
    case 4:
        return stringForBytes(bytes[bytes.startIndex],
                              bytes[bytes.startIndex + 1],
                              bytes[bytes.startIndex + 2],
                              bytes[bytes.startIndex + 3])
    default:
        return stringForBytes(bytes[bytes.startIndex],
                              bytes[bytes.startIndex + 1],
                              bytes[bytes.startIndex + 2],
                              bytes[bytes.startIndex + 3],
                              bytes[bytes.startIndex + 4])
    }
}

private func stringForBytes(_ b0: Byte, _ b1: Byte, _ b2: Byte, _ b3: Byte, _ b4: Byte) -> String {
    let q = quintetsFromBytes(b0, b1, b2, b3, b4)
    let c0 = characterForValue(q.0)
    let c1 = characterForValue(q.1)
    let c2 = characterOrPaddingForValue(q.2)
    let c3 = characterOrPaddingForValue(q.3)
    let c4 = characterOrPaddingForValue(q.4)
    let c5 = characterOrPaddingForValue(q.5)
    let c6 = characterOrPaddingForValue(q.6)
    let c7 = characterOrPaddingForValue(q.7)
    return String([c0, c1, c2, c3, c4, c5, c6, c7])
}

private func stringForBytes(_ b0: Byte, _ b1: Byte, _ b2: Byte, _ b3: Byte) -> String {
    let q = quintetsFromBytes(b0, b1, b2, b3, nil)
    let c0 = characterForValue(q.0)
    let c1 = characterForValue(q.1)
    let c2 = characterOrPaddingForValue(q.2)
    let c3 = characterOrPaddingForValue(q.3)
    let c4 = characterOrPaddingForValue(q.4)
    let c5 = characterOrPaddingForValue(q.5)
    let c6 = characterOrPaddingForValue(q.6)
    let c7 = characterOrPaddingForValue(q.7)
    return String([c0, c1, c2, c3, c4, c5, c6, c7])
}

private func stringForBytes(_ b0: Byte, _ b1: Byte, _ b2: Byte) -> String {
    let q = quintetsFromBytes(b0, b1, b2, nil, nil)
    let c0 = characterForValue(q.0)
    let c1 = characterForValue(q.1)
    let c2 = characterOrPaddingForValue(q.2)
    let c3 = characterOrPaddingForValue(q.3)
    let c4 = characterOrPaddingForValue(q.4)
    let c5 = characterOrPaddingForValue(q.5)
    let c6 = characterOrPaddingForValue(q.6)
    let c7 = characterOrPaddingForValue(q.7)
    return String([c0, c1, c2, c3, c4, c5, c6, c7])
}

private func stringForBytes(_ b0: Byte, _ b1: Byte) -> String {
    let q = quintetsFromBytes(b0, b1, nil, nil, nil)
    let c0 = characterForValue(q.0)
    let c1 = characterForValue(q.1)
    let c2 = characterOrPaddingForValue(q.2)
    let c3 = characterOrPaddingForValue(q.3)
    let c4 = characterOrPaddingForValue(q.4)
    let c5 = characterOrPaddingForValue(q.5)
    let c6 = characterOrPaddingForValue(q.6)
    let c7 = characterOrPaddingForValue(q.7)
    return String([c0, c1, c2, c3, c4, c5, c6, c7])
}

private func stringForBytes(_ b0: Byte) -> String {
    let q = quintetsFromBytes(b0, nil, nil, nil, nil)
    let c0 = characterForValue(q.0)
    let c1 = characterForValue(q.1)
    let c2 = characterOrPaddingForValue(q.2)
    let c3 = characterOrPaddingForValue(q.3)
    let c4 = characterOrPaddingForValue(q.4)
    let c5 = characterOrPaddingForValue(q.5)
    let c6 = characterOrPaddingForValue(q.6)
    let c7 = characterOrPaddingForValue(q.7)
    return String([c0, c1, c2, c3, c4, c5, c6, c7])
}
{'fraction_non_alphanumeric': 0.10994916485112563, 'fraction_numerical': 0.03543936092955701, 'mean_word_length': 2.280609814197237, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1177718', 'n_tokens_mistral': 2288, 'n_tokens_neox': 2218, 'n_words': 535}