<commit_before>use v6;

unit module Crust::Utils;

# internal use only. we'll change this file without notice.

sub parse-header-line(Str $header) is export {
    $header ~~ /^ (<-[: \s]>*) \s* \: \s* (.*) $/;
    return $/[0].Str.lc => $/[1].Str;
}

sub parse-header-item(Str $header) is export {
    my ($first, @items) = split(/\s*\;\s*/, $header);

    @items ==> map {
        $_ .= trim;
        my ($k, $v) = @(.split(/\=/));
        $v = $v.subst(/^\"(.*)\"$/, -> $/ { $/[0].Str });
        $k => $v
    } ==> my %opts;
    return $first.trim, %opts;
}

sub encode-html(Str $raw) is export {
    return $raw.trans(
        [ '&',     '<',    '>',    '"',      q{'}    ] =>
        [ '&amp;', '&lt;', '&gt;', '&quot;', '&#39;' ]
    );
}

sub status-with-no-entity-body(Int $status) returns Bool is export {
    return $status < 200 || $status == 204 || $status == 304;
}

sub content-length($body) is export {
    return Nil unless $body.defined;

    if $body.isa(List) {
        my $cl = 0;
        for @$body -> $chunk {
            my $length;
            given $chunk {
                when Str { $length = $chunk.encode.elems }
                when Blob { $length = $chunk.elems }
            }
            $cl += $length;
        }
        return $cl;
    } elsif $body.isa(IO::Handle) {
        return $body.s - $body.tell;
    }

    return Nil;
}

sub load-class($class, $prefix) is export {
    my $c = $class;

    if $prefix {
        unless $c ~~ s/^'+'// || $c ~~ /^$prefix/ {
            $c = $prefix ~ '::' ~ $c;
        }
    }

    require ::("$c");

    return $c;
}
<commit_msg>Use multi sub<commit_after>use v6;

unit module Crust::Utils;

# internal use only. we'll change this file without notice.

sub parse-header-line(Str $header) is export {
    $header ~~ /^ (<-[: \s]>*) \s* \: \s* (.*) $/;
    return $/[0].Str.lc => $/[1].Str;
}

sub parse-header-item(Str $header) is export {
    my ($first, @items) = split(/\s*\;\s*/, $header);

    @items ==> map {
        $_ .= trim;
        my ($k, $v) = @(.split(/\=/));
        $v = $v.subst(/^\"(.*)\"$/, -> $/ { $/[0].Str });
        $k => $v
    } ==> my %opts;
    return $first.trim, %opts;
}

sub encode-html(Str $raw) is export {
    return $raw.trans(
        [ '&',     '<',    '>',    '"',      q{'}    ] =>
        [ '&amp;', '&lt;', '&gt;', '&quot;', '&#39;' ]
    );
}

sub status-with-no-entity-body(Int $status) returns Bool is export {
    return $status < 200 || $status == 204 || $status == 304;
}

sub content-length($body) is export {
    return Nil unless $body.defined;

    if $body.isa(List) {
        my $cl = 0;
        for @$body -> $chunk {
            my $length;
            given $chunk {
                when Str { $length = $chunk.encode.elems }
                when Blob { $length = $chunk.elems }
            }
            $cl += $length;
        }
        return $cl;
    } elsif $body.isa(IO::Handle) {
        return $body.s - $body.tell;
    }

    return Nil;
}

multi sub load-class($class) is export {
    require ::($class);
    return $class;
}

multi sub load-class($class is copy, $prefix) is export {
    unless $class ~~ s/^'+'// || $class ~~ /^$prefix/ {
        $class = $prefix ~ '::' ~ $class;
    }
    return load-class($class);
}

{'fraction_non_alphanumeric': 0.22283440465258647, 'fraction_numerical': 0.009794918885827977, 'mean_word_length': 1.8148148148148149, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 21, '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': '2439717', 'n_tokens_mistral': 1242, 'n_tokens_neox': 1190, 'n_words': 289}