/usr/share/perl5/Cz/Sort.pm is in cstocs 1:3.42-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 | =head1 NAME
Cz::Sort - Czech sort
=cut
#
# Here starts the Cz::Sort namespace
#
package Cz::Sort;
no locale;
use integer;
use strict;
use Exporter;
use vars qw( @ISA @EXPORT $VERSION $DEBUG );
@ISA = qw( Exporter );
#
# We implicitly export czcmp, czsort, cscmp and cssort functions.
# Since these are the only ones that can be used by ordinary users,
# it should not cause big harm.
#
@EXPORT = qw( czsort czcmp cssort cscmp );
$VERSION = '0.68';
$DEBUG = 0;
sub DEBUG { $DEBUG; }
#
# The table with sorting definitions.
#
my @def_table = (
'aA áÁ â ãà äÄ ±¡',
'bB',
'cC æÆ çÇ', 'èÈ',
'dD ïÏ ðÐ',
'eE éÉ ìÌ ëË êÊ',
'fF',
'gG',
'hH',
'<ch><Ch><CH>',
'iI íÍ îÎ',
'jJ',
'kK',
'lL åÅ µ¥ ³£',
'mM',
'nN ñÑ òÒ',
'oO óÓ ôÔ öÖ õÕ',
'pP',
'qQ',
'rR àÀ', 'øØ',
'sS ¶¦ ºª', '¹©',
'ß',
'tT »« þÞ',
'uU úÚ ùÙ üÜ ûÛ',
'vV',
'wW',
'xX',
'yY ýÝ',
'zZ ¿¯ ¼¬', '¾®',
'0', '1', '2', '3',
'4', '5', '6', '7',
'8', '9',
' .,;?!:"`\'',
' -|/\\()[]<>{}',
' @&§%$',
' _^=+×*÷#¢~',
' ÿ·°¨½¸²',
' ¤',
);
#
# Conversion table will hold four arrays, one for each pass. They will
# be created on the fly if they are needed. We also need to hold
# information (regexp) about groups of letters that need to be considered
# as one character (ch).
#
my @table = ( );
my @regexp = ( '.', '.', '.', '.' );
my @multiple = ( {}, {}, {}, {} );
#
# Make_table will build sorting table for given level.
#
sub make_table
{
my $level = shift;
@{$table[$level]} = ( undef ) x 256;
@{$table[$level]}[ord ' ', ord "\t"] = (0, 0);
my $i = 1;
my $irow = 0;
while (defined $def_table[$irow])
{
my $def_row = $def_table[$irow];
next if $level <= 2 and $def_row =~ /^ /;
while ($def_row =~ /<([cC].*?)>|(.)/sg)
{
my $match = $+;
if ($match eq ' ')
{
if ($level == 1)
{ $i++; }
}
else
{
if (length $match == 1)
{ $table[$level][ord $match] = $i; }
else
{
$multiple[$level]{$match} = $i;
$regexp[$level] = $match . "|" . $regexp[$level];
}
if ($level >= 2)
{ $i++; }
}
}
$i++ if $level < 2;
}
continue
{ $irow++; }
}
#
# Create the tables now.
#
for (0 .. 3)
{ make_table($_); }
#
# Compare two scalar, according to the tables.
#
sub czcmp
{
my ($a, $b) = (shift, shift);
print STDERR "czcmp: $a/$b\n" if DEBUG;
my ($a1, $b1) = ($a, $b);
my $level = 0;
while (1)
{
my ($ac, $bc, $a_no, $b_no, $ax, $bx) = ('', '', 0, 0,
undef, undef);
if ($level == 0)
{
while (not defined $ax and not $a_no)
{
$a =~ /$regexp[$level]/sg or $a_no = 1;
$ac = $&;
$ax = ( length $ac == 1 ?
$table[$level][ord $ac]
: ${$multiple[$level]}{$ac} )
if defined $ac;
}
while (not defined $bx and not $b_no)
{
$b =~ /$regexp[$level]/sg or $b_no = 1;
$bc = $&;
$bx = ( length $bc == 1 ?
$table[$level][ord $bc]
: ${$multiple[$level]}{$bc} )
if defined $bc;
}
}
else
{
while (not defined $ax and not $a_no)
{
$a1 =~ /$regexp[$level]/sg or $a_no = 1;
$ac = $&;
$ax = ( length $ac == 1 ?
$table[$level][ord $ac]
: ${$multiple[$level]}{$ac} )
if defined $ac;
}
while (not defined $bx and not $b_no)
{
$b1 =~ /$regexp[$level]/sg or $b_no = 1;
$bc = $&;
$bx = ( length $bc == 1 ?
$table[$level][ord $bc]
: ${$multiple[$level]}{$bc} )
if defined $bc;
}
}
print STDERR "level $level: ac: $ac -> $ax; bc: $bc -> $bx ($a_no, $b_no)\n" if DEBUG;
return -1 if $a_no and not $b_no;
return 1 if not $a_no and $b_no;
if ($a_no and $b_no)
{
if ($level == 0)
{ $level = 1; next; }
last;
}
return -1 if ($ax < $bx);
return 1 if ($ax > $bx);
if ($ax == 0 and $bx == 0)
{
if ($level == 0)
{ $level = 1; next; }
$level = 0; next;
}
}
for $level (2 .. 3)
{
while (1)
{
my ($ac, $bc, $a_no, $b_no, $ax, $bx)
= ('', '', 0, 0, undef, undef);
while (not defined $ax and not $a_no)
{
$a =~ /$regexp[$level]/sg or $a_no = 1;
$ac = $&;
$ax = ( length $ac == 1 ?
$table[$level][ord $ac]
: ${$multiple[$level]}{$ac} )
if defined $ac;
}
while (not defined $bx and not $b_no)
{
$b =~ /$regexp[$level]/sg or $b_no = 1;
$bc = $&;
$bx = ( length $bc == 1 ?
$table[$level][ord $bc]
: ${$multiple[$level]}{$bc} )
if defined $bc;
}
print STDERR "level $level: ac: $ac -> $ax; bc: $bc -> $bx ($a_no, $b_no)\n" if DEBUG;
return -1 if $a_no and not $b_no;
return 1 if not $a_no and $b_no;
if ($a_no and $b_no)
{ last; }
return -1 if ($ax < $bx);
return 1 if ($ax > $bx);
}
}
return 0;
}
1;
#
# Cssort does the real thing.
#
sub czsort
{ sort { my $result = czcmp($a, $b); } @_; }
*cscmp = *czcmp;
*cssort = *czsort;
1;
__END__
=head1 SYNOPSIS
use Cz::Sort;
my $result = czcmp("_x j&á", "_&p");
my @sorted = czsort qw(plachta plaòka Plánièka plánièka plánì);
print "@sorted\n";
=head1 DESCRIPTION
Implements czech sorting conventions, indepentent on current locales
in effect, which are often bad. Does the four-pass sort. The idea and
the base of the conversion table comes from Petr Olsak's program B<csr>
and the code is as compliant with CSN 97 6030 as possible.
The basic function provided by this module, is I<czcmp>. If compares
two scalars and returns the (-1, 0, 1) result. The function can be
called directly, like
my $result = czcmp("_x j&á", "_&p");
But for convenience and also because of compatibility with older
versions, there is a function I<czsort>. It works on list of strings
and returns that list, hmm, sorted. The function is defined simply
like
sub czsort
{ sort { czcmp($a, $b); } @_; }
standard use of user's function in I<sort>. Hashes would be simply
sorted
@sorted = sort { czcmp($hash{$a}, $hash{$b}) }
keys %hash;
Both I<czcmp> and I<czsort> are exported into caller's namespace
by default, as well as I<cscmp> and I<cssort> that are just aliases.
This module comes with encoding table prepared for ISO-8859-2
(Latin-2) encoding. If your data come in different one, you might
want to check the module B<Cstocs> which can be used for reencoding
of the list's data prior to calling I<czsort>, or reencode this
module to fit your needs.
=head1 VERSION
0.68
=head1 SEE ALSO
perl(1), Cz::Cstocs(3).
=head1 AUTHOR
(c) 1997--2000 Jan Pazdziora <adelton@fi.muni.cz>,
http://www.fi.muni.cz/~adelton/
at Faculty of Informatics, Masaryk University, Brno
=cut
|