A(z) 11. kódú hibát javító kódrészlet

szerkesztés
sub fix_11 {	# HTML named entities
                # valamint 20: Symbol for dead
                # valamint 50: en dash or em dash
    my ($error_code, $title_str, $text_str) = @_;

    my %HTML_entitiy = (
        quot    => "\x{0022}",
        sect    => "\x{00a7}",
        copy    => "\x{00a9}",
        middot  => "\x{00b7}",
        Agrave  => "\x{00c0}",
        Aring   => "\x{00c5}",
        Auml    => "\x{00c4}",
        AElig   => "\x{00c6}",
        Ccedil  => "\x{00c7}",
        Ntilde  => "\x{00d1}",
        Uuml    => "\x{00dc}",
        agrave  => "\x{00e0}",
        auml    => "\x{00e4}",
        aring   => "\x{00e5}",
        aelig   => "\x{00e6}",
        ccedil  => "\x{00e7}",
        ntilde  => "\x{00f1}",
        uuml    => "\x{00fc}",
        minus   => "\x{2012}",
        ndash   => "\x{2013}",
        mdash   => "\x{2014}",
        dagger  => "\x{2020}",
        Dagger  => "\x{2021}",
        bull    => "\x{2022}",
        hellip  => "\x{2026}",
        trade   => "\x{2122}",
        larr    => "\x{2190}",
        uarr    => "\x{2191}",
        rarr    => "\x{2192}",
        darr    => "\x{2193}",
        harr    => "\x{2194}",
        lArr    => "\x{21d0}",
        uArr    => "\x{21d1}",
        rArr    => "\x{21d2}",
        dArr    => "\x{21d3}",
        hArr    => "\x{21d4}",
    );

    my $excluded = search_tags($text_str);

    my @entities;
    my $count = 0;
    while ($text_str =~ m|\&(\w+);|gs) {
        my ($pos, $entity, $len) =
            (pos($text_str), $1, length($&));
        $pos -= $len;
        next unless exists $HTML_entitiy{$entity};
        next if $excluded->contains($pos);
        unshift(@entities, {
            'pos'       => $pos,
            len         => $len,
            entity      => $entity,
            replacement => $HTML_entitiy{$entity},
        });
        $count++;
    }
    $count or return ('Nincs HTML entitas');
    foreach (@entities) {
        substr($text_str, $_->{pos}, $_->{len}) = $_->{replacement};
    }

    my $summary_str = $latin2->decode(
        "Bot: $count HTML entitás lecserélve. (Hibakód: $error_code)"
    );
    return ($summary_str, $count, $text_str);
}