Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / man / man3 / Unicode::Collate.3
.\" Automatically generated by Pod::Man v1.37, Pod::Parser v1.32
.\"
.\" Standard preamble:
.\" ========================================================================
.de Sh \" Subsection heading
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp \" Vertical space (when we can't use .PP)
.if t .sp .5v
.if n .sp
..
.de Vb \" Begin verbatim text
.ft CW
.nf
.ne \\$1
..
.de Ve \" End verbatim text
.ft R
.fi
..
.\" Set up some character translations and predefined strings. \*(-- will
.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left
.\" double quote, and \*(R" will give a right double quote. | will give a
.\" real vertical bar. \*(C+ will give a nicer C++. Capital omega is used to
.\" do unbreakable dashes and therefore won't be available. \*(C` and \*(C'
.\" expand to `' in nroff, nothing in troff, for use with C<>.
.tr \(*W-|\(bv\*(Tr
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.ie n \{\
. ds -- \(*W-
. ds PI pi
. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
. ds L" ""
. ds R" ""
. ds C` ""
. ds C' ""
'br\}
.el\{\
. ds -- \|\(em\|
. ds PI \(*p
. ds L" ``
. ds R" ''
'br\}
.\"
.\" If the F register is turned on, we'll generate index entries on stderr for
.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index
.\" entries marked with X<> in POD. Of course, you'll have to process the
.\" output yourself in some meaningful fashion.
.if \nF \{\
. de IX
. tm Index:\\$1\t\\n%\t"\\$2"
..
. nr % 0
. rr F
.\}
.\"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.hy 0
.if n .na
.\"
.\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2).
.\" Fear. Run. Save yourself. No user-serviceable parts.
. \" fudge factors for nroff and troff
.if n \{\
. ds #H 0
. ds #V .8m
. ds #F .3m
. ds #[ \f1
. ds #] \fP
.\}
.if t \{\
. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
. ds #V .6m
. ds #F 0
. ds #[ \&
. ds #] \&
.\}
. \" simple accents for nroff and troff
.if n \{\
. ds ' \&
. ds ` \&
. ds ^ \&
. ds , \&
. ds ~ ~
. ds /
.\}
.if t \{\
. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.\}
. \" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
. \" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
. \" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
. ds : e
. ds 8 ss
. ds o a
. ds d- d\h'-1'\(ga
. ds D- D\h'-1'\(hy
. ds th \o'bp'
. ds Th \o'LP'
. ds ae ae
. ds Ae AE
.\}
.rm #[ #] #H #V #F C
.\" ========================================================================
.\"
.IX Title "Unicode::Collate 3"
.TH Unicode::Collate 3 "2001-09-21" "perl v5.8.8" "Perl Programmers Reference Guide"
.SH "NAME"
Unicode::Collate \- Unicode Collation Algorithm
.SH "SYNOPSIS"
.IX Header "SYNOPSIS"
.Vb 1
\& use Unicode::Collate;
.Ve
.PP
.Vb 2
\& #construct
\& $Collator = Unicode::Collate->new(%tailoring);
.Ve
.PP
.Vb 2
\& #sort
\& @sorted = $Collator->sort(@not_sorted);
.Ve
.PP
.Vb 2
\& #compare
\& $result = $Collator->cmp($a, $b); # returns 1, 0, or -1.
.Ve
.PP
.Vb 2
\& # If %tailoring is false (i.e. empty),
\& # $Collator should do the default collation.
.Ve
.SH "DESCRIPTION"
.IX Header "DESCRIPTION"
This module is an implementation of Unicode Technical Standard #10
(a.k.a. \s-1UTS\s0 #10) \- Unicode Collation Algorithm (a.k.a. \s-1UCA\s0).
.Sh "Constructor and Tailoring"
.IX Subsection "Constructor and Tailoring"
The \f(CW\*(C`new\*(C'\fR method returns a collator object.
.PP
.Vb 21
\& $Collator = Unicode::Collate->new(
\& UCA_Version => $UCA_Version,
\& alternate => $alternate, # deprecated: use of 'variable' is recommended.
\& backwards => $levelNumber, # or \e@levelNumbers
\& entry => $element,
\& hangul_terminator => $term_primary_weight,
\& ignoreName => qr/$ignoreName/,
\& ignoreChar => qr/$ignoreChar/,
\& katakana_before_hiragana => $bool,
\& level => $collationLevel,
\& normalization => $normalization_form,
\& overrideCJK => \e&overrideCJK,
\& overrideHangul => \e&overrideHangul,
\& preprocess => \e&preprocess,
\& rearrange => \e@charList,
\& table => $filename,
\& undefName => qr/$undefName/,
\& undefChar => qr/$undefChar/,
\& upper_before_lower => $bool,
\& variable => $variable,
\& );
.Ve
.IP "UCA_Version" 4
.IX Item "UCA_Version"
If the tracking version number of \s-1UCA\s0 is given,
behavior of that tracking version is emulated on collating.
If omitted, the return value of \f(CW\*(C`UCA_Version()\*(C'\fR is used.
\&\f(CW\*(C`UCA_Version()\*(C'\fR should return the latest tracking version supported.
.Sp
The supported tracking version: 8, 9, 11, or 14.
.Sp
.Vb 6
\& UCA Unicode Standard DUCET (@version)
\& ---------------------------------------------------
\& 8 3.1 3.0.1 (3.0.1d9)
\& 9 3.1 with Corrigendum 3 3.1.1 (3.1.1)
\& 11 4.0 4.0.0 (4.0.0)
\& 14 4.1.0 4.1.0 (4.1.0)
.Ve
.Sp
Note: Recent \s-1UTS\s0 #10 renames \*(L"Tracking Version\*(R" to \*(L"Revision.\*(R"
.IP "alternate" 4
.IX Item "alternate"
\&\-\- see 3.2.2 Alternate Weighting, version 8 of \s-1UTS\s0 #10
.Sp
For backward compatibility, \f(CW\*(C`alternate\*(C'\fR (old name) can be used
as an alias for \f(CW\*(C`variable\*(C'\fR.
.IP "backwards" 4
.IX Item "backwards"
\&\-\- see 3.1.2 French Accents, \s-1UTS\s0 #10.
.Sp
.Vb 1
\& backwards => $levelNumber or \e@levelNumbers
.Ve
.Sp
Weights in reverse order; ex. level 2 (diacritic ordering) in French.
If omitted, forwards at all the levels.
.IP "entry" 4
.IX Item "entry"
\&\-\- see 3.1 Linguistic Features; 3.2.1 File Format, \s-1UTS\s0 #10.
.Sp
If the same character (or a sequence of characters) exists
in the collation element table through \f(CW\*(C`table\*(C'\fR,
mapping to collation elements is overrided.
If it does not exist, the mapping is defined additionally.
.Sp
.Vb 12
\& entry => <<'ENTRY', # for DUCET v4.0.0 (allkeys-4.0.0.txt)
\&0063 0068 ; [.0E6A.0020.0002.0063] # ch
\&0043 0068 ; [.0E6A.0020.0007.0043] # Ch
\&0043 0048 ; [.0E6A.0020.0008.0043] # CH
\&006C 006C ; [.0F4C.0020.0002.006C] # ll
\&004C 006C ; [.0F4C.0020.0007.004C] # Ll
\&004C 004C ; [.0F4C.0020.0008.004C] # LL
\&00F1 ; [.0F7B.0020.0002.00F1] # n-tilde
\&006E 0303 ; [.0F7B.0020.0002.00F1] # n-tilde
\&00D1 ; [.0F7B.0020.0008.00D1] # N-tilde
\&004E 0303 ; [.0F7B.0020.0008.00D1] # N-tilde
\&ENTRY
.Ve
.Sp
.Vb 4
\& entry => <<'ENTRY', # for DUCET v4.0.0 (allkeys-4.0.0.txt)
\&00E6 ; [.0E33.0020.0002.00E6][.0E8B.0020.0002.00E6] # ae ligature as <a><e>
\&00C6 ; [.0E33.0020.0008.00C6][.0E8B.0020.0008.00C6] # AE ligature as <A><E>
\&ENTRY
.Ve
.Sp
\&\fB\s-1NOTE:\s0\fR The code point in the \s-1UCA\s0 file format (before \f(CW';'\fR)
\&\fBmust\fR be a Unicode code point (defined as hexadecimal),
but not a native code point.
So \f(CW0063\fR must always denote \f(CW\*(C`U+0063\*(C'\fR,
but not a character of \f(CW"\ex63"\fR.
.Sp
Weighting may vary depending on collation element table.
So ensure the weights defined in \f(CW\*(C`entry\*(C'\fR will be consistent with
those in the collation element table loaded via \f(CW\*(C`table\*(C'\fR.
.Sp
In \s-1DUCET\s0 v4.0.0, primary weight of \f(CW\*(C`C\*(C'\fR is \f(CW0E60\fR
and that of \f(CW\*(C`D\*(C'\fR is \f(CW\*(C`0E6D\*(C'\fR. So setting primary weight of \f(CW\*(C`CH\*(C'\fR to \f(CW\*(C`0E6A\*(C'\fR
(as a value between \f(CW0E60\fR and \f(CW\*(C`0E6D\*(C'\fR)
makes ordering as \f(CW\*(C`C < CH < D\*(C'\fR.
Exactly speaking \s-1DUCET\s0 already has some characters between \f(CW\*(C`C\*(C'\fR and \f(CW\*(C`D\*(C'\fR:
\&\f(CW\*(C`small capital C\*(C'\fR (\f(CW\*(C`U+1D04\*(C'\fR) with primary weight \f(CW0E64\fR,
\&\f(CW\*(C`c\-hook/C\-hook\*(C'\fR (\f(CW\*(C`U+0188/U+0187\*(C'\fR) with \f(CW0E65\fR,
and \f(CW\*(C`c\-curl\*(C'\fR (\f(CW\*(C`U+0255\*(C'\fR) with \f(CW0E69\fR.
Then primary weight \f(CW\*(C`0E6A\*(C'\fR for \f(CW\*(C`CH\*(C'\fR makes \f(CW\*(C`CH\*(C'\fR
ordered between \f(CW\*(C`c\-curl\*(C'\fR and \f(CW\*(C`D\*(C'\fR.
.IP "hangul_terminator" 4
.IX Item "hangul_terminator"
\&\-\- see 7.1.4 Trailing Weights, \s-1UTS\s0 #10.
.Sp
If a true value is given (non\-zero but should be positive),
it will be added as a terminator primary weight to the end of
every standard Hangul syllable. Secondary and any higher weights
for terminator are set to zero.
If the value is false or \f(CW\*(C`hangul_terminator\*(C'\fR key does not exist,
insertion of terminator weights will not be performed.
.Sp
Boundaries of Hangul syllables are determined
according to conjoining Jamo behavior in \fIthe Unicode Standard\fR
and \fIHangulSyllableType.txt\fR.
.Sp
\&\fBImplementation Note:\fR
(1) For expansion mapping (Unicode character mapped
to a sequence of collation elements), a terminator will not be added
between collation elements, even if Hangul syllable boundary exists there.
Addition of terminator is restricted to the next position
to the last collation element.
.Sp
(2) Non-conjoining Hangul letters
(Compatibility Jamo, halfwidth Jamo, and enclosed letters) are not
automatically terminated with a terminator primary weight.
These characters may need terminator included in a collation element
table beforehand.
.IP "ignoreChar" 4
.IX Item "ignoreChar"
.PD 0
.IP "ignoreName" 4
.IX Item "ignoreName"
.PD
\&\-\- see 3.2.2 Variable Weighting, \s-1UTS\s0 #10.
.Sp
Makes the entry in the table completely ignorable;
i.e. as if the weights were zero at all level.
.Sp
Through \f(CW\*(C`ignoreChar\*(C'\fR, any character matching \f(CW\*(C`qr/$ignoreChar/\*(C'\fR
will be ignored. Through \f(CW\*(C`ignoreName\*(C'\fR, any character whose name
(given in the \f(CW\*(C`table\*(C'\fR file as a comment) matches \f(CW\*(C`qr/$ignoreName/\*(C'\fR
will be ignored.
.Sp
E.g. when 'a' and 'e' are ignorable,
\&'element' is equal to 'lament' (or 'lmnt').
.IP "katakana_before_hiragana" 4
.IX Item "katakana_before_hiragana"
\&\-\- see 7.3.1 Tertiary Weight Table, \s-1UTS\s0 #10.
.Sp
By default, hiragana is before katakana.
If the parameter is made true, this is reversed.
.Sp
\&\fB\s-1NOTE\s0\fR: This parameter simplemindedly assumes that any hiragana/katakana
distinctions must occur in level 3, and their weights at level 3 must be
same as those mentioned in 7.3.1, \s-1UTS\s0 #10.
If you define your collation elements which violate this requirement,
this parameter does not work validly.
.IP "level" 4
.IX Item "level"
\&\-\- see 4.3 Form Sort Key, \s-1UTS\s0 #10.
.Sp
Set the maximum level.
Any higher levels than the specified one are ignored.
.Sp
.Vb 4
\& Level 1: alphabetic ordering
\& Level 2: diacritic ordering
\& Level 3: case ordering
\& Level 4: tie-breaking (e.g. in the case when variable is 'shifted')
.Ve
.Sp
.Vb 1
\& ex.level => 2,
.Ve
.Sp
If omitted, the maximum is the 4th.
.IP "normalization" 4
.IX Item "normalization"
\&\-\- see 4.1 Normalize, \s-1UTS\s0 #10.
.Sp
If specified, strings are normalized before preparation of sort keys
(the normalization is executed after preprocess).
.Sp
A form name \f(CW\*(C`Unicode::Normalize::normalize()\*(C'\fR accepts will be applied
as \f(CW$normalization_form\fR.
Acceptable names include \f(CW'NFD'\fR, \f(CW'NFC'\fR, \f(CW'NFKD'\fR, and \f(CW'NFKC'\fR.
See \f(CW\*(C`Unicode::Normalize::normalize()\*(C'\fR for detail.
If omitted, \f(CW'NFD'\fR is used.
.Sp
\&\f(CW\*(C`normalization\*(C'\fR is performed after \f(CW\*(C`preprocess\*(C'\fR (if defined).
.Sp
Furthermore, special values, \f(CW\*(C`undef\*(C'\fR and \f(CW"prenormalized"\fR, can be used,
though they are not concerned with \f(CW\*(C`Unicode::Normalize::normalize()\*(C'\fR.
.Sp
If \f(CW\*(C`undef\*(C'\fR (not a string \f(CW"undef"\fR) is passed explicitly
as the value for this key,
any normalization is not carried out (this may make tailoring easier
if any normalization is not desired). Under \f(CW\*(C`(normalization => undef)\*(C'\fR,
only contiguous contractions are resolved;
e.g. even if \f(CW\*(C`A\-ring\*(C'\fR (and \f(CW\*(C`A\-ring\-cedilla\*(C'\fR) is ordered after \f(CW\*(C`Z\*(C'\fR,
\&\f(CW\*(C`A\-cedilla\-ring\*(C'\fR would be primary equal to \f(CW\*(C`A\*(C'\fR.
In this point,
\&\f(CW\*(C`(normalization => undef, preprocess => sub { NFD(shift) })\*(C'\fR
\&\fBis not\fR equivalent to \f(CW\*(C`(normalization => 'NFD')\*(C'\fR.
.Sp
In the case of \f(CW\*(C`(normalization => "prenormalized")\*(C'\fR,
any normalization is not performed, but
non-contiguous contractions with combining characters are performed.
Therefore
\&\f(CW\*(C`(normalization => 'prenormalized', preprocess => sub { NFD(shift) })\*(C'\fR
\&\fBis\fR equivalent to \f(CW\*(C`(normalization => 'NFD')\*(C'\fR.
If source strings are finely prenormalized,
\&\f(CW\*(C`(normalization => 'prenormalized')\*(C'\fR may save time for normalization.
.Sp
Except \f(CW\*(C`(normalization => undef)\*(C'\fR,
\&\fBUnicode::Normalize\fR is required (see also \fB\s-1CAVEAT\s0\fR).
.IP "overrideCJK" 4
.IX Item "overrideCJK"
\&\-\- see 7.1 Derived Collation Elements, \s-1UTS\s0 #10.
.Sp
By default, \s-1CJK\s0 Unified Ideographs are ordered in Unicode codepoint order
but \f(CW\*(C`CJK Unified Ideographs\*(C'\fR (if \f(CW\*(C`UCA_Version\*(C'\fR is 8 to 11, its range is
\&\f(CW\*(C`U+4E00..U+9FA5\*(C'\fR; if \f(CW\*(C`UCA_Version\*(C'\fR is 14, its range is \f(CW\*(C`U+4E00..U+9FBB\*(C'\fR)
are lesser than \f(CW\*(C`CJK Unified Ideographs Extension\*(C'\fR (its range is
\&\f(CW\*(C`U+3400..U+4DB5\*(C'\fR and \f(CW\*(C`U+20000..U+2A6D6\*(C'\fR).
.Sp
Through \f(CW\*(C`overrideCJK\*(C'\fR, ordering of \s-1CJK\s0 Unified Ideographs can be overrided.
.Sp
ex. \s-1CJK\s0 Unified Ideographs in the \s-1JIS\s0 code point order.
.Sp
.Vb 7
\& overrideCJK => sub {
\& my $u = shift; # get a 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, 0x20, 0x2, $u ]; # return the collation element
\& },
.Ve
.Sp
ex. ignores all \s-1CJK\s0 Unified Ideographs.
.Sp
.Vb 1
\& overrideCJK => sub {()}, # CODEREF returning empty list
.Ve
.Sp
.Vb 2
\& # where ->eq("Pe\ex{4E00}rl", "Perl") is true
\& # as U+4E00 is a CJK Unified Ideograph and to be ignorable.
.Ve
.Sp
If \f(CW\*(C`undef\*(C'\fR is passed explicitly as the value for this key,
weights for \s-1CJK\s0 Unified Ideographs are treated as undefined.
But assignment of weight for \s-1CJK\s0 Unified Ideographs
in table or \f(CW\*(C`entry\*(C'\fR is still valid.
.IP "overrideHangul" 4
.IX Item "overrideHangul"
\&\-\- see 7.1 Derived Collation Elements, \s-1UTS\s0 #10.
.Sp
By default, Hangul Syllables are decomposed into Hangul Jamo,
even if \f(CW\*(C`(normalization => undef)\*(C'\fR.
But the mapping of Hangul Syllables may be overrided.
.Sp
This parameter works like \f(CW\*(C`overrideCJK\*(C'\fR, so see there for examples.
.Sp
If you want to override the mapping of Hangul Syllables,
\&\s-1NFD\s0, \s-1NFKD\s0, and \s-1FCD\s0 are not appropriate,
since they will decompose Hangul Syllables before overriding.
.Sp
If \f(CW\*(C`undef\*(C'\fR is passed explicitly as the value for this key,
weight for Hangul Syllables is treated as undefined
without decomposition into Hangul Jamo.
But definition of weight for Hangul Syllables
in table or \f(CW\*(C`entry\*(C'\fR is still valid.
.IP "preprocess" 4
.IX Item "preprocess"
\&\-\- see 5.1 Preprocessing, \s-1UTS\s0 #10.
.Sp
If specified, the coderef is used to preprocess
before the formation of sort keys.
.Sp
ex. dropping English articles, such as \*(L"a\*(R" or \*(L"the\*(R".
Then, \*(L"the pen\*(R" is before \*(L"a pencil\*(R".
.Sp
.Vb 5
\& preprocess => sub {
\& my $str = shift;
\& $str =~ s/\eb(?:an?|the)\es+//gi;
\& return $str;
\& },
.Ve
.Sp
\&\f(CW\*(C`preprocess\*(C'\fR is performed before \f(CW\*(C`normalization\*(C'\fR (if defined).
.IP "rearrange" 4
.IX Item "rearrange"
\&\-\- see 3.1.3 Rearrangement, \s-1UTS\s0 #10.
.Sp
Characters that are not coded in logical order and to be rearranged.
If \f(CW\*(C`UCA_Version\*(C'\fR is equal to or lesser than 11, default is:
.Sp
.Vb 1
\& rearrange => [ 0x0E40..0x0E44, 0x0EC0..0x0EC4 ],
.Ve
.Sp
If you want to disallow any rearrangement, pass \f(CW\*(C`undef\*(C'\fR or \f(CW\*(C`[]\*(C'\fR
(a reference to empty list) as the value for this key.
.Sp
If \f(CW\*(C`UCA_Version\*(C'\fR is equal to 14, default is \f(CW\*(C`[]\*(C'\fR (i.e. no rearrangement).
.Sp
\&\fBAccording to the version 9 of \s-1UCA\s0, this parameter shall not be used;
but it is not warned at present.\fR
.IP "table" 4
.IX Item "table"
\&\-\- see 3.2 Default Unicode Collation Element Table, \s-1UTS\s0 #10.
.Sp
You can use another collation element table if desired.
.Sp
The table file should locate in the \fIUnicode/Collate\fR directory
on \f(CW@INC\fR. Say, if the filename is \fIFoo.txt\fR,
the table file is searched as \fIUnicode/Collate/Foo.txt\fR in \f(CW@INC\fR.
.Sp
By default, \fIallkeys.txt\fR (as the filename of \s-1DUCET\s0) is used.
If you will prepare your own table file, any name other than \fIallkeys.txt\fR
may be better to avoid namespace conflict.
.Sp
If \f(CW\*(C`undef\*(C'\fR is passed explicitly as the value for this key,
no file is read (but you can define collation elements via \f(CW\*(C`entry\*(C'\fR).
.Sp
A typical way to define a collation element table
without any file of table:
.Sp
.Vb 11
\& $onlyABC = Unicode::Collate->new(
\& table => undef,
\& entry => << 'ENTRIES',
\&0061 ; [.0101.0020.0002.0061] # LATIN SMALL LETTER A
\&0041 ; [.0101.0020.0008.0041] # LATIN CAPITAL LETTER A
\&0062 ; [.0102.0020.0002.0062] # LATIN SMALL LETTER B
\&0042 ; [.0102.0020.0008.0042] # LATIN CAPITAL LETTER B
\&0063 ; [.0103.0020.0002.0063] # LATIN SMALL LETTER C
\&0043 ; [.0103.0020.0008.0043] # LATIN CAPITAL LETTER C
\&ENTRIES
\& );
.Ve
.Sp
If \f(CW\*(C`ignoreName\*(C'\fR or \f(CW\*(C`undefName\*(C'\fR is used, character names should be
specified as a comment (following \f(CW\*(C`#\*(C'\fR) on each line.
.IP "undefChar" 4
.IX Item "undefChar"
.PD 0
.IP "undefName" 4
.IX Item "undefName"
.PD
\&\-\- see 6.3.4 Reducing the Repertoire, \s-1UTS\s0 #10.
.Sp
Undefines the collation element as if it were unassigned in the table.
This reduces the size of the table.
If an unassigned character appears in the string to be collated,
the sort key is made from its codepoint
as a single-character collation element,
as it is greater than any other assigned collation elements
(in the codepoint order among the unassigned characters).
But, it'd be better to ignore characters
unfamiliar to you and maybe never used.
.Sp
Through \f(CW\*(C`undefChar\*(C'\fR, any character matching \f(CW\*(C`qr/$undefChar/\*(C'\fR
will be undefined. Through \f(CW\*(C`undefName\*(C'\fR, any character whose name
(given in the \f(CW\*(C`table\*(C'\fR file as a comment) matches \f(CW\*(C`qr/$undefName/\*(C'\fR
will be undefined.
.Sp
ex. Collation weights for beyond-BMP characters are not stored in object:
.Sp
.Vb 1
\& undefChar => qr/[^\e0-\ex{fffd}]/,
.Ve
.IP "upper_before_lower" 4
.IX Item "upper_before_lower"
\&\-\- see 6.6 Case Comparisons, \s-1UTS\s0 #10.
.Sp
By default, lowercase is before uppercase.
If the parameter is made true, this is reversed.
.Sp
\&\fB\s-1NOTE\s0\fR: This parameter simplemindedly assumes that any lowercase/uppercase
distinctions must occur in level 3, and their weights at level 3 must be
same as those mentioned in 7.3.1, \s-1UTS\s0 #10.
If you define your collation elements which differs from this requirement,
this parameter doesn't work validly.
.IP "variable" 4
.IX Item "variable"
\&\-\- see 3.2.2 Variable Weighting, \s-1UTS\s0 #10.
.Sp
This key allows to variable weighting for variable collation elements,
which are marked with an \s-1ASTERISK\s0 in the table
(\s-1NOTE:\s0 Many punction marks and symbols are variable in \fIallkeys.txt\fR).
.Sp
.Vb 1
\& variable => 'blanked', 'non-ignorable', 'shifted', or 'shift-trimmed'.
.Ve
.Sp
These names are case\-insensitive.
By default (if specification is omitted), 'shifted' is adopted.
.Sp
.Vb 2
\& 'Blanked' Variable elements are made ignorable at levels 1 through 3;
\& considered at the 4th level.
.Ve
.Sp
.Vb 1
\& 'Non-Ignorable' Variable elements are not reset to ignorable.
.Ve
.Sp
.Vb 3
\& 'Shifted' Variable elements are made ignorable at levels 1 through 3
\& their level 4 weight is replaced by the old level 1 weight.
\& Level 4 weight for Non-Variable elements is 0xFFFF.
.Ve
.Sp
.Vb 2
\& 'Shift-Trimmed' Same as 'shifted', but all FFFF's at the 4th level
\& are trimmed.
.Ve
.Sh "Methods for Collation"
.IX Subsection "Methods for Collation"
.ie n .IP """@sorted = $Collator\->sort(@not_sorted)""" 4
.el .IP "\f(CW@sorted = $Collator\->sort(@not_sorted)\fR" 4
.IX Item "@sorted = $Collator->sort(@not_sorted)"
Sorts a list of strings.
.ie n .IP """$result = $Collator\->cmp($a, $b)""" 4
.el .IP "\f(CW$result = $Collator\->cmp($a, $b)\fR" 4
.IX Item "$result = $Collator->cmp($a, $b)"
Returns 1 (when \f(CW$a\fR is greater than \f(CW$b\fR)
or 0 (when \f(CW$a\fR is equal to \f(CW$b\fR)
or \-1 (when \f(CW$a\fR is lesser than \f(CW$b\fR).
.ie n .IP """$result = $Collator\->eq($a, $b)""" 4
.el .IP "\f(CW$result = $Collator\->eq($a, $b)\fR" 4
.IX Item "$result = $Collator->eq($a, $b)"
.PD 0
.ie n .IP """$result = $Collator\->ne($a, $b)""" 4
.el .IP "\f(CW$result = $Collator\->ne($a, $b)\fR" 4
.IX Item "$result = $Collator->ne($a, $b)"
.ie n .IP """$result = $Collator\->lt($a, $b)""" 4
.el .IP "\f(CW$result = $Collator\->lt($a, $b)\fR" 4
.IX Item "$result = $Collator->lt($a, $b)"
.ie n .IP """$result = $Collator\->le($a, $b)""" 4
.el .IP "\f(CW$result = $Collator\->le($a, $b)\fR" 4
.IX Item "$result = $Collator->le($a, $b)"
.ie n .IP """$result = $Collator\->gt($a, $b)""" 4
.el .IP "\f(CW$result = $Collator\->gt($a, $b)\fR" 4
.IX Item "$result = $Collator->gt($a, $b)"
.ie n .IP """$result = $Collator\->ge($a, $b)""" 4
.el .IP "\f(CW$result = $Collator\->ge($a, $b)\fR" 4
.IX Item "$result = $Collator->ge($a, $b)"
.PD
They works like the same name operators as theirs.
.Sp
.Vb 6
\& eq : whether $a is equal to $b.
\& ne : whether $a is not equal to $b.
\& lt : whether $a is lesser than $b.
\& le : whether $a is lesser than $b or equal to $b.
\& gt : whether $a is greater than $b.
\& ge : whether $a is greater than $b or equal to $b.
.Ve
.ie n .IP """$sortKey = $Collator\->getSortKey($string)""" 4
.el .IP "\f(CW$sortKey = $Collator\->getSortKey($string)\fR" 4
.IX Item "$sortKey = $Collator->getSortKey($string)"
\&\-\- see 4.3 Form Sort Key, \s-1UTS\s0 #10.
.Sp
Returns a sort key.
.Sp
You compare the sort keys using a binary comparison
and get the result of the comparison of the strings using \s-1UCA\s0.
.Sp
.Vb 1
\& $Collator->getSortKey($a) cmp $Collator->getSortKey($b)
.Ve
.Sp
.Vb 1
\& is equivalent to
.Ve
.Sp
.Vb 1
\& $Collator->cmp($a, $b)
.Ve
.ie n .IP """$sortKeyForm = $Collator\->viewSortKey($string)""" 4
.el .IP "\f(CW$sortKeyForm = $Collator\->viewSortKey($string)\fR" 4
.IX Item "$sortKeyForm = $Collator->viewSortKey($string)"
Converts a sorting key into its representation form.
If \f(CW\*(C`UCA_Version\*(C'\fR is 8, the output is slightly different.
.Sp
.Vb 3
\& use Unicode::Collate;
\& my $c = Unicode::Collate->new();
\& print $c->viewSortKey("Perl"),"\en";
.Ve
.Sp
.Vb 3
\& # output:
\& # [0B67 0A65 0B7F 0B03 | 0020 0020 0020 0020 | 0008 0002 0002 0002 | FFFF FFFF FFFF FFFF]
\& # Level 1 Level 2 Level 3 Level 4
.Ve
.Sh "Methods for Searching"
.IX Subsection "Methods for Searching"
\&\fB\s-1DISCLAIMER:\s0\fR If \f(CW\*(C`preprocess\*(C'\fR or \f(CW\*(C`normalization\*(C'\fR parameter is true
for \f(CW$Collator\fR, calling these methods (\f(CW\*(C`index\*(C'\fR, \f(CW\*(C`match\*(C'\fR, \f(CW\*(C`gmatch\*(C'\fR,
\&\f(CW\*(C`subst\*(C'\fR, \f(CW\*(C`gsubst\*(C'\fR) is croaked,
as the position and the length might differ
from those on the specified string.
(And \f(CW\*(C`rearrange\*(C'\fR and \f(CW\*(C`hangul_terminator\*(C'\fR parameters are neglected.)
.PP
The \f(CW\*(C`match\*(C'\fR, \f(CW\*(C`gmatch\*(C'\fR, \f(CW\*(C`subst\*(C'\fR, \f(CW\*(C`gsubst\*(C'\fR methods work
like \f(CW\*(C`m//\*(C'\fR, \f(CW\*(C`m//g\*(C'\fR, \f(CW\*(C`s///\*(C'\fR, \f(CW\*(C`s///g\*(C'\fR, respectively,
but they are not aware of any pattern, but only a literal substring.
.ie n .IP """$position = $Collator\->index($string, $substring[, $position])""" 4
.el .IP "\f(CW$position = $Collator\->index($string, $substring[, $position])\fR" 4
.IX Item "$position = $Collator->index($string, $substring[, $position])"
.PD 0
.ie n .IP """($position, $length) = $Collator\->index($string, $substring[, $position])""" 4
.el .IP "\f(CW($position, $length) = $Collator\->index($string, $substring[, $position])\fR" 4
.IX Item "($position, $length) = $Collator->index($string, $substring[, $position])"
.PD
If \f(CW$substring\fR matches a part of \f(CW$string\fR, returns
the position of the first occurrence of the matching part in scalar context;
in list context, returns a two-element list of
the position and the length of the matching part.
.Sp
If \f(CW$substring\fR does not match any part of \f(CW$string\fR,
returns \f(CW\*(C`\-1\*(C'\fR in scalar context and
an empty list in list context.
.Sp
e.g. you say
.Sp
.Vb 8
\& my $Collator = Unicode::Collate->new( normalization => undef, level => 1 );
\& # (normalization => undef) is REQUIRED.
\& my $str = "Ich muß studieren Perl.";
\& my $sub = "MÜSS";
\& my $match;
\& if (my($pos,$len) = $Collator->index($str, $sub)) {
\& $match = substr($str, $pos, $len);
\& }
.Ve
.Sp
and get \f(CW"muß"\fR in \f(CW$match\fR since \f(CW"muß"\fR
is primary equal to \f(CW"MÜSS"\fR.
.ie n .IP """$match_ref = $Collator\->match($string, $substring)""" 4
.el .IP "\f(CW$match_ref = $Collator\->match($string, $substring)\fR" 4
.IX Item "$match_ref = $Collator->match($string, $substring)"
.PD 0
.ie n .IP """($match) = $Collator\->match($string, $substring)""" 4
.el .IP "\f(CW($match) = $Collator\->match($string, $substring)\fR" 4
.IX Item "($match) = $Collator->match($string, $substring)"
.PD
If \f(CW$substring\fR matches a part of \f(CW$string\fR, in scalar context, returns
\&\fBa reference to\fR the first occurrence of the matching part
(\f(CW$match_ref\fR is always true if matches,
since every reference is \fBtrue\fR);
in list context, returns the first occurrence of the matching part.
.Sp
If \f(CW$substring\fR does not match any part of \f(CW$string\fR,
returns \f(CW\*(C`undef\*(C'\fR in scalar context and
an empty list in list context.
.Sp
e.g.
.Sp
.Vb 5
\& if ($match_ref = $Collator->match($str, $sub)) { # scalar context
\& print "matches [$$match_ref].\en";
\& } else {
\& print "doesn't match.\en";
\& }
.Ve
.Sp
.Vb 1
\& or
.Ve
.Sp
.Vb 5
\& if (($match) = $Collator->match($str, $sub)) { # list context
\& print "matches [$match].\en";
\& } else {
\& print "doesn't match.\en";
\& }
.Ve
.ie n .IP """@match = $Collator\->gmatch($string, $substring)""" 4
.el .IP "\f(CW@match = $Collator\->gmatch($string, $substring)\fR" 4
.IX Item "@match = $Collator->gmatch($string, $substring)"
If \f(CW$substring\fR matches a part of \f(CW$string\fR, returns
all the matching parts (or matching count in scalar context).
.Sp
If \f(CW$substring\fR does not match any part of \f(CW$string\fR,
returns an empty list.
.ie n .IP """$count = $Collator\->subst($string, $substring, $replacement)""" 4
.el .IP "\f(CW$count = $Collator\->subst($string, $substring, $replacement)\fR" 4
.IX Item "$count = $Collator->subst($string, $substring, $replacement)"
If \f(CW$substring\fR matches a part of \f(CW$string\fR,
the first occurrence of the matching part is replaced by \f(CW$replacement\fR
(\f(CW$string\fR is modified) and return \f(CW$count\fR (always equals to \f(CW1\fR).
.Sp
\&\f(CW$replacement\fR can be a \f(CW\*(C`CODEREF\*(C'\fR,
taking the matching part as an argument,
and returning a string to replace the matching part
(a bit similar to \f(CW\*(C`s/(..)/$coderef\->($1)/e\*(C'\fR).
.ie n .IP """$count = $Collator\->gsubst($string, $substring, $replacement)""" 4
.el .IP "\f(CW$count = $Collator\->gsubst($string, $substring, $replacement)\fR" 4
.IX Item "$count = $Collator->gsubst($string, $substring, $replacement)"
If \f(CW$substring\fR matches a part of \f(CW$string\fR,
all the occurrences of the matching part is replaced by \f(CW$replacement\fR
(\f(CW$string\fR is modified) and return \f(CW$count\fR.
.Sp
\&\f(CW$replacement\fR can be a \f(CW\*(C`CODEREF\*(C'\fR,
taking the matching part as an argument,
and returning a string to replace the matching part
(a bit similar to \f(CW\*(C`s/(..)/$coderef\->($1)/eg\*(C'\fR).
.Sp
e.g.
.Sp
.Vb 4
\& my $Collator = Unicode::Collate->new( normalization => undef, level => 1 );
\& # (normalization => undef) is REQUIRED.
\& my $str = "Camel donkey zebra came\ex{301}l CAMEL horse cAm\e0E\e0L...";
\& $Collator->gsubst($str, "camel", sub { "<b>$_[0]</b>" });
.Ve
.Sp
.Vb 2
\& # now $str is "<b>Camel</b> donkey zebra <b>came\ex{301}l</b> <b>CAMEL</b> horse <b>cAm\e0E\e0L</b>...";
\& # i.e., all the camels are made bold-faced.
.Ve
.Sh "Other Methods"
.IX Subsection "Other Methods"
.ie n .IP """%old_tailoring = $Collator\->change(%new_tailoring)""" 4
.el .IP "\f(CW%old_tailoring = $Collator\->change(%new_tailoring)\fR" 4
.IX Item "%old_tailoring = $Collator->change(%new_tailoring)"
Change the value of specified keys and returns the changed part.
.Sp
.Vb 1
\& $Collator = Unicode::Collate->new(level => 4);
.Ve
.Sp
.Vb 1
\& $Collator->eq("perl", "PERL"); # false
.Ve
.Sp
.Vb 1
\& %old = $Collator->change(level => 2); # returns (level => 4).
.Ve
.Sp
.Vb 1
\& $Collator->eq("perl", "PERL"); # true
.Ve
.Sp
.Vb 1
\& $Collator->change(%old); # returns (level => 2).
.Ve
.Sp
.Vb 1
\& $Collator->eq("perl", "PERL"); # false
.Ve
.Sp
Not all \f(CW\*(C`(key,value)\*(C'\fRs are allowed to be changed.
See also \f(CW@Unicode::Collate::ChangeOK\fR and \f(CW@Unicode::Collate::ChangeNG\fR.
.Sp
In the scalar context, returns the modified collator
(but it is \fBnot\fR a clone from the original).
.Sp
.Vb 1
\& $Collator->change(level => 2)->eq("perl", "PERL"); # true
.Ve
.Sp
.Vb 1
\& $Collator->eq("perl", "PERL"); # true; now max level is 2nd.
.Ve
.Sp
.Vb 1
\& $Collator->change(level => 4)->eq("perl", "PERL"); # false
.Ve
.ie n .IP """$version = $Collator\->version()""" 4
.el .IP "\f(CW$version = $Collator\->version()\fR" 4
.IX Item "$version = $Collator->version()"
Returns the version number (a string) of the Unicode Standard
which the \f(CW\*(C`table\*(C'\fR file used by the collator object is based on.
If the table does not include a version line (starting with \f(CW@version\fR),
returns \f(CW"unknown"\fR.
.ie n .IP """UCA_Version()""" 4
.el .IP "\f(CWUCA_Version()\fR" 4
.IX Item "UCA_Version()"
Returns the tracking version number of \s-1UTS\s0 #10 this module consults.
.ie n .IP """Base_Unicode_Version()""" 4
.el .IP "\f(CWBase_Unicode_Version()\fR" 4
.IX Item "Base_Unicode_Version()"
Returns the version number of \s-1UTS\s0 #10 this module consults.
.SH "EXPORT"
.IX Header "EXPORT"
No method will be exported.
.SH "INSTALL"
.IX Header "INSTALL"
Though this module can be used without any \f(CW\*(C`table\*(C'\fR file,
to use this module easily, it is recommended to install a table file
in the \s-1UCA\s0 format, by copying it under the directory
<a place in \f(CW@INC\fR>/Unicode/Collate.
.PP
The most preferable one is \*(L"The Default Unicode Collation Element Table\*(R"
(aka \s-1DUCET\s0), available from the Unicode Consortium's website:
.PP
.Vb 1
\& http://www.unicode.org/Public/UCA/
.Ve
.PP
.Vb 1
\& http://www.unicode.org/Public/UCA/latest/allkeys.txt (latest version)
.Ve
.PP
If \s-1DUCET\s0 is not installed, it is recommended to copy the file
from http://www.unicode.org/Public/UCA/latest/allkeys.txt
to <a place in \f(CW@INC\fR>/Unicode/Collate/allkeys.txt
manually.
.SH "CAVEATS"
.IX Header "CAVEATS"
.IP "Normalization" 4
.IX Item "Normalization"
Use of the \f(CW\*(C`normalization\*(C'\fR parameter requires the \fBUnicode::Normalize\fR
module (see Unicode::Normalize).
.Sp
If you need not it (say, in the case when you need not
handle any combining characters),
assign \f(CW\*(C`normalization => undef\*(C'\fR explicitly.
.Sp
\&\-\- see 6.5 Avoiding Normalization, \s-1UTS\s0 #10.
.IP "Conformance Test" 4
.IX Item "Conformance Test"
The Conformance Test for the \s-1UCA\s0 is available
under <http://www.unicode.org/Public/UCA/>.
.Sp
For \fICollationTest_SHIFTED.txt\fR,
a collator via \f(CW\*(C`Unicode::Collate\->new( )\*(C'\fR should be used;
for \fICollationTest_NON_IGNORABLE.txt\fR, a collator via
\&\f(CW\*(C`Unicode::Collate\->new(variable => "non\-ignorable", level => 3)\*(C'\fR.
.Sp
\&\fBUnicode::Normalize is required to try The Conformance Test.\fR
.SH "AUTHOR, COPYRIGHT AND LICENSE"
.IX Header "AUTHOR, COPYRIGHT AND LICENSE"
The Unicode::Collate module for perl was written by \s-1SADAHIRO\s0 Tomoyuki,
<SADAHIRO@cpan.org>. This module is Copyright(C) 2001\-2005,
\&\s-1SADAHIRO\s0 Tomoyuki. Japan. All rights reserved.
.PP
This module is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.
.PP
The file Unicode/Collate/allkeys.txt was copied directly
from <http://www.unicode.org/Public/UCA/4.1.0/allkeys.txt>.
This file is Copyright (c) 1991\-2005 Unicode, Inc. All rights reserved.
Distributed under the Terms of Use in <http://www.unicode.org/copyright.html>.
.SH "SEE ALSO"
.IX Header "SEE ALSO"
.IP "Unicode Collation Algorithm \- \s-1UTS\s0 #10" 4
.IX Item "Unicode Collation Algorithm - UTS #10"
<http://www.unicode.org/reports/tr10/>
.IP "The Default Unicode Collation Element Table (\s-1DUCET\s0)" 4
.IX Item "The Default Unicode Collation Element Table (DUCET)"
<http://www.unicode.org/Public/UCA/latest/allkeys.txt>
.IP "The conformance test for the \s-1UCA\s0" 4
.IX Item "The conformance test for the UCA"
<http://www.unicode.org/Public/UCA/latest/CollationTest.html>
.Sp
<http://www.unicode.org/Public/UCA/latest/CollationTest.zip>
.IP "Hangul Syllable Type" 4
.IX Item "Hangul Syllable Type"
<http://www.unicode.org/Public/UNIDATA/HangulSyllableType.txt>
.IP "Unicode Normalization Forms \- \s-1UAX\s0 #15" 4
.IX Item "Unicode Normalization Forms - UAX #15"
<http://www.unicode.org/reports/tr15/>