xref: /openbsd-src/gnu/usr.bin/perl/t/lib/Cname.pm (revision eac174f2741a08d8deb8aae59a7f778ef9b5d770)
1850e2753Smillertpackage Cname;
2850e2753Smillertour $Evil='A';
3850e2753Smillert
4850e2753Smillertsub translator {
5*eac174f2Safresh1
6*eac174f2Safresh1    # Returns the input as a name, except for these special ones
7*eac174f2Safresh1
8850e2753Smillert    my $str = shift;
9850e2753Smillert    if ( $str eq 'EVIL' ) {
10b39c5158Smillert        # Returns A first time, AB second, ABC third ... A-ZA the 27th time.
11850e2753Smillert        (my $c=substr("A".$Evil,-1))++;
12850e2753Smillert        my $r=$Evil;
13850e2753Smillert        $Evil.=$c;
14850e2753Smillert        return $r;
15850e2753Smillert    }
16850e2753Smillert    if ( $str eq 'EMPTY-STR') {
17850e2753Smillert       return "";
18850e2753Smillert    }
19b39c5158Smillert    if ( $str eq 'NULL') {
20b39c5158Smillert        return "\0";
21b39c5158Smillert    }
22b39c5158Smillert    if ( $str eq 'LONG-STR') {
23b39c5158Smillert        return 'A' x 255;
24b39c5158Smillert    }
25b39c5158Smillert    # Should exceed limit for regex \N bytes in a sequence.  Anyway it will if
26b39c5158Smillert    # UCHAR_MAX is 255.
27b39c5158Smillert    if ( $str eq 'TOO-LONG-STR') {
28b39c5158Smillert       return 'A' x 256;
29b39c5158Smillert    }
30*eac174f2Safresh1
31850e2753Smillert    return $str;
32850e2753Smillert}
33850e2753Smillert
34850e2753Smillertsub import {
35850e2753Smillert    shift;
36850e2753Smillert    $^H{charnames} = \&translator;
37850e2753Smillert}
38850e2753Smillert1;
39