NAME
Sort::UCA - use UCA (Unicode Collation Algorithm)
SYNOPSIS
use Sort::UCA;
#construct
$uca = Sort::UCA->new(%tailoring);
#sort
@sorted = $uca->sort(@not_sorted);
#compare
$result = $uca->cmp($a, $b); # returns 1, 0, or -1.
DESCRIPTION
Constructor and Tailoring
$uca = Sort::UCA->new(
alternate => $alternate,
backwards => $levelNumber, # or \@levelNumbers
entry => $element,
ignoreName => qr/regex/,
ignoreChar => qr/regex/,
level => $collationLevel,
overrideCJK => \&overrideCJK,
overrideHangul => \&overrideHangul,
preprocess => \&preprocess,
rearrange => \@charList,
table => $filename,
upper_before_lower => $bool,
);
- alternate
-
-- see 3.2.2 Alternate Weighting, UTR #10.
alternate => 'shifted', 'blanked', 'non-ignorable', or 'shift-trimmed'.
By default (if specification is omitted), 'shifted' is adopted.
- backwards
-
-- see 3.1.2 French Accents, UTR #10.
backwards => $levelNumber or \@levelNumbers
Weights in reverse order; ex. level 2 (diacritic ordering) in French. If omitted, forwards at all the levels.
- entry
-
-- see 3.1 Linguistic Features; 3.2.1 File Format, UTR #10.
Override a default order or add a new element
entry => <<'ENTRIES', # use the UCA file format 00E6 ; [.0861.0020.0002.00E6] [.08B1.0020.0002.00E6] # ligature <ae> as <a e> 0063 0068 ; [.0893.0020.0002.0063] # "ch" in traditional Spanish 0043 0068 ; [.0893.0020.0008.0043] # "Ch" in traditional Spanish ENTRIES
- ignoreName or ignoreChar
-
-- see 6.3.4 Reducing the Repertoire, UTR #10.
ignoreName => qr/\bDINGBAT\b/, # Elements the name of which matches the regex are ignored. ignoreChar => qr/^(?:\p{InDingbat}|\p{Lm})$/, # Elements which matches the regex are ignored.
When 'a' and 'e' are ignored, 'element' is equal to 'lament' (or 'lmnt').
But, it'd be better to ignore characters unfamiliar to you (and maybe never used).
- level
-
-- see 4.3 Form a sort key for each string, UTR #10.
Set the maximum level. Any higher levels than the specified one are ignored.
Level 1: alphabetic ordering Level 2: diacritic ordering Level 3: case ordering Level 4: tie-breaking (e.g. in the case when alternate is 'shifted') ex.level => 2,
- overrideCJK or overrideHangul
-
-- see 7.1 Derived Collation Elements, UTR #10.
By default, mapping of CJK Unified Ideographs uses the Unicode codepoint order and Hangul Syllables are decomposed into Hangul Jamo.
The mapping of CJK Unified Ideographs or Hangul Syllables may be overrided.
ex. CJK Unified Ideographs in the JIS codepoint order.
overrideCJK => sub { my $u = shift; # get unicode codepoint my $b = pack('n', $u); # to UTF-16BE my $s = your_unicode_to_sjis_converter($b); # convert my $n = unpack('n', $s); # convert sjis to short [ $n, 1, 1 ]; # return collation element },
- preprocess
-
-- see 5.1 Preprocessing, UTR #10.
If specified, the coderef is used to preprocess before the formation of sort keys.
ex. dropping English articles, such as "a" or "the". Then, "the pen" is before "a pencil".
preprocess => sub { my $str = shift; $str =~ s/\b(?:an?|the)\s+//g; $str; },
- rearrange
-
-- see 3.1.3 Rearrangement, UTR #10.
Characters that are not coded in logical order and to be rearranged. By default,
rearrange => [ 0x0E40..0x0E44, 0x0EC0..0x0EC4],
- table
-
-- see 3.2 Default Unicode Collation Element Table, UTR #10.
You can use another element table if desired. The table file must be in your
lib/Sort/UCA
directory.By default, the file
lib/Sort/UCA/allkeys.txt
is used. - upper_before_lower
-
-- see 6.6 Case Comparisons; 7.3.1 Tertiary Weight Table, UTR #10.
By default, lowercase is before uppercase. If upper_before_lower is true, this is reversed.
EXPORT
None by default.
AUTHOR
SADAHIRO Tomoyuki, <SADAHIRO@cpan.org>
http://homepage1.nifty.com/nomenclator/perl/
Copyright(C) 2001, SADAHIRO Tomoyuki. Japan. All rights reserved.
This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
SEE ALSO
perl.
UCA - Unicode TR #10
http://www.unicode.org/unicode/reports/tr10/