perlunicode.html
来自「perl教程」· HTML 代码 · 共 1,163 行 · 第 1/5 页
HTML
1,163 行
<p>For more about blocks, see:</p>
<pre>
<a href="http://www.unicode.org/Public/UNIDATA/Blocks.txt">http://www.unicode.org/Public/UNIDATA/Blocks.txt</a></pre>
<p>Block names are given with the <code>In</code> prefix. For example, the
Katakana block is referenced via <code>\p{InKatakana}</code>. The <code>In</code>
prefix may be omitted if there is no naming conflict with a script
or any other property, but it is recommended that <code>In</code> always be used
for block tests to avoid confusion.</p>
<p>These block names are supported:</p>
<pre>
InAlphabeticPresentationForms
InArabic
InArabicPresentationFormsA
InArabicPresentationFormsB
InArmenian
InArrows
InBasicLatin
InBengali
InBlockElements
InBopomofo
InBopomofoExtended
InBoxDrawing
InBraillePatterns
InBuhid
InByzantineMusicalSymbols
InCJKCompatibility
InCJKCompatibilityForms
InCJKCompatibilityIdeographs
InCJKCompatibilityIdeographsSupplement
InCJKRadicalsSupplement
InCJKSymbolsAndPunctuation
InCJKUnifiedIdeographs
InCJKUnifiedIdeographsExtensionA
InCJKUnifiedIdeographsExtensionB
InCherokee
InCombiningDiacriticalMarks
InCombiningDiacriticalMarksforSymbols
InCombiningHalfMarks
InControlPictures
InCurrencySymbols
InCyrillic
InCyrillicSupplementary
InDeseret
InDevanagari
InDingbats
InEnclosedAlphanumerics
InEnclosedCJKLettersAndMonths
InEthiopic
InGeneralPunctuation
InGeometricShapes
InGeorgian
InGothic
InGreekExtended
InGreekAndCoptic
InGujarati
InGurmukhi
InHalfwidthAndFullwidthForms
InHangulCompatibilityJamo
InHangulJamo
InHangulSyllables
InHanunoo
InHebrew
InHighPrivateUseSurrogates
InHighSurrogates
InHiragana
InIPAExtensions
InIdeographicDescriptionCharacters
InKanbun
InKangxiRadicals
InKannada
InKatakana
InKatakanaPhoneticExtensions
InKhmer
InLao
InLatin1Supplement
InLatinExtendedA
InLatinExtendedAdditional
InLatinExtendedB
InLetterlikeSymbols
InLowSurrogates
InMalayalam
InMathematicalAlphanumericSymbols
InMathematicalOperators
InMiscellaneousMathematicalSymbolsA
InMiscellaneousMathematicalSymbolsB
InMiscellaneousSymbols
InMiscellaneousTechnical
InMongolian
InMusicalSymbols
InMyanmar
InNumberForms
InOgham
InOldItalic
InOpticalCharacterRecognition
InOriya
InPrivateUseArea
InRunic
InSinhala
InSmallFormVariants
InSpacingModifierLetters
InSpecials
InSuperscriptsAndSubscripts
InSupplementalArrowsA
InSupplementalArrowsB
InSupplementalMathematicalOperators
InSupplementaryPrivateUseAreaA
InSupplementaryPrivateUseAreaB
InSyriac
InTagalog
InTagbanwa
InTags
InTamil
InTelugu
InThaana
InThai
InTibetan
InUnifiedCanadianAboriginalSyllabics
InVariationSelectors
InYiRadicals
InYiSyllables</pre>
<ul>
<li>
<p>The special pattern <code>\X</code> matches any extended Unicode
sequence--"a combining character sequence" in Standardese--where the
first character is a base character and subsequent characters are mark
characters that apply to the base character. <code>\X</code> is equivalent to
<code>(?:\PM\pM*)</code>.</p>
</li>
<li>
<p>The <a href="../../lib/Pod/perlfunc.html#item_tr_"><code>tr///</code></a> operator translates characters instead of bytes. Note
that the <a href="../../lib/Pod/perlfunc.html#item_tr_"><code>tr///CU</code></a> functionality has been removed. For similar
functionality see pack('U0', ...) and pack('C0', ...).</p>
</li>
<li>
<p>Case translation operators use the Unicode case translation tables
when character input is provided. Note that <a href="../../lib/Pod/perlfunc.html#item_uc"><code>uc()</code></a>, or <code>\U</code> in
interpolated strings, translates to uppercase, while <a href="../../lib/Pod/perlfunc.html#item_ucfirst"><code>ucfirst</code></a>,
or <code>\u</code> in interpolated strings, translates to titlecase in languages
that make the distinction.</p>
</li>
<li>
<p>Most operators that deal with positions or lengths in a string will
automatically switch to using character positions, including
<a href="../../lib/Pod/perlfunc.html#item_chop"><code>chop()</code></a>, <a href="../../lib/Pod/perlfunc.html#item_chomp"><code>chomp()</code></a>, <a href="../../lib/Pod/perlvar.html#item_substr"><code>substr()</code></a>, <a href="../../lib/Pod/perlfunc.html#item_pos"><code>pos()</code></a>, <a href="../../lib/Pod/perlfunc.html#item_index"><code>index()</code></a>, <a href="../../lib/Pod/perlfunc.html#item_rindex"><code>rindex()</code></a>,
<a href="../../lib/Pod/perlfunc.html#item_sprintf"><code>sprintf()</code></a>, <a href="../../lib/Pod/perlfunc.html#item_write"><code>write()</code></a>, and <a href="../../lib/Pod/perlfunc.html#item_length"><code>length()</code></a>. Operators that
specifically do not switch include <a href="../../lib/Pod/perlfunc.html#item_vec"><code>vec()</code></a>, <a href="../../lib/Pod/perlfunc.html#item_pack"><code>pack()</code></a>, and
<a href="../../lib/Pod/perlfunc.html#item_unpack"><code>unpack()</code></a>. Operators that really don't care include
operators that treats strings as a bucket of bits such as <a href="../../lib/Pod/perlfunc.html#item_sort"><code>sort()</code></a>,
and operators dealing with filenames.</p>
</li>
<li>
<p>The <a href="../../lib/Pod/perlfunc.html#item_pack"><code>pack()</code></a>/<a href="../../lib/Pod/perlfunc.html#item_unpack"><code>unpack()</code></a> letters <code>c</code> and <code>C</code> do <em>not</em> change,
since they are often used for byte-oriented formats. Again, think
<code>char</code> in the C language.</p>
<p>There is a new <code>U</code> specifier that converts between Unicode characters
and code points.</p>
</li>
<li>
<p>The <a href="../../lib/Pod/perlfunc.html#item_chr"><code>chr()</code></a> and <a href="../../lib/Pod/perlfunc.html#item_ord"><code>ord()</code></a> functions work on characters, similar to
<a href="../../lib/Pod/perlfunc.html#item_pack"><code>pack("U")</code></a> and <a href="../../lib/Pod/perlfunc.html#item_unpack"><code>unpack("U")</code></a>, <em>not</em> <a href="../../lib/Pod/perlfunc.html#item_pack"><code>pack("C")</code></a> and
<a href="../../lib/Pod/perlfunc.html#item_unpack"><code>unpack("C")</code></a>. <a href="../../lib/Pod/perlfunc.html#item_pack"><code>pack("C")</code></a> and <a href="../../lib/Pod/perlfunc.html#item_unpack"><code>unpack("C")</code></a> are methods for
emulating byte-oriented <a href="../../lib/Pod/perlfunc.html#item_chr"><code>chr()</code></a> and <a href="../../lib/Pod/perlfunc.html#item_ord"><code>ord()</code></a> on Unicode strings.
While these methods reveal the internal encoding of Unicode strings,
that is not something one normally needs to care about at all.</p>
</li>
<li>
<p>The bit string operators, <code>& | ^ ~</code>, can operate on character data.
However, for backward compatibility, such as when using bit string
operations when characters are all less than 256 in ordinal value, one
should not use <code>~</code> (the bit complement) with characters of both
values less than 256 and values greater than 256. Most importantly,
DeMorgan's laws (<code>~($x|$y) eq ~$x&~$y</code> and <code>~($x&$y) eq ~$x|~$y</code>)
will not hold. The reason for this mathematical <em>faux pas</em> is that
the complement cannot return <strong>both</strong> the 8-bit (byte-wide) bit
complement <strong>and</strong> the full character-wide bit complement.</p>
</li>
<li>
<p>lc(), uc(), lcfirst(), and <a href="../../lib/Pod/perlfunc.html#item_ucfirst"><code>ucfirst()</code></a> work for the following cases:</p>
<ul>
<li>
<p>the case mapping is from a single Unicode character to another
single Unicode character, or</p>
</li>
<li>
<p>the case mapping is from a single Unicode character to more
than one Unicode character.</p>
</li>
</ul>
<p>Things to do with locales (Lithuanian, Turkish, Azeri) do <strong>not</strong> work
since Perl does not understand the concept of Unicode locales.</p>
<p>See the Unicode Technical Report #21, Case Mappings, for more details.</p>
</ul>
<ul>
<li>
<p>And finally, <a href="../../lib/Pod/perlfunc.html#item_reverse"><code>scalar reverse()</code></a> reverses by character rather than by byte.</p>
</li>
</ul>
<p>
</p>
<h2><a name="userdefined_character_properties">User-Defined Character Properties</a></h2>
<p>You can define your own character properties by defining subroutines
whose names begin with "In" or "Is". The subroutines can be defined in
any package. The user-defined properties can be used in the regular
expression <code>\p</code> and <code>\P</code> constructs; if you are using a user-defined
property from a package other than the one you are in, you must specify
its package in the <code>\p</code> or <code>\P</code> construct.</p>
<pre>
<span class="comment"># assuming property IsForeign defined in Lang::</span>
<span class="keyword">package</span> <span class="variable">main</span><span class="operator">;</span> <span class="comment"># property package name required</span>
<span class="keyword">if</span> <span class="operator">(</span><span class="variable">$txt</span> <span class="operator">=~</span> <span class="regex">/\p{Lang::IsForeign}+/</span><span class="operator">)</span> <span class="operator">{</span> <span class="operator">...</span> <span class="operator">}</span>
</pre>
<pre>
<span class="keyword">package</span> <span class="variable">Lang</span><span class="operator">;</span> <span class="comment"># property package name not required</span>
<span class="keyword">if</span> <span class="operator">(</span><span class="variable">$txt</span> <span class="operator">=~</span> <span class="regex">/\p{IsForeign}+/</span><span class="operator">)</span> <span class="operator">{</span> <span class="operator">...</span> <span class="operator">}</span>
</pre>
<p>Note that the effect is compile-time and immutable once defined.</p>
<p>The subroutines must return a specially-formatted string, with one
or more newline-separated lines. Each line must be one of the following:</p>
<ul>
<li>
<p>Two hexadecimal numbers separated by horizontal whitespace (space or
tabular characters) denoting a range of Unicode code points to include.</p>
</li>
<li>
<p>Something to include, prefixed by "+": a built-in character
property (prefixed by "utf8::") or a user-defined character property,
to represent all the characters in that property; two hexadecimal code
points for a range; or a single hexadecimal code point.</p>
</li>
<li>
<p>Something to exclude, prefixed by "-": an existing character
property (prefixed by "utf8::") or a user-defined character property,
to represent all the characters in that property; two hexadecimal code
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?