ucd.html

来自「perl教程」· HTML 代码 · 共 410 行 · 第 1/2 页

HTML
410
字号
</p>
<h2><a name="charscripts">charscripts</a></h2>
<pre>
    <span class="keyword">use</span> <span class="variable">Unicode::UCD</span> <span class="string">'charscripts'</span><span class="operator">;</span>
</pre>
<pre>
    <span class="keyword">my</span> <span class="variable">%charscripts</span> <span class="operator">=</span> <span class="variable">charscripts</span><span class="operator">();</span>
</pre>
<p><code>charscripts()</code> returns a hash with the known script names as the keys,
and the code point ranges (see <a href="#charscript">charscript</a>) as the values.</p>
<p>See also <a href="#blocks_versus_scripts">Blocks versus Scripts</a>.</p>
<p>
</p>
<h2><a name="blocks_versus_scripts">Blocks versus Scripts</a></h2>
<p>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.</p>
<p>For example the Latin <strong>script</strong> is spread over several <strong>blocks</strong>, such
as <code>Basic Latin</code>, <code>Latin 1 Supplement</code>, <code>Latin Extended-A</code>, and
<code>Latin Extended-B</code>.  On the other hand, the Latin script does not
contain all the characters of the <code>Basic Latin</code> block (also known as
the ASCII): it includes only the letters, and not, for example, the digits
or the punctuation.</p>
<p>For blocks see <a href="http://www.unicode.org/Public/UNIDATA/Blocks.txt">http://www.unicode.org/Public/UNIDATA/Blocks.txt</a></p>
<p>For scripts see UTR #24: <a href="http://www.unicode.org/unicode/reports/tr24/">http://www.unicode.org/unicode/reports/tr24/</a></p>
<p>
</p>
<h2><a name="matching_scripts_and_blocks">Matching Scripts and Blocks</a></h2>
<p>Scripts are matched with the regular-expression construct
<code>\p{...}</code> (e.g. <code>\p{Tibetan}</code> matches characters of the Tibetan script),
while <code>\p{In...}</code> is used for blocks (e.g. <code>\p{InTibetan}</code> matches
any of the 256 code points in the Tibetan block).</p>
<p>
</p>
<h2><a name="code_point_arguments">Code Point Arguments</a></h2>
<p>A <em>code point argument</em> is either a decimal or a hexadecimal scalar
designating a Unicode character, or <code>U+</code> 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 <code>0x</code> or <code>U+</code>, because a string like e.g. <code>123</code> will
be interpreted as a decimal code point.  Also note that Unicode is
<strong>not</strong> limited to 16 bits (the number of Unicode characters is
open-ended, in theory unlimited): you may have more than 4 hexdigits.</p>
<p>
</p>
<h2><a name="charinrange">charinrange</a></h2>
<p>In addition to using the <code>\p{In...}</code> and <code>\P{In...}</code> constructs, you
can also test whether a code point is in the <em>range</em> as returned by
<a href="#charblock">charblock</a> and <a href="#charscript">charscript</a> or as the values of the hash returned
by <a href="#charblocks">charblocks</a> and <a href="#charscripts">charscripts</a> by using charinrange():</p>
<pre>
    <span class="keyword">use</span> <span class="variable">Unicode::UCD</span> <span class="string">qw(charscript charinrange)</span><span class="operator">;</span>
</pre>
<pre>
    <span class="variable">$range</span> <span class="operator">=</span> <span class="variable">charscript</span><span class="operator">(</span><span class="string">'Hiragana'</span><span class="operator">);</span>
    <span class="keyword">print</span> <span class="string">"looks like hiragana\n"</span> <span class="keyword">if</span> <span class="variable">charinrange</span><span class="operator">(</span><span class="variable">$range</span><span class="operator">,</span> <span class="variable">$codepoint</span><span class="operator">);</span>
</pre>
<p>
</p>
<h2><a name="compexcl">compexcl</a></h2>
<pre>
    <span class="keyword">use</span> <span class="variable">Unicode::UCD</span> <span class="string">'compexcl'</span><span class="operator">;</span>
</pre>
<pre>
    <span class="keyword">my</span> <span class="variable">$compexcl</span> <span class="operator">=</span> <span class="variable">compexcl</span><span class="operator">(</span><span class="string">"09dc"</span><span class="operator">);</span>
</pre>
<p>The <code>compexcl()</code> returns the composition exclusion (that is, if the
character should not be produced during a precomposition) of the 
character specified by a <strong>code point argument</strong>.</p>
<p>If there is a composition exclusion for the character, true is
returned.  Otherwise, false is returned.</p>
<p>
</p>
<h2><a name="casefold">casefold</a></h2>
<pre>
    <span class="keyword">use</span> <span class="variable">Unicode::UCD</span> <span class="string">'casefold'</span><span class="operator">;</span>
</pre>
<pre>
    <span class="keyword">my</span> <span class="variable">$casefold</span> <span class="operator">=</span> <span class="variable">casefold</span><span class="operator">(</span><span class="string">"00DF"</span><span class="operator">);</span>
</pre>
<p>The <code>casefold()</code> returns the locale-independent case folding of the
character specified by a <strong>code point argument</strong>.</p>
<p>If there is a case folding for that character, a reference to a hash
with the following fields is returned:</p>
<pre>
    key</pre>
<pre>
    code             code point with at least four hexdigits
    status           &quot;C&quot;, &quot;F&quot;, &quot;S&quot;, or &quot;I&quot;
    mapping          one or more codes separated by spaces</pre>
<p>The meaning of the <em>status</em> is as follows:</p>
<pre>
   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</pre>
<p>If there is no case folding for that character, <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> is returned.</p>
<p>For more information about case mappings see
<a href="http://www.unicode.org/unicode/reports/tr21/">http://www.unicode.org/unicode/reports/tr21/</a></p>
<p>
</p>
<h2><a name="casespec">casespec</a></h2>
<pre>
    <span class="keyword">use</span> <span class="variable">Unicode::UCD</span> <span class="string">'casespec'</span><span class="operator">;</span>
</pre>
<pre>
    <span class="keyword">my</span> <span class="variable">$casespec</span> <span class="operator">=</span> <span class="variable">casespec</span><span class="operator">(</span><span class="string">"FB00"</span><span class="operator">);</span>
</pre>
<p>The <code>casespec()</code> returns the potentially locale-dependent case mapping
of the character specified by a <strong>code point argument</strong>.  The mapping
may change the length of the string (which the basic Unicode case
mappings as returned by <code>charinfo()</code> never do).</p>
<p>If there is a case folding for that character, a reference to a hash
with the following fields is returned:</p>
<pre>
    key</pre>
<pre>
    code             code point with at least four hexdigits
    lower            lowercase
    title            titlecase
    upper            uppercase
    condition        condition list (may be undef)</pre>
<p>The <code>condition</code> is optional.  Where present, it consists of one or
more <em>locales</em> or <em>contexts</em>, 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.
Conditions preceded by &quot;NON_&quot; represent the negation of the condition.</p>
<p>Note that when there are multiple case folding definitions for a
single code point because of different locales, the value returned by
<code>casespec()</code> is a hash reference which has the locales as the keys and
hash references as described above as the values.</p>
<p>A <em>locale</em> is defined as a 2-letter ISO 3166 country code, possibly
followed by a &quot;_&quot; and a 2-letter ISO language code (possibly followed
by a &quot;_&quot; and a variant code).  You can find the lists of those codes,
see <a href="../../lib/Locale/Country.html">the Locale::Country manpage</a> and <a href="../../lib/Locale/Language.html">the Locale::Language manpage</a>.</p>
<p>A <em>context</em> is one of the following choices:</p>
<pre>
    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 &quot;i&quot; (U+0069)</pre>
<p>For more information about case mappings see
<a href="http://www.unicode.org/unicode/reports/tr21/">http://www.unicode.org/unicode/reports/tr21/</a></p>
<p>
</p>
<h2><a name="namedseq__"><code>namedseq()</code></a></h2>
<pre>
    <span class="keyword">use</span> <span class="variable">Unicode::UCD</span> <span class="string">'namedseq'</span><span class="operator">;</span>
</pre>
<pre>
    <span class="keyword">my</span> <span class="variable">$namedseq</span> <span class="operator">=</span> <span class="variable">namedseq</span><span class="operator">(</span><span class="string">"KATAKANA LETTER AINU P"</span><span class="operator">);</span>
    <span class="keyword">my</span> <span class="variable">@namedseq</span> <span class="operator">=</span> <span class="variable">namedseq</span><span class="operator">(</span><span class="string">"KATAKANA LETTER AINU P"</span><span class="operator">);</span>
    <span class="keyword">my</span> <span class="variable">%namedseq</span> <span class="operator">=</span> <span class="variable">namedseq</span><span class="operator">();</span>
</pre>
<p>If used with a single argument in a scalar context, returns the string
consisting of the code points of the named sequence, or <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> 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
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 <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a> or empty list depending
on the context.</p>
<p>(New from Unicode 4.1.0)</p>
<p>
</p>
<h2><a name="unicode__ucd__unicodeversion">Unicode::UCD::UnicodeVersion</a></h2>
<p>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 (<code>'.'</code>).</p>
<p>
</p>
<h2><a name="implementation_note">Implementation Note</a></h2>
<p>The first use of <code>charinfo()</code> opens a read-only filehandle to the Unicode
Character Database (the database is included in the Perl distribution).
The filehandle is then kept open for further queries.  In other words,
if you are wondering where one of your filehandles went, that's where.</p>
<p>
</p>
<hr />
<h1><a name="bugs">BUGS</a></h1>
<p>Does not yet support EBCDIC platforms.</p>
<p>
</p>
<hr />
<h1><a name="author">AUTHOR</a></h1>
<p>Jarkko Hietaniemi</p>

</body>

</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?