use strict;
use warnings;
-our $VERSION = '0.26';
+our $VERSION = '0.27';
use Storable qw(dclone);
=head1 DESCRIPTION
-The Unicode::UCD module offers a simple interface to the Unicode
+The Unicode::UCD module offers a series of functions that
+provide a simple interface to the Unicode
Character Database.
+=head2 code point argument
+
+Some of the functions are called with a I<code point argument>, which is either
+a decimal or a hexadecimal scalar designating a Unicode code point, or C<U+>
+followed by hexadecimals designating a Unicode code point. In other words, if
+you want a code point to be interpreted as a hexadecimal number, you must
+prefix it with either C<0x> or C<U+>, because a string like e.g. C<123> will be
+interpreted as a decimal code point. Also note that Unicode is B<not> limited
+to 16 bits (the number of Unicode code points is open-ended, in theory
+unlimited): you may have more than 4 hexdigits.
=cut
my $UNICODEFH;
return $f;
}
-=head2 charinfo
+=head2 B<charinfo()>
use Unicode::UCD 'charinfo';
my $charinfo = charinfo(0x41);
-charinfo() returns a reference to a hash that has the following fields
-as defined by the Unicode standard:
-
- key
-
- code code point with at least four hexdigits
- name name of the character IN UPPER CASE
- category general category of the character
- combining classes used in the Canonical Ordering Algorithm
- bidi bidirectional type
- decomposition character decomposition mapping
- decimal if decimal digit this is the integer numeric value
- digit if digit this is the numeric value
- numeric if numeric is the integer or rational numeric value
- mirrored if mirrored in bidirectional text
- unicode10 Unicode 1.0 name if existed and different
- comment ISO 10646 comment field
- upper uppercase equivalent mapping
- lower lowercase equivalent mapping
- title titlecase equivalent mapping
-
- block block the character belongs to (used in \p{In...})
- script script the character belongs to
-
-If no match is found, a reference to an empty hash is returned.
-
-The C<block> property is the same as returned by charinfo(). It is
-not defined in the Unicode Character Database proper (Chapter 4 of the
-Unicode 3.0 Standard, aka TUS3) but instead in an auxiliary database
-(Chapter 14 of TUS3). Similarly for the C<script> property.
+This returns information about the input L</code point argument>
+as a reference to a hash of fields as defined by the Unicode
+standard. If the L</code point argument> is not assigned in the standard
+(i.e., has the general category C<Cn> meaning C<Unassigned>)
+or is a non-character (meaning it is guaranteed to never be assigned in
+the standard),
+B<undef> is returned.
+
+Fields that aren't applicable to the particular code point argument exist in the
+returned hash, and are empty.
+
+The keys in the hash with the meanings of their values are:
+
+=over
+
+=item B<code>
+
+the input L</code point argument> expressed in hexadecimal, with leading zeros
+added if necessary to make it contain at least four hexdigits
+
+=item B<name>
+
+name of I<code>, all IN UPPER CASE.
+Some control-type code points do not have names.
+This field will be empty for C<Surrogate> and C<Private Use> code points,
+and for the others without a name,
+it will contain a description enclosed in angle brackets, like
+C<E<lt>controlE<gt>>.
+
+
+=item B<category>
+
+The short name of the general category of I<code>.
+This will match one of the keys in the hash returned by L</general_categories()>.
+
+=item B<combining>
+
+the combining class number for I<code> used in the Canonical Ordering Algorithm.
+For Unicode 5.1, this is described in Section 3.11 C<Canonical Ordering Behavior>
+available at
+L<http://www.unicode.org/versions/Unicode5.1.0/>
+
+=item B<bidi>
+
+bidirectional type of I<code>.
+This will match one of the keys in the hash returned by L</bidi_types()>.
+
+=item B<decomposition>
+
+is empty if I<code> has no decomposition; or is one or more codes
+(separated by spaces) that taken in order represent a decomposition for
+I<code>. Each has at least four hexdigits.
+The codes may be preceded by a word enclosed in angle brackets then a space,
+like C<E<lt>compatE<gt> >, giving the type of decomposition
+
+=item B<decimal>
+
+if I<code> is a decimal digit this is its integer numeric value
+
+=item B<digit>
+
+if I<code> represents a whole number, this is its integer numeric value
+
+=item B<numeric>
+
+if I<code> represents a whole or rational number, this is its numeric value.
+Rational values are expressed as a string like C<1/4>.
+
+=item B<mirrored>
+
+C<Y> or C<N> designating if I<code> is mirrored in bidirectional text
+
+=item B<unicode10>
+
+name of I<code> in the Unicode 1.0 standard if one
+existed for this code point and is different from the current name
+
+=item B<comment>
+
+ISO 10646 comment field.
+It appears in parentheses in the ISO 10646 names list,
+or contains an asterisk to indicate there is
+a note for this code point in Annex P of that standard.
+
+=item B<upper>
+
+is empty if there is no single code point uppercase mapping for I<code>;
+otherwise it is that mapping expressed as at least four hexdigits.
+(L</casespec()> should be used in addition to B<charinfo()>
+for case mappings when the calling program can cope with multiple code point
+mappings.)
+
+=item B<lower>
+
+is empty if there is no single code point lowercase mapping for I<code>;
+otherwise it is that mapping expressed as at least four hexdigits.
+(L</casespec()> should be used in addition to B<charinfo()>
+for case mappings when the calling program can cope with multiple code point
+mappings.)
+
+=item B<title>
+
+is empty if there is no single code point titlecase mapping for I<code>;
+otherwise it is that mapping expressed as at least four hexdigits.
+(L</casespec()> should be used in addition to B<charinfo()>
+for case mappings when the calling program can cope with multiple code point
+mappings.)
+
+=item B<block>
+
+block I<code> belongs to (used in \p{In...}).
+See L</Blocks versus Scripts>.
+
+
+=item B<script>
+
+script I<code> belongs to.
+See L</Blocks versus Scripts>.
+
+=back
Note that you cannot do (de)composition and casing based solely on the
-above C<decomposition> and C<lower>, C<upper>, C<title>, properties,
-you will need also the compexcl(), casefold(), and casespec() functions.
+I<decomposition>, I<combining>, I<lower>, I<upper>, and I<title> fields;
+you will need also the L</compexcl()>, and L</casespec()> functions.
=cut
_search($range, 0, $#$range, $code);
}
-=head2 charblock
+=head2 B<charblock()>
use Unicode::UCD 'charblock';
my $charblock = charblock(0x41);
my $charblock = charblock(1234);
- my $charblock = charblock("0x263a");
+ my $charblock = charblock(0x263a);
my $charblock = charblock("U+263a");
my $range = charblock('Armenian');
-With a B<code point argument> charblock() returns the I<block> the character
-belongs to, e.g. C<Basic Latin>. Note that not all the character
-positions within all blocks are defined.
+With a L</code point argument> charblock() returns the I<block> the code point
+belongs to, e.g. C<Basic Latin>.
+If the code point is unassigned, this returns the block it would belong to if
+it were assigned (which it may in future versions of the Unicode Standard).
See also L</Blocks versus Scripts>.
If supplied with an argument that can't be a code point, charblock() tries
-to do the opposite and interpret the argument as a character block. The
+to do the opposite and interpret the argument as a code point block. The
return value is a I<range>: an anonymous list of lists that contain
I<start-of-range>, I<end-of-range> code point pairs. You can test whether
-a code point is in a range using the L</charinrange> function. If the
-argument is not a known character block, C<undef> is returned.
+a code point is in a range using the L</charinrange()> function. If the
+argument is not a known code point block, B<undef> is returned.
=cut
}
}
-=head2 charscript
+=head2 B<charscript()>
use Unicode::UCD 'charscript';
my $range = charscript('Thai');
-With a B<code point argument> charscript() returns the I<script> the
-character belongs to, e.g. C<Latin>, C<Greek>, C<Han>.
-
-See also L</Blocks versus Scripts>.
+With a L</code point argument> charscript() returns the I<script> the
+code point belongs to, e.g. C<Latin>, C<Greek>, C<Han>.
+If the code point is unassigned, it returns B<undef>
If supplied with an argument that can't be a code point, charscript() tries
-to do the opposite and interpret the argument as a character script. The
+to do the opposite and interpret the argument as a code point script. The
return value is a I<range>: an anonymous list of lists that contain
I<start-of-range>, I<end-of-range> code point pairs. You can test whether a
-code point is in a range using the L</charinrange> function. If the
-argument is not a known character script, C<undef> is returned.
+code point is in a range using the L</charinrange()> function. If the
+argument is not a known code point script, B<undef> is returned.
+
+See also L</Blocks versus Scripts>.
=cut
}
}
-=head2 charblocks
+=head2 B<charblocks()>
use Unicode::UCD 'charblocks';
my $charblocks = charblocks();
charblocks() returns a reference to a hash with the known block names
-as the keys, and the code point ranges (see L</charblock>) as the values.
+as the keys, and the code point ranges (see L</charblock()>) as the values.
See also L</Blocks versus Scripts>.
return dclone \%BLOCKS;
}
-=head2 charscripts
+=head2 B<charscripts()>
use Unicode::UCD 'charscripts';
my $charscripts = charscripts();
charscripts() returns a reference to a hash with the known script
-names as the keys, and the code point ranges (see L</charscript>) as
+names as the keys, and the code point ranges (see L</charscript()>) as
the values.
See also L</Blocks versus Scripts>.
return dclone \%SCRIPTS;
}
-=head2 Blocks versus Scripts
-
-The difference between a block and a script is that scripts are closer
-to the linguistic notion of a set of characters required to present
-languages, while block is more of an artifact of the Unicode character
-numbering and separation into blocks of (mostly) 256 characters.
-
-For example the Latin B<script> is spread over several B<blocks>, such
-as C<Basic Latin>, C<Latin 1 Supplement>, C<Latin Extended-A>, and
-C<Latin Extended-B>. On the other hand, the Latin script does not
-contain all the characters of the C<Basic Latin> block (also known as
-the ASCII): it includes only the letters, and not, for example, the digits
-or the punctuation.
-
-For blocks see http://www.unicode.org/Public/UNIDATA/Blocks.txt
-
-For scripts see UTR #24: http://www.unicode.org/unicode/reports/tr24/
-
-=head2 Matching Scripts and Blocks
-
-Scripts are matched with the regular-expression construct
-C<\p{...}> (e.g. C<\p{Tibetan}> matches characters of the Tibetan script),
-while C<\p{In...}> is used for blocks (e.g. C<\p{InTibetan}> matches
-any of the 256 code points in the Tibetan block).
-
-=head2 Code Point Arguments
-
-A I<code point argument> is either a decimal or a hexadecimal scalar
-designating a Unicode character, or C<U+> followed by hexadecimals
-designating a Unicode character. In other words, if you want a code
-point to be interpreted as a hexadecimal number, you must prefix it
-with either C<0x> or C<U+>, because a string like e.g. C<123> will
-be interpreted as a decimal code point. Also note that Unicode is
-B<not> limited to 16 bits (the number of Unicode characters is
-open-ended, in theory unlimited): you may have more than 4 hexdigits.
-
-=head2 charinrange
+=head2 B<charinrange()>
In addition to using the C<\p{In...}> and C<\P{In...}> constructs, you
can also test whether a code point is in the I<range> as returned by
-L</charblock> and L</charscript> or as the values of the hash returned
-by L</charblocks> and L</charscripts> by using charinrange():
+L</charblock()> and L</charscript()> or as the values of the hash returned
+by L</charblocks()> and L</charscripts()> by using charinrange():
use Unicode::UCD qw(charscript charinrange);
return dclone \%GENERAL_CATEGORIES;
}
-=head2 general_categories
+=head2 B<general_categories()>
use Unicode::UCD 'general_categories';
my $categories = general_categories();
-The general_categories() returns a reference to a hash which has short
+This returns a reference to a hash which has short
general category names (such as C<Lu>, C<Nd>, C<Zs>, C<S>) as keys and long
names (such as C<UppercaseLetter>, C<DecimalNumber>, C<SpaceSeparator>,
C<Symbol>) as values. The hash is reversible in case you need to go
from the long names to the short names. The general category is the
-one returned from charinfo() under the C<category> key.
+one returned from
+L</charinfo()> under the C<category> key.
=cut
'ON' => 'Other Neutrals',
);
-sub bidi_types {
- return dclone \%BIDI_TYPES;
-}
-
-=head2 bidi_types
+=head2 B<bidi_types()>
use Unicode::UCD 'bidi_types';
my $categories = bidi_types();
-The bidi_types() returns a reference to a hash which has the short
+This returns a reference to a hash which has the short
bidi (bidirectional) type names (such as C<L>, C<R>) as keys and long
names (such as C<Left-to-Right>, C<Right-to-Left>) as values. The
hash is reversible in case you need to go from the long names to the
-short names. The bidi type is the one returned from charinfo()
+short names. The bidi type is the one returned from
+L</charinfo()>
under the C<bidi> key. For the exact meaning of the various bidi classes
the Unicode TR9 is recommended reading:
-http://www.unicode.org/reports/tr9/tr9-17.html
+L<http://www.unicode.org/reports/tr9/>
(as of Unicode 5.0.0)
=cut
-=head2 compexcl
+sub bidi_types {
+ return dclone \%BIDI_TYPES;
+}
+
+=head2 B<compexcl()>
use Unicode::UCD 'compexcl';
- my $compexcl = compexcl("09dc");
+ my $compexcl = compexcl(0x09dc);
-The compexcl() returns the composition exclusion (that is, if the
-character should not be produced during a precomposition) of the
-character specified by a B<code point argument>.
+This returns B<true> if the
+L</code point argument> should not be produced by composition normalization,
+B<AND> if that fact is not otherwise determinable from the Unicode data base.
+It currently does not return B<true> if the code point has a decomposition
+consisting of another single code point, nor if its decomposition starts
+with a code point whose combining class is non-zero. Code points that meet
+either of these conditions should also not be produced by composition
+normalization.
-If there is a composition exclusion for the character, true is
-returned. Otherwise, false is returned.
+It returns B<false> otherwise.
=cut
return exists $COMPEXCL{$code};
}
-=head2 casefold
+=head2 B<casefold()>
use Unicode::UCD 'casefold';
- my $casefold = casefold("00DF");
+ my $casefold = casefold(0xDF);
+ if (defined $casefold) {
+ my @full_fold_hex = split / /, $casefold->{'full'};
+ my $full_fold_string =
+ join "", map {chr(hex($_))} @full_fold_hex;
+ my @turkic_fold_hex =
+ split / /, ($casefold->{'turkic'} ne "")
+ ? $casefold->{'turkic'}
+ : $casefold->{'full'};
+ my $turkic_fold_string =
+ join "", map {chr(hex($_))} @turkic_fold_hex;
+ }
+ if (defined $casefold && $casefold->{'simple'} ne "") {
+ my $simple_fold_hex = $casefold->{'simple'};
+ my $simple_fold_string = chr(hex($simple_fold_hex));
+ }
-The casefold() returns the locale-independent case folding of the
-character specified by a B<code point argument>.
+This returns the (almost) locale-independent case folding of the
+character specified by the L</code point argument>.
-If there is a case folding for that character, a reference to a hash
+If there is no case folding for that code point, B<undef> is returned.
+
+If there is a case folding for that code point, a reference to a hash
with the following fields is returned:
- key
+=over
+
+=item B<code>
+
+the input L</code point argument> expressed in hexadecimal, with leading zeros
+added if necessary to make it contain at least four hexdigits
+
+=item B<full>
+
+one or more codes (separated by spaces) that taken in order give the
+code points for the case folding for I<code>.
+Each has at least four hexdigits.
+
+=item B<simple>
+
+is empty, or is exactly one code with at least four hexdigits which can be used
+as an alternative case folding when the calling program cannot cope with the
+fold being a sequence of multiple code points. If I<full> is just one code
+point, then I<simple> equals I<full>. If there is no single code point folding
+defined for I<code>, then I<simple> is the empty string. Otherwise, it is an
+inferior, but still better-than-nothing alternative folding to I<full>.
+
+=item B<mapping>
+
+is the same as I<simple> if I<simple> is not empty, and it is the same as I<full>
+otherwise. It can be considered to be the simplest possible folding for
+I<code>. It is defined primarily for backwards compatibility.
+
+=item B<status>
- code code point with at least four hexdigits
- status "C", "F", "S", or "I"
- mapping one or more codes separated by spaces
+is C<C> (for C<common>) if the best possible fold is a single code point
+(I<simple> equals I<full> equals I<mapping>). It is C<S> if there are distinct
+folds, I<simple> and I<full> (I<mapping> equals I<simple>). And it is C<F> if
+there only a I<full> fold (I<mapping> equals I<full>; I<simple> is empty). Note
+that this
+describes the contents of I<mapping>. It is defined primarily for backwards
+compatibility.
-The meaning of the I<status> is as follows:
+On versions 3.1 and earlier of Unicode, I<status> can also be
+C<I> which is the same as C<C> but is a special case for dotted uppercase I and
+dotless lowercase i:
- C common case folding, common mappings shared
- by both simple and full mappings
- F full case folding, mappings that cause strings
- to grow in length. Multiple characters are separated
- by spaces
- S simple case folding, mappings to single characters
- where different from F
- I special case for dotted uppercase I and
- dotless lowercase i
- - If this mapping is included, the result is
- case-insensitive, but dotless and dotted I's
- are not distinguished
- - If this mapping is excluded, the result is not
- fully case-insensitive, but dotless and dotted
- I's are distinguished
+=over
-If there is no case folding for that character, C<undef> is returned.
+=item B<*>
+
+If you use this C<I> mapping, the result is case-insensitive,
+but dotless and dotted I's are not distinguished
+
+=item B<*>
+
+If you exclude this C<I> mapping, the result is not fully case-insensitive, but
+dotless and dotted I's are distinguished
+
+=back
+
+=item B<turkic>
+
+contains any special folding for Turkic languages. For versions of Unicode
+starting with 3.2, this field is empty unless I<code> has a different folding
+in Turkic languages, in which case it is one or more codes (separated by
+spaces) that taken in order give the code points for the case folding for
+I<code> in those languages.
+Each code has at least four hexdigits.
+Note that this folding does not maintain canonical equivalence without
+additional processing.
+
+For versions of Unicode 3.1 and earlier, this field is empty unless there is a
+special folding for Turkic languages, in which case I<status> is C<I>, and
+I<mapping>, I<full>, I<simple>, and I<turkic> are all equal.
+
+=back
+
+Programs that want complete generality and the best folding results should use
+the folding contained in the I<full> field. But note that the fold for some
+code points will be a sequence of multiple code points.
+
+Programs that can't cope with the fold mapping being multiple code points can
+use the folding contained in the I<simple> field, with the loss of some
+generality. In Unicode 5.1, about 7% of the defined foldings have no single
+code point folding.
+
+The I<mapping> and I<status> fields are provided for backwards compatibility for
+existing programs. They contain the same values as in previous versions of
+this function.
+
+Locale is not completely independent. The I<turkic> field contains results to
+use when the locale is a Turkic language.
For more information about case mappings see
-http://www.unicode.org/unicode/reports/tr21/
+L<http://www.unicode.org/unicode/reports/tr21>
=cut
if (openunicode(\$CASEFOLDFH, "CaseFolding.txt")) {
local $_;
while (<$CASEFOLDFH>) {
- if (/^([0-9A-F]+); ([CFSI]); ([0-9A-F]+(?: [0-9A-F]+)*);/) {
+ if (/^([0-9A-F]+); ([CFIST]); ([0-9A-F]+(?: [0-9A-F]+)*);/) {
my $code = hex($1);
- $CASEFOLD{$code} = { code => $1,
- status => $2,
- mapping => $3 };
+ $CASEFOLD{$code}{'code'} = $1;
+ $CASEFOLD{$code}{'turkic'} = "" unless
+ defined $CASEFOLD{$code}{'turkic'};
+ if ($2 eq 'C' || $2 eq 'I') { # 'I' is only on 3.1 and
+ # earlier Unicodes
+ # Both entries there (I
+ # only checked 3.1) are
+ # the same as C, and
+ # there are no other
+ # entries for those
+ # codepoints, so treat
+ # as if C, but override
+ # the turkic one for
+ # 'I'.
+ $CASEFOLD{$code}{'status'} = $2;
+ $CASEFOLD{$code}{'full'} = $CASEFOLD{$code}{'simple'} =
+ $CASEFOLD{$code}{'mapping'} = $3;
+ $CASEFOLD{$code}{'turkic'} = $3 if $2 eq 'I';
+ } elsif ($2 eq 'F') {
+ $CASEFOLD{$code}{'full'} = $3;
+ unless (defined $CASEFOLD{$code}{'simple'}) {
+ $CASEFOLD{$code}{'simple'} = "";
+ $CASEFOLD{$code}{'mapping'} = $3;
+ $CASEFOLD{$code}{'status'} = $2;
+ }
+ } elsif ($2 eq 'S') {
+
+
+ # There can't be a simple without a full, and simple
+ # overrides all but full
+
+ $CASEFOLD{$code}{'simple'} = $3;
+ $CASEFOLD{$code}{'mapping'} = $3;
+ $CASEFOLD{$code}{'status'} = $2;
+ } elsif ($2 eq 'T') {
+ $CASEFOLD{$code}{'turkic'} = $3;
+ } # else can't happen because only [CIFST] are possible
}
}
close($CASEFOLDFH);
return $CASEFOLD{$code};
}
-=head2 casespec
+=head2 B<casespec()>
use Unicode::UCD 'casespec';
- my $casespec = casespec("FB00");
+ my $casespec = casespec(0xFB00);
-The casespec() returns the potentially locale-dependent case mapping
-of the character specified by a B<code point argument>. The mapping
-may change the length of the string (which the basic Unicode case
-mappings as returned by charinfo() never do).
+This returns the potentially locale-dependent case mappings of the L</code point
+argument>. The mappings may be longer than a single code point (which the basic
+Unicode case mappings as returned by L</charinfo()> never are).
-If there is a case folding for that character, a reference to a hash
-with the following fields is returned:
+If there are no case mappings for the L</code point argument>, or if all three
+possible mappings (I<lower>, I<title> and I<upper>) result in single code
+points and are locale independent and uncondtional, B<undef> is returned.
+
+Otherwise, a reference to a hash giving the mappings (or a reference to a hash
+of such hashes, explained below) is returned.
+
+The keys in the bottom layer hash with the meanings of their values are:
+
+=over
+
+=item B<code>
+
+the input L</code point argument> expressed in hexadecimal, with leading zeros
+added if necessary to make it contain at least four hexdigits
+
+=item B<lower>
+
+one or more codes (separated by spaces) that taken in order give the
+code points for the lower case of I<code>.
+Each has at least four hexdigits.
+
+=item B<title>
- key
+one or more codes (separated by spaces) that taken in order give the
+code points for the title case of I<code>.
+Each has at least four hexdigits.
- code code point with at least four hexdigits
- lower lowercase
- title titlecase
- upper uppercase
- condition condition list (may be undef)
+=item B<lower>
-The C<condition> is optional. Where present, it consists of one or
-more I<locales> or I<contexts>, separated by spaces (other than as
-used to separate elements, spaces are to be ignored). A condition
-list overrides the normal behavior if all of the listed conditions are
-true. Case distinctions in the condition list are not significant.
+one or more codes (separated by spaces) that taken in order give the
+code points for the upper case of I<code>.
+Each has at least four hexdigits.
+
+=item B<condition>
+
+the conditions for the mappings to be valid.
+If B<undef>, the mappings are always valid.
+When defined, this field is a list of conditions,
+all of which must be true for the mappings to be valid.
+The list consists of one or more
+I<locales> (see below)
+and/or I<contexts> (explained in the next paragraph),
+separated by spaces.
+(Other than as used to separate elements, spaces are to be ignored.)
+Case distinctions in the condition list are not significant.
Conditions preceded by "NON_" represent the negation of the condition.
-Note that when there are multiple case folding definitions for a
-single code point because of different locales, the value returned by
-casespec() is a hash reference which has the locales as the keys and
-hash references as described above as the values.
+A I<context> is one of those defined in the Unicode standard.
+For Unicode 5.1, they are defined in Section 3.13 C<Default Case Operations>
+available at
+L<http://www.unicode.org/versions/Unicode5.1.0/>
-A I<locale> is defined as a 2-letter ISO 3166 country code, possibly
+=back
+
+If the return value is to a hash of hashes, it is because there are multiple
+case mapping definitions for a single code point
+(because of different rules for different locales).
+Each sub-hash is of the form above, and the keys of the outer hash are
+the locales, which are
+defined as 2-letter ISO 3166 country codes, possibly
followed by a "_" and a 2-letter ISO language code (possibly followed
-by a "_" and a variant code). You can find the lists of those codes,
+by a "_" and a variant code). You can find the lists of all possible locales,
see L<Locale::Country> and L<Locale::Language>.
-
-A I<context> is one of the following choices:
-
- FINAL The letter is not followed by a letter of
- general category L (e.g. Ll, Lt, Lu, Lm, or Lo)
- MODERN The mapping is only used for modern text
- AFTER_i The last base character was "i" (U+0069)
+(In Unicode 5.1, the only locales returned by this function
+are C<lt>, C<tr>, and C<az>.)
For more information about case mappings see
-http://www.unicode.org/unicode/reports/tr21/
+L<http://www.unicode.org/unicode/reports/tr21/>
=cut
return ref $CASESPEC{$code} ? dclone $CASESPEC{$code} : $CASESPEC{$code};
}
-=head2 namedseq()
+=head2 B<namedseq()>
use Unicode::UCD 'namedseq';
my %namedseq = namedseq();
If used with a single argument in a scalar context, returns the string
-consisting of the code points of the named sequence, or C<undef> if no
+consisting of the code points of the named sequence, or B<undef> if no
named sequence by that name exists. If used with a single argument in
-a list context, returns list of the code points. If used with no
+a list context, it returns the list of the code points. If used with no
arguments in a list context, returns a hash with the names of the
named sequences as the keys and the named sequences as strings as
-the values. Otherwise, returns C<undef> or empty list depending
+the values. Otherwise, it returns B<undef> or an empty list depending
on the context.
-(New from Unicode 4.1.0)
+This function only operates on officially approved (not provisional) named
+sequences.
=cut
=head2 Unicode::UCD::UnicodeVersion
-Unicode::UCD::UnicodeVersion() returns the version of the Unicode
-Character Database, in other words, the version of the Unicode
-standard the database implements. The version is a string
-of numbers delimited by dots (C<'.'>).
+This returns the version of the Unicode Character Database, in other words, the
+version of the Unicode standard the database implements. The version is a
+string of numbers delimited by dots (C<'.'>).
=cut
return $UNICODEVERSION;
}
+=head2 B<Blocks versus Scripts>
+
+The difference between a block and a script is that scripts are closer
+to the linguistic notion of a set of code points required to present
+languages, while block is more of an artifact of the Unicode code point
+numbering and separation into blocks of (mostly) 256 code points.
+
+For example the Latin B<script> is spread over several B<blocks>, such
+as C<Basic Latin>, C<Latin 1 Supplement>, C<Latin Extended-A>, and
+C<Latin Extended-B>. On the other hand, the Latin script does not
+contain all the characters of the C<Basic Latin> block (also known as
+ASCII): it includes only the letters, and not, for example, the digits
+or the punctuation.
+
+For blocks see L<http://www.unicode.org/Public/UNIDATA/Blocks.txt>
+
+For scripts see UTR #24: L<http://www.unicode.org/unicode/reports/tr24/>
+
+=head2 B<Matching Scripts and Blocks>
+
+Scripts are matched with the regular-expression construct
+C<\p{...}> (e.g. C<\p{Tibetan}> matches characters of the Tibetan script),
+while C<\p{In...}> is used for blocks (e.g. C<\p{InTibetan}> matches
+any of the 256 code points in the Tibetan block).
+
+
=head2 Implementation Note
The first use of charinfo() opens a read-only filehandle to the Unicode
Does not yet support EBCDIC platforms.
+L</compexcl()> should give a complete list of excluded code points.
+
=head1 AUTHOR
Jarkko Hietaniemi
#!perl -w
BEGIN {
- if (ord("A") == 193) {
+ if (ord("A") != 65) {
print "1..0 # Skip: EBCDIC\n";
exit 0;
}
use Unicode::UCD;
use Test::More;
-BEGIN { plan tests => 194 };
+BEGIN { plan tests => 239 };
use Unicode::UCD 'charinfo';
is($charinfo->{block}, 'Mathematical Alphanumeric Symbols');
is($charinfo->{script}, 'Common');
+$charinfo = charinfo(0x9FBA); #Bug 58428
+
+is($charinfo->{code}, '9FBA', 'U+9FBA');
+is($charinfo->{name}, 'CJK UNIFIED IDEOGRAPH-9FBA');
+is($charinfo->{category}, 'Lo');
+is($charinfo->{combining}, '0');
+is($charinfo->{bidi}, 'L');
+is($charinfo->{decomposition}, '');
+is($charinfo->{decimal}, '');
+is($charinfo->{digit}, '');
+is($charinfo->{numeric}, '');
+is($charinfo->{mirrored}, 'N');
+is($charinfo->{unicode10}, '');
+is($charinfo->{comment}, '');
+is($charinfo->{upper}, '');
+is($charinfo->{lower}, '');
+is($charinfo->{title}, '');
+is($charinfo->{block}, 'CJK Unified Ideographs');
+is($charinfo->{script}, 'Han');
+
use Unicode::UCD qw(charblock charscript);
# 0x0590 is in the Hebrew block but unused.
is($bt->{L}, 'Left-to-Right', 'L is Left-to-Right');
is($bt->{AL}, 'Right-to-Left Arabic', 'AL is Right-to-Left Arabic');
+# If this fails, then maybe one should look at the Unicode changes to see
+# what else might need to be updated.
is(Unicode::UCD::UnicodeVersion, '5.1.0', 'UnicodeVersion');
use Unicode::UCD qw(compexcl);
$casefold = casefold(0x41);
-ok($casefold->{code} eq '0041' &&
- $casefold->{status} eq 'C' &&
- $casefold->{mapping} eq '0061', 'casefold 0x41');
+is($casefold->{code}, '0041', 'casefold 0x41 code');
+is($casefold->{status}, 'C', 'casefold 0x41 status');
+is($casefold->{mapping}, '0061', 'casefold 0x41 mapping');
+is($casefold->{full}, '0061', 'casefold 0x41 full');
+is($casefold->{simple}, '0061', 'casefold 0x41 simple');
+is($casefold->{turkic}, "", 'casefold 0x41 turkic');
$casefold = casefold(0xdf);
-ok($casefold->{code} eq '00DF' &&
- $casefold->{status} eq 'F' &&
- $casefold->{mapping} eq '0073 0073', 'casefold 0xDF');
+is($casefold->{code}, '00DF', 'casefold 0xDF code');
+is($casefold->{status}, 'F', 'casefold 0xDF status');
+is($casefold->{mapping}, '0073 0073', 'casefold 0xDF mapping');
+is($casefold->{full}, '0073 0073', 'casefold 0xDF full');
+is($casefold->{simple}, "", 'casefold 0xDF simple');
+is($casefold->{turkic}, "", 'casefold 0xDF turkic');
+
+# Do different tests depending on if version <= 3.1, or not.
+(my $version = Unicode::UCD::UnicodeVersion) =~ /^(\d+)\.(\d+)/;
+if (defined $1 && ($1 <= 2 || $1 == 3 && defined $2 && $2 <= 1)) {
+ $casefold = casefold(0x130);
+
+ is($casefold->{code}, '0130', 'casefold 0x130 code');
+ is($casefold->{status}, 'I' , 'casefold 0x130 status');
+ is($casefold->{mapping}, '0069', 'casefold 0x130 mapping');
+ is($casefold->{full}, '0069', 'casefold 0x130 full');
+ is($casefold->{simple}, "0069", 'casefold 0x130 simple');
+ is($casefold->{turkic}, "0069", 'casefold 0x130 turkic');
+
+ $casefold = casefold(0x131);
+
+ is($casefold->{code}, '0131', 'casefold 0x131 code');
+ is($casefold->{status}, 'I' , 'casefold 0x131 status');
+ is($casefold->{mapping}, '0069', 'casefold 0x131 mapping');
+ is($casefold->{full}, '0069', 'casefold 0x131 full');
+ is($casefold->{simple}, "0069", 'casefold 0x131 simple');
+ is($casefold->{turkic}, "0069", 'casefold 0x131 turkic');
+} else {
+ $casefold = casefold(0x49);
+
+ is($casefold->{code}, '0049', 'casefold 0x49 code');
+ is($casefold->{status}, 'C' , 'casefold 0x49 status');
+ is($casefold->{mapping}, '0069', 'casefold 0x49 mapping');
+ is($casefold->{full}, '0069', 'casefold 0x49 full');
+ is($casefold->{simple}, "0069", 'casefold 0x49 simple');
+ is($casefold->{turkic}, "0131", 'casefold 0x49 turkic');
+
+ $casefold = casefold(0x130);
+
+ is($casefold->{code}, '0130', 'casefold 0x130 code');
+ is($casefold->{status}, 'F' , 'casefold 0x130 status');
+ is($casefold->{mapping}, '0069 0307', 'casefold 0x130 mapping');
+ is($casefold->{full}, '0069 0307', 'casefold 0x130 full');
+ is($casefold->{simple}, "", 'casefold 0x130 simple');
+ is($casefold->{turkic}, "0069", 'casefold 0x130 turkic');
+}
+
+$casefold = casefold(0x1F88);
+
+is($casefold->{code}, '1F88', 'casefold 0x1F88 code');
+is($casefold->{status}, 'S' , 'casefold 0x1F88 status');
+is($casefold->{mapping}, '1F80', 'casefold 0x1F88 mapping');
+is($casefold->{full}, '1F00 03B9', 'casefold 0x1F88 full');
+is($casefold->{simple}, '1F80', 'casefold 0x1F88 simple');
+is($casefold->{turkic}, "", 'casefold 0x1F88 turkic');
ok(!casefold(0x20));