perlunicode > 5.36.0 との差分

perlunicode 5.36.0 と 5.10.0 の差分

11
2=encoding utf8
2=encoding euc-jp
33
44=head1 NAME
55
66=begin original
77
88perlunicode - Unicode support in Perl
99
1010=end original
1111
1212perlunicode - Perl における Unicode サポート
1313
1414=head1 DESCRIPTION
1515
16=begin original
17
18If you haven't already, before reading this document, you should become
19familiar with both L<perlunitut> and L<perluniintro>.
20
21=end original
22
23もしまだなら、この文書を読む前に、L<perlunitut> と L<perluniintro> に
24親しんでおく方が良いでしょう。
25
26=begin original
27
28Unicode aims to B<UNI>-fy the en-B<CODE>-ings of all the world's
29character sets into a single Standard. For quite a few of the various
30coding standards that existed when Unicode was first created, converting
31from each to Unicode essentially meant adding a constant to each code
32point in the original standard, and converting back meant just
33subtracting that same constant. For ASCII and ISO-8859-1, the constant
34is 0. For ISO-8859-5, (Cyrillic) the constant is 864; for Hebrew
35(ISO-8859-8), it's 1488; Thai (ISO-8859-11), 3424; and so forth. This
36made it easy to do the conversions, and facilitated the adoption of
37Unicode.
38
39=end original
40
41Unicode は世界中の全ての文字集合のエンコーディング(en-B<CODE>-ings) を
42一つの標準に統合(B<UNI>-fy)することを目標としています。
43Unicode が最初に作られたといに存在していたいくつかの符号標準に
44ついては、それぞれから Unicode への変換は、元の標準のそれぞれの符号位置に
45ある定数を足すことで、
46逆変換は単に同じ定数を引くことでした。
47ASCII と ISO-8859-1 では、定数は 0 です。
48ISO-8859-5 (キリル文字) では、定数は 864 です;
49ヘブライ文字 (ISO-8859-8) では、これは 1488 です;
50タイ (ISO-8859-11) は 3424、などです。
51これは変換を容易にし、Unicode の採用を促進しました。
52
53=begin original
54
55And it worked; nowadays, those legacy standards are rarely used. Most
56everyone uses Unicode.
57
58=end original
59
60そしてこれはうまくいきました; 最近は、これらの昔の標準はめったに使われません。
61ほとんどみんなが Unicode を使います。
62
63=begin original
64
65Unicode is a comprehensive standard. It specifies many things outside
66the scope of Perl, such as how to display sequences of characters. For
67a full discussion of all aspects of Unicode, see
68L<https://www.unicode.org>.
69
70=end original
71
72Unicode は包括的な標準です。
73これは、文字の並びをどのように表示するかといった、Perl のスコープの
74範囲外の多くのことを規定します。
75Unicode のあらゆる側面に関する完全な議論については、
76L<https://www.unicode.org> を参照してください。
77
7816=head2 Important Caveats
7917
8018(重要な警告)
8119
8220=begin original
8321
84Even though some of this section may not be understandable to you on
85first reading, we think it's important enough to highlight some of the
86gotchas before delving further, so here goes:
87
88=end original
89
90この節の一部は最初に読んだときには理解できないかもしれませんが、
91さらに掘り下げる前にいくつかの癖について強調することは重要だと考えたので、
92ここで行います:
93
94=begin original
95
9622Unicode support is an extensive requirement. While Perl does not
9723implement the Unicode standard or the accompanying technical reports
9824from cover to cover, Perl does support many Unicode features.
9925
10026=end original
10127
102Unicode サポートは大規模な要求です。
28Uncode サポートは大規模な要求です。
10329Perl は標準 Unicode や付随する技術的なレポートを一つ残らず
10430実装しているわけではありませんが、多くの Unicode 機能を
10531サポートしています。
10632
10733=begin original
10834
109Also, the use of Unicode may present security issues that aren't
35People who want to learn to use Unicode in Perl, should probably read
110obvious, see L</Security Implications of Unicode> below.
36L<the Perl Unicode tutorial|perlunitut> before reading this reference
37document.
11138
11239=end original
11340
114また、Unicode を使うと、明らかではなセキュティ問題が姿現すかも
41Perl で Unicode を使うを学びた人は、多分このファレンス読む前に
115知れませ;
42L<the Perl Unicode tutorial|perlunitut> を読だ方がよいでしょう。
116後述の L</Security Implications of Unicode> を参照してください。
11743
11844=over 4
11945
120=item Safest if you C<use feature 'unicode_strings'>
46=item Input and Output Layers
12147
122(C<use feature 'unicode_strings'> とすれば一番安全)
48(入出力層)
12349
12450=begin original
12551
126In order to preserve backward compatibility, Perl does not turn
52Perl knows when a filehandle uses Perl's internal Unicode encodings
127on full internal Unicode support unless the pragma
53(UTF-8, or UTF-EBCDIC if in EBCDIC) if the filehandle is opened with
128L<S<C<use feature 'unicode_strings'>>|feature/The 'unicode_strings' feature>
54the ":utf8" layer. Other encodings can be converted to Perl's
129is specified. (This is automatically
55encoding on input or from Perl's encoding on output by use of the
130selected if you S<C<use v5.12>> or higher.) Failure to do this can
56":encoding(...)" layer. See L<open>.
131trigger unexpected surprises. See L</The "Unicode Bug"> below.
13257
13358=end original
13459
135後方互換性を維持するために、Perl は
60Perl は、ファイルハンドルが ":utf8" 層を指定してオープンされると、
136L<S<C<use feature 'unicode_strings'>>|feature/The 'unicode_strings' feature> プラマが指定されない限り
61ファイルハンドルが Perl の内部 Unicode エンコーディン
137完全な内部 Unicode 対応オンにしせん
62(UTF-8, または EBCDIC の時は UTF-EBCDIC)使うことが分かり
138(これ S<C<use v5.12>> 以上を使うと自動的に選択されます。)
63その他のエンコーディング、":encoding(...)" を使うで、
139こうするに失敗すると予測できない驚きを引き起こすかも知れません。
64入力時 Perl のエンコーディングへの変換や出力時の Perl の
140後述する L</The "Unicode Bug"> 参照してください
65エンコーディングからの変換行えます
66L<open> を参照してください。
14167
14268=begin original
14369
144This pragma doesn't affect I/O. Nor does it change the internal
70To indicate that Perl source itself is in UTF-8, use C<use utf8;>.
145representation of strings, only their interpretation. There are still
146several places where Unicode isn't fully supported, such as in
147filenames.
14871
14972=end original
15073
151プラグマは I/O には影響しません。
74Perl ソース自身が UTF-8 であることを示すには、C<use utf8;> を
152また、文字列の内部表現も変更しません; その解釈けです
75使ってくさい
153ファイル名のように Unicode に完全に対応していない場所がいくつかあります。
15476
155=item Input and Output Layers
77=item Regular Expressions
15678
157(入出力層)
79(正規表現)
15880
15981=begin original
16082
161Use the C<:encoding(...)> layer to read from and write to
83The regular expression compiler produces polymorphic opcodes. That is,
162filehandles using the specified encoding. (See L<open>.)
84the pattern adapts to the data and automatically switches to the Unicode
85character scheme when presented with data that is internally encoded in
86UTF-8 -- or instead uses a traditional byte scheme when presented with
87byte data.
16388
16489=end original
16590
166特定のエンーディグを使ってファルハンルと読み書きるには、
91正規表現コンラは多態的なオペコーを生成しま
167C<:encoding(...)> 層を使っくだい。
92つまり、パターンはデータに対し適用れ、データが内部で UTF-8 で
168(L<open> を参照してください。)
93エンコードされている場合には Unicode 文字スキームに自動的に
94切り替わります -- さもなければ、バイトデータで表されている場合には
95伝統的なバイトスキームが使われます。
16996
170=item You must convert your non-ASCII, non-UTF-8 Perl scripts to be
97=item C<use utf8> still needed to enable UTF-8/UTF-EBCDIC in scripts
171UTF-8.
17298
173(非 ASCII、非 UTF-8 Perl スクリプトは UTF-8 に変換しなければなりません)
174
17599=begin original
176100
177The L<encoding> module has been deprecated since perl 5.18 and the
101As a compatibility measure, the C<use utf8> pragma must be explicitly
178perl internals it requires have been removed with perl 5.26.
102included to enable recognition of UTF-8 in the Perl scripts themselves
103(in string or regular expression literals, or in identifier names) on
104ASCII-based machines or to recognize UTF-EBCDIC on EBCDIC-based
105machines. B<These are the only times when an explicit C<use utf8>
106is needed.> See L<utf8>.
179107
180108=end original
181109
182L<encoding> モジュルは perl 5.18 から廃止予定で、
110互換性のために、ASCII スのマシンにおいて Perl スクリプトそれ自身の
183これが要求している perl 内部は perl 5.26 削除されました。
111UTF-8 を(文字列や正規表現リテラル、あるいは変数名) 認識可能に
112するためや、EBCDIC ベースのマシンで UTF-EBCDIC を認識させるために
113C<use utf8> プラグマを明示的に含めなければなりません。
114B<これらは明示的に C<use utf8> が必要な唯一の場合です。>
115L<utf8> を参照してください。
184116
185=item C<use utf8> still needed to enable L<UTF-8|/Unicode Encodings> in scripts
117=item BOM-marked scripts and UTF-16 scripts autodetected
186118
187(スクリプト内で L<UTF-8|/Unicode Encodings> を有効にするには、まだ C<use utf8> が必要です)
188
189119=begin original
190120
191If your Perl script is itself encoded in L<UTF-8|/Unicode Encodings>,
121If a Perl script begins marked with the Unicode BOM (UTF-16LE, UTF16-BE,
192the S<C<use utf8>> pragma must be explicitly included to enable
122or UTF-8), or if the script looks like non-BOM-marked UTF-16 of either
193recognition of that (in string or regular expression literals, or in
123endianness, Perl will correctly read in the script as Unicode.
194identifier names). B<This is the only time when an explicit S<C<use
124(BOMless UTF-8 cannot be effectively recognized or differentiated from
195utf8>> is needed.> (See L<utf8>).
125ISO 8859-1 or other eight-bit encodings.)
196126
197127=end original
198128
199Perl スクリプト自身が L<UTF-8|/Unicode Encodings>
129Unicode BOM (UTF-16LE, UTF16-BE, またはUTF-8) Perl スクリプトが
200エンコードされている場合Perl スクリプトそれ自身の
130始まっていたり、スクリプトが BOM がついていない
201中を(文字列や正規表現リテラル、あるは変数名で) 認識可能に
131UTF-16(BE か LE のずれか) であった場合、Perl はそのスクリプトを
202するために、C<use utf8> プラグマを明示的に含めければなりません。
132Unicode であるとして正しく読み込みます(BOM い UTF-8 は、
203B<これは明示的に C<use utf8> が必要唯一場合です。>
133効率的に ISO 8859-1 8 ビットエンコーディングと区別したり
204(L<utf8> を参照してください。)
134認識することができません。)
205135
136=item C<use encoding> needed to upgrade non-Latin-1 byte strings
137
206138=begin original
207139
208If a Perl script begins with the bytes that form the UTF-8 encoding of
140By default, there is a fundamental asymmetry in Perl's Unicode model:
209the Unicode BYTE ORDER MARK (C<BOM>, see L</Unicode Encodings>), those
141implicit upgrading from byte strings to Unicode strings assumes that
210bytes are completely ignored.
142they were encoded in I<ISO 8859-1 (Latin-1)>, but Unicode strings are
143downgraded with UTF-8 encoding. This happens because the first 256
144codepoints in Unicode happens to agree with Latin-1.
211145
212146=end original
213147
214Perl スクリプトが Unicode のバイト順マーク
148デフォルトでは、Perl Unicode モデルにおける基本的な非対称があります:
215(BYTE ORDER MARK, C<BOM>, L</Unicode Encodings> 参照) UTF-8
149バイト文字列から Unicode 文字列へ暗黙の昇格はその文字列が
216エンコーディングを示すバイト列で始まっている場合
150I<ISO 8859-1 (Latin-1)> でエンコードされているものと仮定しますが
217これらのバイト列完全に無視されます。
151Unicode 文字列からのダウングレード
152UTF-8 エンコーディングへと行われます。
153これは Unicode の最初の 256 文字が Latin-1 と共通であるからです。
218154
219=item L<UTF-16|/Unicode Encodings> scripts autodetected
220
221(L<UTF-16|/Unicode Encodings> スクリプトは自動認識されます)
222
223155=begin original
224156
225If a Perl script begins with the Unicode C<BOM> (UTF-16LE,
157See L</"Byte and Character Semantics"> for more details.
226UTF16-BE), or if the script looks like non-C<BOM>-marked
227UTF-16 of either endianness, Perl will correctly read in the script as
228the appropriate Unicode encoding.
229158
230159=end original
231160
232しかし、Unicode C<BOM> (UTF-16LE, UTF16-BE)で Perl スクリプトが
161詳細は L</"Byte and Character Semantics"> を参照してください。
233始まっていたり、スクリプトが C<BOM> がついていない
234UTF-16(BE か LE のいずれか) であった場合、Perl はそのスクリプトを
235適切な Unicode エンコーディングとして正しく読み込みます。
236162
237163=back
238164
239165=head2 Byte and Character Semantics
240166
241167(バイトと文字のセマンティクス)
242168
243169=begin original
244170
245Before Unicode, most encodings used 8 bits (a single byte) to encode
171Beginning with version 5.6, Perl uses logically-wide characters to
246each character. Thus a character was a byte, and a byte was a
172represent strings internally.
247character, and there could be only 256 or fewer possible characters.
248"Byte Semantics" in the title of this section refers to
249this behavior. There was no need to distinguish between "Byte" and
250"Character".
251173
252174=end original
253175
254Unicode 以前、ほとんどのエンコディそれぞれの文字のエンコードに
176ジョ 5.6 から、Perl 論理的なワイド文字を内部的な文字列
2558 ビット (1 バイト) を使っていました
177表現のために使っていま
256従って文字はバイトであり、バイトは文字であり、可能な文字は 256 文字
257以下でした。
258この章のタイトルである「バイトのセマンティクス」は、この振る舞いを
259示しています。
260「バイト」と「文字」を区別する必要はありませんでした。
261178
262179=begin original
263180
264Then along comes Unicode which has room for over a million characters
181In future, Perl-level operations will be expected to work with
265(and Perl allows for even more). This means that a character may
182characters rather than bytes.
266require more than a single byte to represent it, and so the two terms
267are no longer equivalent. What matter are the characters as whole
268entities, and not usually the bytes that comprise them. That's what the
269term "Character Semantics" in the title of this section refers to.
270183
271184=end original
272185
273それから100 万文字以上を扱える (そして Perl はもっ扱え) Unicode が
186将来は、Perl レベルの操作バイトではなく文字に対して働くこになでしょう。
274登場します。
275これは、一つの文字を表現するのに複数バイトが必要になる場合があり、
276二つの用語はもはや等価ではないということを意味します。
277問題となるのはエンティティ全体としての文字であり、通常はそれを構成する
278バイトではありません。
279これが、この章のタイトルにある「文字セマンティクス」が指しているものです。
280187
281188=begin original
282189
283Perl had to change internally to decouple "bytes" from "characters".
190However, as an interim compatibility measure, Perl aims to
284It is important that you too change your ideas, if you haven't already,
191provide a safe migration path from byte semantics to character
285so that "byte" and "character" no longer mean the same thing in your
192semantics for programs. For operations where Perl can unambiguously
286mind.
193decide that the input data are characters, Perl switches to
194character semantics. For operations where this determination cannot
195be made without additional information from the user, Perl decides in
196favor of compatibility and chooses to use byte semantics.
287197
288198=end original
289199
290Perl は、「バイト」と「文字」から切り離すために内部を変更する
200しかしながら、一時的な互換性の措置として、Perl は
291必要がありました。
201プログラムに対するバイトセマンティクスから文字セマンティクスへの
292たの頭の中で「バイト」「文字」はもはや同じもの
202安全移行パスを提供することを目指します。
293意味しないように、(もしまだなら)考え方を変えとが重要す。
203入力データが文字であると Perl 曖昧さなく決定きる操作については、
204Perl は文字セマンティクスに切り替えます。
205ユーザーからの付加的な情報抜きに決定することができない操作については
206Perl は互換性の観点からバイトセマンティクスを選択します。
294207
295208=begin original
296209
297The basic building block of Perl strings has always been a "character".
210This behavior preserves compatibility with earlier versions of Perl,
298The changes basically come down to that the implementation no longer
211which allowed byte semantics in Perl operations only if
299thinks that a character is always just a single byte.
212none of the program's inputs were marked as being as source of Unicode
213character data. Such data may come from filehandles, from calls to
214external programs, from information provided by the system (such as %ENV),
215or from literals and constants in the source text.
300216
301217=end original
302218
303Perl の文字列基礎要素は常に「文字」でた。
219この動作は Perl の以前バージョンとの互換性を維持、プログラムの
304変更は基本的に、実装はもはや文字常に 1 バイトであると
220入力Unicode の文字データのソースであるとマークされていない場合にのみ
305考えないということです。
221Perl の操作バイトセマンティクスを許可します。
222そのようなデータは、ファイルハンドル、外部プログラムの呼び出し、
223システムから提供される情報(%ENV のような)、ソーステキスト中のリテラルや
224定数といったものからくるものです。
306225
307226=begin original
308227
309There are various things to note:
228The C<bytes> pragma will always, regardless of platform, force byte
229semantics in a particular lexical scope. See L<bytes>.
310230
311231=end original
312232
313記しておくべき様々なこがあります:
233C<bytes> プラグマは常に、プラットフォームは無関係に、特定の
234レキシカルスコープにおいてバイトセマンティクスを強制します。
235L<bytes> を参照してください。
314236
315=over 4
316
317=item *
318
319237=begin original
320238
321String handling functions, for the most part, continue to operate in
239The C<utf8> pragma is primarily a compatibility device that enables
322terms of characters. C<length()>, for example, returns the number of
240recognition of UTF-(8|EBCDIC) in literals encountered by the parser.
323characters in a string, just as before. But that number no longer is
241Note that this pragma is only required while Perl defaults to byte
324necessarily the same as the number of bytes in the string (there may be
242semantics; when character semantics become the default, this pragma
325more bytes than characters). The other such functions include
243may become a no-op. See L<utf8>.
326C<chop()>, C<chomp()>, C<substr()>, C<pos()>, C<index()>, C<rindex()>,
327C<sort()>, C<sprintf()>, and C<write()>.
328244
329245=end original
330246
331文字列処理関数、ほんどの場合、引き続き文字に関して動作しま
247C<utf8> プラグマとしてパーサが遭遇るリテラル中の UTF-(8|EBCDIC) の
332たとえば C<length()> は、以前と同じように文字列内の文字の数を返します。
248認識を有効にする互換デバイス(compatibility device)です。
333しかし、そもはや文字列内のバイト数と常に同じりません
249プラグマ Perl デフォルトがバイトセマンティクスであるときにのみ
334(文字数よりもバイト数が多い場合がります)
250必要でることに注意してください
335その他のそのような関数には、
251文字セマンティクスがデフォルトである場合には、
336C<chop()>, C<chomp()>, C<substr()>, C<pos()>, C<index()>, C<rindex()>,
252このプラグマは何もしません。
337C<sort()>, C<sprintf()>, and C<write()> があります
253L<utf8> を参照してください
338254
339255=begin original
340256
341The exceptions are:
257Unless explicitly stated, Perl operators use character semantics
258for Unicode data and byte semantics for non-Unicode data.
259The decision to use character semantics is made transparently. If
260input data comes from a Unicode source--for example, if a character
261encoding layer is added to a filehandle or a literal Unicode
262string constant appears in a program--character semantics apply.
263Otherwise, byte semantics are in effect. The C<bytes> pragma should
264be used to force byte semantics on Unicode data.
342265
343266=end original
344267
345例外:
268明示的に指定されない限り、Perl の演算子 Unicode データに対しては
269文字セマンティクスを用い、非 Unicode データに対しては
270バイトセマンティクスを用います。
271文字セマンティクスの使用の決定はトランスペアレントに行われます。
272もし入力データが Unicode ソースから来たもの -- たとえば、
273文字エンコーディング層がファイルハンドルに附加されているか
274リテラルの Unicode 文字列定数がプログラムの中にある -- のであれば
275文字セマンティクスが適用されます。
276そうでなければ、バイトセマンティクスが有効になります。
277C<bytes> プラグマは Unicode データに対してバイトセマンティクスを
278強制するときに使うと良いでしょう。
346279
347=over 4
348
349=item *
350
351280=begin original
352281
353the bit-oriented C<vec>
282If strings operating under byte semantics and strings with Unicode
283character data are concatenated, the new string will be created by
284decoding the byte strings as I<ISO 8859-1 (Latin-1)>, even if the
285old Unicode string used EBCDIC. This translation is done without
286regard to the system's native 8-bit encoding.
354287
355288=end original
356289
357ビッ単位 C<vec>
290バイセマンティクス元での文字列の操作で、Unicode 文字データが
291連結された文字列であった場合、新たな文字列は、古い Unicode 文字列が
292EBCDIC を使っていたとしても、バイト文字列を I<ISO 8859-1 (Latin-1)> として
293デコードすることで作成されます。
294この変換はシステムのネイティブな 8 ビットエンコーディングとは
295無関係に行われます。
358296
359E<nbsp>
360
361=item *
362
363297=begin original
364298
365the byte-oriented C<pack>/C<unpack> C<"C"> format
299Under character semantics, many operations that formerly operated on
300bytes now operate on characters. A character in Perl is
301logically just a number ranging from 0 to 2**31 or so. Larger
302characters may encode into longer sequences of bytes internally, but
303this internal detail is mostly hidden for Perl code.
304See L<perluniintro> for more.
366305
367306=end original
368307
369バイト単位 C<pack>/C<unpack> C<"C"> フォーマット
308文字セマンティクスの元では、伝統的にバイトに対して働いていた操作多くが
309文字に対して働きます。
310Perl における文字は論理的には 0 から 2**31 までの範囲の数値です。
311大きな文字は内部的にはより長いシーケンスにエンコードされる可能性が
312ありますが、この内部の詳細は Perl プログラムからほとんど隠されています。
313詳細は L<perluniintro> を参照してください。
370314
371=begin original
315=head2 Effects of Character Semantics
372316
373However, the C<W> specifier does operate on whole characters, as does the
317(文字セマンティクスの効果)
374C<U> specifier.
375318
376=end original
377
378しかし、C<W> 指示子は C<U> 指示子と同様、文字全体を操作します。
379
380=item *
381
382319=begin original
383320
384some operators that interact with the platform's operating system
321Character semantics have the following effects:
385322
386323=end original
387324
388プラットフォームのオペレーティングシテムと相互作用する一部演算子
325文字セマンティは以下効果を持っています:
389326
390=begin original
327=over 4
391328
392Operators dealing with filenames are examples.
393
394=end original
395
396例としてはファイル名を扱う演算子です。
397
398329=item *
399330
400331=begin original
401332
402when the functions are called from within the scope of the
403S<C<L<use bytes|bytes>>> pragma
404
405=end original
406
407関数が S<C<L<use bytes|bytes>>> プラグマのスコープ内から呼び出された場合
408
409=begin original
410
411Likely, you should use this only for debugging anyway.
412
413=end original
414
415おそらく、これはデバッグのためだけに行うべきです。
416
417=back
418
419=item *
420
421=begin original
422
423333Strings--including hash keys--and regular expression patterns may
424contain characters that have ordinal values larger than 255.
334contain characters that have an ordinal value larger than 255.
425335
426336=end original
427337
428338文字列 -- ハッシュのキーを含め -- と正規表現パターンは序数値として 255 を
429339超える値を持つ文字を含めることができます。
430340
431341=begin original
432342
433343If you use a Unicode editor to edit your program, Unicode characters may
434344occur directly within the literal strings in UTF-8 encoding, or UTF-16.
435(The former requires a C<use utf8>, the latter may require a C<BOM>.)
345(The former requires a BOM or C<use utf8>, the latter requires a BOM.)
436346
437347=end original
438348
349
439350プログラムを編集するのに Unicode エディタを使っているのであれば、Unicode の
440351文字 UTF-8 か UTF-16 のエンコーディングコーディングでリテラル文字列に
441352含めることができます。
442(前者は C<use utf8> を必要とし、後者は C<BOM> を必要とするかもせん。)
353(前者は BOM か C<use utf8> を必要とし、後者は BOM を必要としま。)
443354
444355=begin original
445356
446L<perluniintro/Creating Unicode> gives other ways to place non-ASCII
357Unicode characters can also be added to a string by using the C<\x{...}>
447characters in your strings.
358notation. The Unicode code for the desired character, in hexadecimal,
359should be placed in the braces. For instance, a smiley face is
360C<\x{263A}>. This encoding scheme only works for all characters, but
361for characters under 0x100, note that Perl may use an 8 bit encoding
362internally, for optimization and/or backward compatibility.
448363
449364=end original
450365
451L<perluniintro/Creating Unicode> は、文字列に非 ASCII 文字を置くための
366Unicode 文字 C<\x{...}> 表記を使うことにより文字列に
452その他の方法を提供します。
367追加することもできます。
368その表現される Unicode コードは、16 進でブレースに囲みます。
369たとえば、smiley face は C<\x{263A}> です。
370このエンコーディングスキームは 0x100 未満の全ての文字でのみ動作します;
371Perl は最適化や後方互換性のために内部で 8 ビットエンコーディングを
372使うかもしれないことに注意してください。
453373
454=item *
455
456374=begin original
457375
458The C<chr()> and C<ord()> functions work on whole characters.
376Additionally, if you
459377
460378=end original
461379
462C<chr()> 関数と C<ord()> 関数は文字全体対し働きます。
380これ加え
463381
464=item *
382 use charnames ':full';
465383
466384=begin original
467385
468Regular expressions match whole characters. For example, C<"."> matches
386you can use the C<\N{...}> notation and put the official Unicode
469a whole character instead of only a single byte.
387character name within the braces, such as C<\N{WHITE SMILING FACE}>.
470388
471389=end original
472390
473正規現は文字全体にマッチします。
391とすると C<\N{...}> 記を使うことができ、公式な Unicode 文字名を
474例えば、C<"."> 1 バイトだけではなく、ひとつ文字全体マッチします。
392C<\N{WHITE SMILING FACE}>ようブレースの中に置くことができます。
475393
476394=item *
477395
478396=begin original
479397
480The C<tr///> operator translates whole characters. (Note that the
398If an appropriate L<encoding> is specified, identifiers within the
481C<tr///CU> functionality has been removed. For similar functionality to
399Perl script may contain Unicode alphanumeric characters, including
482that, see C<pack('U0', ...)> and C<pack('C0', ...)>).
400ideographs. Perl does not currently attempt to canonicalize variable
401names.
483402
484403=end original
485404
486C<tr///> 演算は文字全体を変換します。
405適切な L<encoding> が指定されていれば、Perl スクリプトの中の識別
487C<tr///CU> は削除されたことに注意してください
406表意文字を含めた Unicode の英数字を含めることができます
488(これと同様のことには C<pack('U0', ...)> C<pack('C0', ...)> を
407Perl は現在、変数名正規化しようとはしません。
489参照してください。)
490408
491409=item *
492410
493411=begin original
494412
495C<scalar reverse()> reverses by character rather than by byte.
413Regular expressions match characters instead of bytes. "." matches
414a character instead of a byte.
496415
497416=end original
498417
499C<scalar reverse()> はバイト単位ではなく文字単位で
418正規表現はバイトではなく文字にマッチします。
500反転を行います。
419"." は一バイトではなく、ひとつの文字にマッチします。
501420
502421=item *
503422
504423=begin original
505424
506The bit string operators, C<& | ^ ~> and (starting in v5.22)
425Character classes in regular expressions match characters instead of
507C<&. |. ^. ~.> can operate on bit strings encoded in UTF-8, but this
426bytes and match against the character properties specified in the
508can give unexpected results if any of the strings contain code points
427Unicode properties database. C<\w> can be used to match a Japanese
509above 0xFF. Starting in v5.28, it is a fatal error to have such an
428ideograph, for instance.
510operand. Otherwise, the operation is performed on a non-UTF-8 copy of
511the operand. If you're not sure about the encoding of a string,
512downgrade it before using any of these operators; you can use
513L<C<utf8::utf8_downgrade()>|utf8/Utility functions>.
514429
515430=end original
516431
517ビット文字列演算子 C<& | ^ ~> および
432正規表現中の文字クラスはバイではなく文字にマッチし、Unicode
518(v5.22 からの) C<&. |. ^. ~.> は UTF-8 でエンコされたビット文字
433特性デタベースで定義されている文字特性に対してマッチ行います。
519操作できますが、文字列の一部 0xFF を超え符号位置を含んいる場合、
434たとえばC<\w> は日本語の表意文字にマッチさせために使うことがきます。
520予想外の結果になるかもしれません。
521v5.28 から、そのようなオペランドに対しては致命的エラーになります。
522さもなければ、処理はオペランドの非 UTF-8 のコピーに対して行われます。
523文字列のエンコーディンがはっきりしない場合、
524これらの演算子を使う前に降格してください;
525L<C<utf8::utf8_downgrade()>|utf8/Utility functions> が使えます。
526435
527=back
436=item *
528437
529438=begin original
530439
531The bottom line is that Perl has always practiced "Character Semantics",
440Named Unicode properties, scripts, and block ranges may be used like
532but with the advent of Unicode, that is now different than "Byte
441character classes via the C<\p{}> "matches property" construct and
533Semantics".
442the C<\P{}> negation, "doesn't match property".
534443
535444=end original
536445
537まとめとしては、Perl は常に「文字意味論」で動作しますが
446名前付けされた Unicode の特性用字、ブロックの範囲は C<\p{}>
538Unicode の搭乗により、これは「バイト意味論」とは
447"matches property" 構造やそ否定形 C<\P{}> "doesn't match property" を
539異なるようになています。
448使た文字クラスで使うことができます。
540449
541=head2 ASCII Rules versus Unicode Rules
542
543(ASCII 規則対 Unicode 規則)
544
545450=begin original
546451
547Before Unicode, when a character was a byte was a character,
452See L</"Unicode Character Properties"> for more details.
548Perl knew only about the 128 characters defined by ASCII, code points 0
549through 127 (except for under L<S<C<use locale>>|perllocale>). That
550left the code
551points 128 to 255 as unassigned, and available for whatever use a
552program might want. The only semantics they have is their ordinal
553numbers, and that they are members of none of the non-negative character
554classes. None are considered to match C<\w> for example, but all match
555C<\W>.
556453
557454=end original
558455
559Unicode 以前、文字はバイトでバイトは文字という時代は、
456さらなる詳細については L</"Unicode Character Properties"> を
560Perl は ASCII で定義れた 128 文字、符号位置 0 から 127 に
457参照してくだい。
561ついてしか知りませんでした (L<S<C<use locale>>|perllocale> の下を除く)。
562そのため、符号位置 128 から 255 は割り当てられておらず、プログラムが
563望むあらゆる用途に利用可能でした。
564それらが持つ唯一のセマンティクスは序数であり、
565それらは否定でない文字クラスのメンバーではありません。
566たとえば、どれも C<\w> にマッチングするとは見なされず、すべてが C<\W> に
567マッチングします。
568458
569459=begin original
570460
571Unicode, of course, assigns each of those code points a particular
461You can define your own character properties and use them
572meaning (along with ones above 255). To preserve backward
462in the regular expression with the C<\p{}> or C<\P{}> construct.
573compatibility, Perl only uses the Unicode meanings when there is some
574indication that Unicode is what is intended; otherwise the non-ASCII
575code points remain treated as if they are unassigned.
576463
577464=end original
578465
579Unicodeはもちろん、これら符号位置のそれぞれに特定の意味を割り当てます
466独自文字性を義でき、C<\p{}> や C<\P{}> 構造で正規表現で使えます
580(255 より上も同様です)。
581後方互換性を保つために、Perl は Unicode が意図されたものであることを示す
582何らかの表示がある場合にのみ Unicode の意味を使用します;
583それ以外の場合、非 ASCII 符号位置は、割り当てられていないものとして
584扱われます。
585467
586468=begin original
587469
588Here are the ways that Perl knows that a string should be treated as
470See L</"User-Defined Character Properties"> for more details.
589Unicode:
590471
591472=end original
592473
593次のもの、文字列が Unicode として扱われるべきと Perl が分かる方法です:
474更なる詳細についてL</"User-Defined Character Properties">
475参照してください。
594476
595=over
596
597477=item *
598478
599479=begin original
600480
601Within the scope of S<C<use utf8>>
481The special pattern C<\X> matches any extended Unicode
482sequence--"a combining character sequence" in Standardese--where the
483first character is a base character and subsequent characters are mark
484characters that apply to the base character. C<\X> is equivalent to
485C<(?:\PM\pM*)>.
602486
603487=end original
604488
605S<C<use utf8>>スコープの内側
489特殊なパターン C<\X> は拡張 Unicode シーケンス -- Standardese
490"a combining character sequence" -- 最初の文字が基本となる文字で
491続く文字が基本文字に適用されるマーク文字にマッチします。
492C<\X> は C<(?:\PM\pM*)> と等価です。
606493
607=begin original
608
609If the whole program is Unicode (signified by using 8-bit B<U>nicode
610B<T>ransformation B<F>ormat), then all literal strings within it must be
611Unicode.
612
613=end original
614
615プログラム全体が (8-bit B<U>nicode B<T>ransformation B<F>ormat を
616使うことで示される) Unicode の場合、その中の全てのリテラルな文字列は
617Unicode でなければなりません。
618
619494=item *
620495
621496=begin original
622497
623Within the scope of
498The C<tr///> operator translates characters instead of bytes. Note
624L<S<C<use feature 'unicode_strings'>>|feature/The 'unicode_strings' feature>
499that the C<tr///CU> functionality has been removed. For similar
500functionality see pack('U0', ...) and pack('C0', ...).
625501
626502=end original
627503
628L<S<C<use feature 'unicode_strings'>>|feature/The 'unicode_strings' feature>
504C<tr///> 演算子はバイトではなく文字で変換します。
629のスコープの内側
505C<tr///CU> は削除されたことに注意してください。
506同様のことを行うには pack('U0', ...) と pack('C0', ...) を
507参照してください。
630508
631=begin original
632
633This pragma was created so you can explicitly tell Perl that operations
634executed within its scope are to use Unicode rules. More operations are
635affected with newer perls. See L</The "Unicode Bug">.
636
637=end original
638
639このプラグマは、このスコープ内で実行される操作は Unicode の規則が
640使われるべきということを明示的に Perl に伝えるために作られました。
641より新しい perl では更なる操作が影響を受けます。
642L</The "Unicode Bug"> を参照してください。
643
644509=item *
645510
646511=begin original
647512
648Within the scope of S<C<use v5.12>> or higher
513Case translation operators use the Unicode case translation tables
514when character input is provided. Note that C<uc()>, or C<\U> in
515interpolated strings, translates to uppercase, while C<ucfirst>,
516or C<\u> in interpolated strings, translates to titlecase in languages
517that make the distinction.
649518
650519=end original
651520
652S<C<use v5.12>> 以上スコ内側
521大小文字の変換演算子は Unicode の大小文字変換テブルを、文字入力が
522あったときに使用します。
523C<uc()> や展開文字列中の C<\U> は大文字に変換し、C<ucfirst> や
524展開文字列中の C<\u> はその言語で区別されているときに
525タイトルケースに変換します。
653526
654=begin original
655
656This implicitly turns on S<C<use feature 'unicode_strings'>>.
657
658=end original
659
660これは暗黙に S<C<use feature 'unicode_strings'>> を有効にします。
661
662527=item *
663528
664529=begin original
665530
666Within the scope of
531Most operators that deal with positions or lengths in a string will
667L<S<C<use locale 'not_characters'>>|perllocale/Unicode and UTF-8>,
532automatically switch to using character positions, including
668or L<S<C<use locale>>|perllocale> and the current
533C<chop()>, C<chomp()>, C<substr()>, C<pos()>, C<index()>, C<rindex()>,
669locale is a UTF-8 locale.
534C<sprintf()>, C<write()>, and C<length()>. An operator that
535specifically does not switch is C<vec()>. Operators that really don't
536care include operators that treat strings as a bucket of bits such as
537C<sort()>, and operators dealing with filenames.
670538
671539=end original
672540
673L<S<C<use locale 'not_characters'>>|perllocale/Unicode and UTF-8> か
541文字列の位置や長さを取り扱う演算子の大部分は自動的に文字の位置を
674L<S<C<use locale>>|perllocale> のスコープ内で、現在のロケールが
542使うように変更されました。
675UTF-8 ロケール。
543これには C<chop()>, C<chomp()>, C<substr()>, C<pos()>, C<index()>,
544C<rindex()>, C<sprintf()>, C<write()>, C<length()> が含まれます。
545C<vec()> は変更されていません。
546文字列をビットのバケツのように扱う C<sort()>、ファイル名を取り扱う
547演算子は文字かどうかを気にしません。
676548
677=begin original
678
679The former is defined to imply Unicode handling; and the latter
680indicates a Unicode locale, hence a Unicode interpretation of all
681strings within it.
682
683=end original
684
685前者は Unicode の扱いを暗示し、後者は Unicode ロケールを示すので、
686この中の全ての文字列は Unicode の解釈になります。
687
688549=item *
689550
690551=begin original
691552
692When the string contains a Unicode-only code point
553The C<pack()>/C<unpack()> letter C<C> does I<not> change, since it is often
554used for byte-oriented formats. Again, think C<char> in the C language.
693555
694556=end original
695557
696文字列が Unicodeみの符号位置を含んでるとき
558C<pack()>/C<unpack()>文字 C<C> は I<変更されてません>。
559なぜなら、これらはしばしばバイト指向の書式のために使われるからです。
560繰り返しますが、C 言語の C<char> を考えてください。
697561
698562=begin original
699563
700Perl has never accepted code points above 255 without them being
564There is a new C<U> specifier that converts between Unicode characters
701Unicode, so their use implies Unicode for the whole string.
565and code points. There is also a C<W> specifier that is the equivalent of
566C<chr>/C<ord> and properly handles character values even if they are above 255.
702567
703568=end original
704569
705Perl は Unicode でない限り 255 を超える符号位置を決して受け入れいので、
570Unicode の文字と符号位置の間の変換行う新た C<U> 指定子があります。
706これらを使うと文字列全体Unicode であること暗示します。
571C<chr>/C<ord> 等価で、文字の値255超えていても適切に扱える
572C<W> 指定子もあります。
707573
708574=item *
709575
710576=begin original
711577
712When the string contains a Unicode named code point C<\N{...}>
578The C<chr()> and C<ord()> functions work on characters, similar to
579C<pack("W")> and C<unpack("W")>, I<not> C<pack("C")> and
580C<unpack("C")>. C<pack("C")> and C<unpack("C")> are methods for
581emulating byte-oriented C<chr()> and C<ord()> on Unicode strings.
582While these methods reveal the internal encoding of Unicode strings,
583that is not something one normally needs to care about at all.
713584
714585=end original
715586
716文字列が Unicode の名前付き符号位置 C<\N{...}> を含んでいるとき
587C<chr()> 関数と C<ord()> 関数は C<pack("W")> や C<unpack("W")> のように
588文字に対して働き、C<pack("C")> や C<unpack("C")> のようには I<働きません>。
589C<pack("C")> と C<unpack("C")> は Unicode 文字列においてバイト指向の
590C<chr()> や C<ord()> をエミュレートするためのメソッドです。
591これらのメソッドが Unicode 文字列の内部エンコーディングを明らかにするので、
592通常はケアする必要はありません。
717593
718=begin original
719
720The C<\N{...}> construct explicitly refers to a Unicode code point,
721even if it is one that is also in ASCII. Therefore the string
722containing it must be Unicode.
723
724=end original
725
726C<\N{...}> 構文は、たとえ ASCII にもあるものだとしても、
727明示的に Unicode 符号位置を参照します。
728従ってこれを含む文字列は Unicode でなければなりません。
729
730594=item *
731595
732596=begin original
733597
734When the string has come from an external source marked as
598The bit string operators, C<& | ^ ~>, can operate on character data.
735Unicode
599However, for backward compatibility, such as when using bit string
600operations when characters are all less than 256 in ordinal value, one
601should not use C<~> (the bit complement) with characters of both
602values less than 256 and values greater than 256. Most importantly,
603DeMorgan's laws (C<~($x|$y) eq ~$x&~$y> and C<~($x&$y) eq ~$x|~$y>)
604will not hold. The reason for this mathematical I<faux pas> is that
605the complement cannot return B<both> the 8-bit (byte-wide) bit
606complement B<and> the full character-wide bit complement.
736607
737608=end original
738609
739文字列 Unicode とマクされている外部ソースから来たと
610ビット文字列演算子 C<& | ^ ~> は文字デタを操作でます。
611しかし、例えば全ての文字の値が 255 以下のときに
612ビット文字列演算を使った場合の後方互換性のために、
613256 以上の値の文字と 255 以下の値の文字の両方が含まれている文字列に
614C<~> (ビット補数) を使うべきではありません。
615最も重要なことは、ド・モルガンの法則 (C<~($x|$y) eq ~$x&~$y> と
616C<~($x&$y) eq ~$x|~$y>) が成り立たないということです。
617この数学的な I<過失> の理由は補数(complement)が 8 ビットのビット補数
618B<および> 文字幅のビット補数の B<両方> を返すことができないためです。
740619
741=begin original
742
743The L<C<-C>|perlrun/-C [numberE<sol>list]> command line option can
744specify that certain inputs to the program are Unicode, and the values
745of this can be read by your Perl code, see L<perlvar/"${^UNICODE}">.
746
747=end original
748
749L<C<-C>|perlrun/-C [numberE<sol>list]> コマンドラインオプションは
750プログラムへの特定の入力が Unicode であることを指定でき、その値は
751Perl のコードで読み込めます; L<perlvar/"${^UNICODE}"> を参照してください。
752
753=item * When the string has been upgraded to UTF-8
754
755(文字列が UTF-8 に昇格したとき)
756
757=begin original
758
759The function L<C<utf8::utf8_upgrade()>|utf8/Utility functions>
760can be explicitly used to permanently (unless a subsequent
761C<utf8::utf8_downgrade()> is called) cause a string to be treated as
762Unicode.
763
764=end original
765
766L<C<utf8::utf8_upgrade()>|utf8/Utility functions> 関数は、
767(後に C<utf8::utf8_downgrade()> が呼び出されるまで)
768恒久的に文字列を Unicode として扱うことを明示的に示すために使われます。
769
770=item * There are additional methods for regular expression patterns
771
772(正規表現パターンに追加の手法があるとき)
773
774=begin original
775
776A pattern that is compiled with the C<< /u >> or C<< /a >> modifiers is
777treated as Unicode (though there are some restrictions with C<< /a >>).
778Under the C<< /d >> and C<< /l >> modifiers, there are several other
779indications for Unicode; see L<perlre/Character set modifiers>.
780
781=end original
782
783C<< /u >> や C<< /a >> の修飾子付きでコンパイルされたパターンは、
784Unicode として扱われます (但し、C<< /a >> にはいくつかの制限があります)。
785C<< /d >> と C<< /l >> の修飾子の下では、Unicode を示す他の方法がいくつか
786あります; L<perlre/Character set modifiers> を参照してください。
787
788=back
789
790=begin original
791
792Note that all of the above are overridden within the scope of
793C<L<use bytes|bytes>>; but you should be using this pragma only for
794debugging.
795
796=end original
797
798前述の全ては C<L<use bytes|bytes>> のスコープ内では上書きされます;
799しかしこのプラグマはデバッグ用にのみ使うべきです。
800
801=begin original
802
803Note also that some interactions with the platform's operating system
804never use Unicode rules.
805
806=end original
807
808また、プラットフォームのオペレーティングシステムとの相互作用の一部は
809決して Unicode の規則を使いません。
810
811=begin original
812
813When Unicode rules are in effect:
814
815=end original
816
817Unicode の規則が有効の場合:
818
819=over 4
820
821620=item *
822621
823622=begin original
824623
825Case translation operators use the Unicode case translation tables.
624lc(), uc(), lcfirst(), and ucfirst() work for the following cases:
826625
827626=end original
828627
829大小文字の変換演算子は Unicode大小文字変換テーブルを使用します
628lc(), uc(), lcfirst(), ucfirst() は以下場合に働きます:
830629
831=begin original
630=over 8
832631
833Note that C<uc()>, or C<\U> in interpolated strings, translates to
834uppercase, while C<ucfirst>, or C<\u> in interpolated strings,
835translates to titlecase in languages that make the distinction (which is
836equivalent to uppercase in languages without the distinction).
837
838=end original
839
840C<uc()> や展開文字列中の C<\U> は大文字に変換し、C<ucfirst> や
841展開文字列中の C<\u> はその言語で区別されているときに
842タイトルケースに変換します (これは、区別がない言語では大文字と等価です)。
843
844=begin original
845
846There is a CPAN module, C<L<Unicode::Casing>>, which allows you to
847define your own mappings to be used in C<lc()>, C<lcfirst()>, C<uc()>,
848C<ucfirst()>, and C<fc> (or their double-quoted string inlined versions
849such as C<\U>). (Prior to Perl 5.16, this functionality was partially
850provided in the Perl core, but suffered from a number of insurmountable
851drawbacks, so the CPAN module was written instead.)
852
853=end original
854
855C<lc()>, C<lcfirst()>, C<uc()>, C<ucfirst()>, C<fc> (および C<\U> のような
856ダブルクォート文字列インライン版) で使える独自のマッピングを定義できる
857CPAN モジュール C<L<Unicode::Casing>> があります。
858(Perl 5.16 以前では、この機能は Perl コアで部分的に提供されていましたが、
859多くの克服できない欠点があったため、代わりに CPAN モジュールが書かれました。)
860
861632=item *
862633
863634=begin original
864635
865Character classes in regular expressions match based on the character
636the case mapping is from a single Unicode character to another
866properties specified in the Unicode properties database.
637single Unicode character, or
867638
868639=end original
869640
870正規表現の文字クラは、Unicode 特性データベースで定義されている文字特性を
641ケーマッピングが単一の Unicode 文字から
871基にしてマッチングします。
642別の単一の Unicode 文字へのものであるか、
872643
873=begin original
874
875C<\w> can be used to match a Japanese ideograph, for instance; and
876C<[[:digit:]]> a Bengali number.
877
878=end original
879
880例えば、C<\w> は日本語の文字にマッチングするために使われ、
881C<[[:digit:]]> はベンガル数字に使われます。
882
883644=item *
884645
885646=begin original
886647
887Named Unicode properties, scripts, and block ranges may be used (like
648the case mapping is from a single Unicode character to more
888bracketed character classes) by using the C<\p{}> "matches property"
649than one Unicode character.
889construct and the C<\P{}> negation, "doesn't match property".
890650
891651=end original
892652
893名前付き Unicode 特性、用、ブロック範囲は、
653ケースマッピングが単一の Unicode から
894C<\p{}> 「特性にマッチング」構および否定である C<\P{}>
654一文字以上の Unicode 字へのものである
895「特性にマッチングしない」を使って(大かっこ文字クラスのように)使えます。
896655
897=begin original
656=back
898657
899See L</"Unicode Character Properties"> for more details.
900
901=end original
902
903さらなる詳細については L</"Unicode Character Properties"> を参照してください。
904
905658=begin original
906659
907You can define your own character properties and use them
660Things to do with locales (Lithuanian, Turkish, Azeri) do B<not> work
908in the regular expression with the C<\p{}> or C<\P{}> construct.
661since Perl does not understand the concept of Unicode locales.
909See L</"User-Defined Character Properties"> for more details.
910662
911663=end original
912664
913独自の文字特性を定義して、C<\p{}>C<\P{}> 構文によって
665ロケール(Lithuanian, Turkish, Azeri)に付随するこ B<働きません>
914正規表現でそれらを使うことができます。
666それは Perl Unicode のロケールのコンセプトを理解しないからです。
915さらなる詳細については L</"User-Defined Character Properties"> を
916参照してください。
917667
918=back
919
920=head2 Extended Grapheme Clusters (Logical characters)
921
922(拡張書記素クラスタ (論理文字))
923
924668=begin original
925669
926Consider a character, say C<H>. It could appear with various marks around it,
670See the Unicode Technical Report #21, Case Mappings, for more details.
927such as an acute accent, or a circumflex, or various hooks, circles, arrows,
928I<etc.>, above, below, to one side or the other, I<etc>. There are many
929possibilities among the world's languages. The number of combinations is
930astronomical, and if there were a character for each combination, it would
931soon exhaust Unicode's more than a million possible characters. So Unicode
932took a different approach: there is a character for the base C<H>, and a
933character for each of the possible marks, and these can be variously combined
934to get a final logical character. So a logical character--what appears to be a
935single character--can be a sequence of more than one individual characters.
936The Unicode standard calls these "extended grapheme clusters" (which
937is an improved version of the no-longer much used "grapheme cluster");
938Perl furnishes the C<\X> regular expression construct to match such
939sequences in their entirety.
940671
941672=end original
942673
943一つ文字、例えば C<H> につい考えてみます
674詳しくは Unicode Technical Report #21 の Case Mappings を参照しください
944これは文字の回りの様々なマークと共に現れることがあって、
945鋭アクセント、曲折アクセント、フック、円、矢など、上、下、左、右、などです。
946世界中の言語の中では多くの可能性があります。
947組み合わせの数は天文学的で、
948それぞれの組み合わせを一つの文字にすると、Unicode の数百万の可能な文字を
949すぐに使い切ってしまいます。
950それで Unicode は異なる手法を取りました:
951基本となる C<H> を一つの文字として、
952それぞれの可能なマークのそれぞれを一つの文字として、
953最後に論理的な文字でこれらを様々に結合できるようにしました。
954それで一つの論理文字--単一の文字として現れるもの--は
955複数の独立した文字の並びになることがあります。
956Unicode 標準はこれを「拡張書記素クラスタ」("extended grapheme cluster")
957(もはやあまり使われない「書記素クラスタ」"grapheme cluster" の改良版) と
958呼びます;
959Perl はこのような並び丸ごとにマッチングする C<\X> 正規表現構文を
960用意しています。
961675
962676=begin original
963677
964But Unicode's intent is to unify the existing character set standards and
678But you can also define your own mappings to be used in the lc(),
965practices, and several pre-existing standards have single characters that
679lcfirst(), uc(), and ucfirst() (or their string-inlined versions).
966mean the same thing as some of these combinations, like ISO-8859-1,
967which has quite a few of them. For example, C<"LATIN CAPITAL LETTER E
968WITH ACUTE"> was already in this standard when Unicode came along.
969Unicode therefore added it to its repertoire as that single character.
970But this character is considered by Unicode to be equivalent to the
971sequence consisting of the character C<"LATIN CAPITAL LETTER E">
972followed by the character C<"COMBINING ACUTE ACCENT">.
973680
974681=end original
975682
976しかし、Unicode目的は、既存の文字集合の標準とプラクティスを
683しかし lc(), lcfirst(), uc(), ucfirst() (およびこれら
977統合することあり、いくつか既存の標準には、これらの組み合わせの
684文字列インライン版) 使える独自マッピングも定義できます。
978いくつかと同じことを意味する単一の文字があります;
979たとえば、ISO-8859-1 には、かなりの数のそのような文字があります。
980たとえば、C<"LATIN CAPITAL LETTER E WITH ACUTE"> は、Unicode が
981登場したときにすでにこの標準に含まれていました。
982したがって、Unicode はそれを単一の文字としてレパートリーに追加しました。
983しかし、Unicode では、この文字は、文字 C<"LATIN CAPITAL LETTER E"> の後に
984文字 C<"COMBINING ACUTE ACCENT"> が続く並びと等価であると見なされます。
985685
986686=begin original
987687
988C<"LATIN CAPITAL LETTER E WITH ACUTE"> is called a "pre-composed"
688See L</"User-Defined Case Mappings"> for more details.
989character, and its equivalence with the "E" and the "COMBINING ACCENT"
990sequence is called canonical equivalence. All pre-composed characters
991are said to have a decomposition (into the equivalent sequence), and the
992decomposition type is also called canonical. A string may be comprised
993as much as possible of precomposed characters, or it may be comprised of
994entirely decomposed characters. Unicode calls these respectively,
995"Normalization Form Composed" (NFC) and "Normalization Form Decomposed".
996The C<L<Unicode::Normalize>> module contains functions that convert
997between the two. A string may also have both composed characters and
998decomposed characters; this module can be used to make it all one or the
999other.
1000689
1001690=end original
1002691
1003C<"LATIN CAPITAL LETTER E WITH ACUTE"> は「合成済」(pre-composed) 文字と
692更なる詳細については L</"User-Defined Case Mappings"> を参照してください。
1004呼ばれ、"E" および "COMBINING ACCENT" と等価な並びは正準等価
1005(canonical equivalence) と呼ばれます。
1006全ての合成済文字は(等価な並びに)分解でき、分解の種類もまた正準と呼ばれます。
1007文字列は、可能な限り合成済文字で構成される場合もあれば、
1008完全に分解された文字で構成される場合もあります。
1009Unicode では、これらをそれぞれ
1010「正規化形式 C」("Normalization Form Composed": NFC) と
1011"Normalization Form Decomposed" と呼んでいます。
1012C<L<Unicode::Normalize>> モジュールには、
1013二つの文字を変換する関数が含まれています。
1014文字列は、合成された文字と分解された文字の両方を持つこともできます。
1015このモジュールを使用して、すべてを片方にすることも、
1016もう片方にすることもできます。
1017693
1018=begin original
694=back
1019695
1020You may be presented with strings in any of these equivalent forms.
696=over 4
1021There is currently nothing in Perl 5 that ignores the differences. So
1022you'll have to specially handle it. The usual advice is to convert your
1023inputs to C<NFD> before processing further.
1024697
1025=end original
698=item *
1026699
1027これらの同等のどの形式でも文字列が表現される場合があります。
1028現在のところ、Perl 5 にはこの違いを無視するものは何もありません。
1029そのため、特別にそれを扱う必要があります。
1030通常のアドバイスは、処理を進める前に入力を C<NFD> に変換することです。
1031
1032700=begin original
1033701
1034For more detailed information, see L<http://unicode.org/reports/tr15/>.
702And finally, C<scalar reverse()> reverses by character rather than by byte.
1035703
1036704=end original
1037705
1038さらに詳い情報についL<http://unicode.org/reports/tr15/>
706して最後にC<scalar reverse()> はバイト単位ではなく文字単位で
1039参照してください。
707反転を行ます
1040708
709=back
710
1041711=head2 Unicode Character Properties
1042712
1043713(Unicode 文字特性)
1044714
1045715=begin original
1046716
1047(The only time that Perl considers a sequence of individual code
717Named Unicode properties, scripts, and block ranges may be used like
1048points as a single logical character is in the C<\X> construct, already
718character classes via the C<\p{}> "matches property" construct and
1049mentioned above. Therefore "character" in this discussion means a single
719the C<\P{}> negation, "doesn't match property".
1050Unicode code point.)
1051720
1052721=end original
1053722
1054(Perl が個々符号位置の並びを単一の論理文として扱う
723名前付けされた Unicode の特性、用、ブロックの範囲は C<\p{}>
1055唯一タイミングは、既に前述した C<\X> 構文です。
724"matches property" 構造やそ否定形の C<\P{}> "doesn't match property" を
1056て、この議論での「文字」は単一の Unicode 符号位置を意味します。)
725使文字クラスで使うことができます。
1057726
1058727=begin original
1059728
1060Very nearly all Unicode character properties are accessible through
729For instance, C<\p{Lu}> matches any character with the Unicode "Lu"
1061regular expressions by using the C<\p{}> "matches property" construct
730(Letter, uppercase) property, while C<\p{M}> matches any character
1062and the C<\P{}> "doesn't match property" for its negation.
731with an "M" (mark--accents and such) property. Brackets are not
732required for single letter properties, so C<\p{M}> is equivalent to
733C<\pM>. Many predefined properties are available, such as
734C<\p{Mirrored}> and C<\p{Tibetan}>.
1063735
1064736=end original
1065737
1066ほぼ全ての Unicode 文字特性は、
738たとえば、C<\p{Lu}> Unicode の "Lu" (Letter, uppercase) 特性を持つ任意の
1067C<\p{}> "matches property" 構文とその否定形の C<\P{}>
739文字にマッチし、C<\p{M}> "M" (mark -- アクセントなど) 特性を持つ任意の
1068"doesn't match property" を使った正規表現を通てアクセス可能です。
740文字にマッチす。
741ブラケットは一文字の特性では省略することができるので、C<\p{M}> は
742C<\PM> と等価です。
743C<\p{Mirrored}> や C<\p{Tibetan}> など多くの特性が定義されています。
1069744
1070745=begin original
1071746
1072For instance, C<\p{Uppercase}> matches any single character with the Unicode
747The official Unicode script and block names have spaces and dashes as
1073C<"Uppercase"> property, while C<\p{L}> matches any character with a
748separators, but for convenience you can use dashes, spaces, or
1074C<General_Category> of C<"L"> (letter) property (see
749underbars, and case is unimportant. It is recommended, however, that
1075L</General_Category> below). Brackets are not
750for consistency you use the following naming: the official Unicode
1076required for single letter property names, so C<\p{L}> is equivalent to C<\pL>.
751script, property, or block name (see below for the additional rules
752that apply to block names) with whitespace and dashes removed, and the
753words "uppercase-first-lowercase-rest". C<Latin-1 Supplement> thus
754becomes C<Latin1Supplement>.
1077755
1078756=end original
1079757
1080たとえば、C<\p{Uppercase}> Unicode の C<"Uppercase"> 特性持つ任意の
758公式の Unicode 用字およびブロック名前はスペースとダッシュ
1081単一文字にマチングしC<\p{L}> は C<General_Category> C<"L"> (letter)
759セパレータとして使っていますが、便利ため、ダシュスペース、
1082特性持つ任意の文字にマッチングし
760アンダーバー使うことができ、また、大小文字の違いは重要ではありせん。
1083(後述する L</General_Category> 参照)。
761しかしながら、以下のネーミングにしたがって、首尾一貫して使うことを
1084中かっこは一文字の特性名では省略することができるのでC<\p{L}>
762お勧めします: Unicode 用字、特性、ブロックの名前 (ブロック名に
1085C<\pL> と等価です。
763適用される付加的なルールについて以下を参照してください) から
764空白とダッシュを取り除き、単語の先頭を大文字にし残りを小文字にします。
765したがって、C<Latin-1 Supplement> は C<Latin1Supplement> となります。
1086766
1087767=begin original
1088768
1089More formally, C<\p{Uppercase}> matches any single character whose Unicode
1090C<Uppercase> property value is C<True>, and C<\P{Uppercase}> matches any character
1091whose C<Uppercase> property value is C<False>, and they could have been written as
1092C<\p{Uppercase=True}> and C<\p{Uppercase=False}>, respectively.
1093
1094=end original
1095
1096より正式には、C<\p{Uppercase}> は Unicode の C<Uppercase> 特性値 が
1097C<True> である任意の単一の文字とマッチングし、C<\P{UpperCase}> は
1098C<UpperCase> 特性値 が C<False> である任意の文字とマッチングします;
1099そしてこれらはそれぞれ C<\p{Uppercase=True}>, C<\p{Uppercase=False}> と書けます。
1100
1101=begin original
1102
1103This formality is needed when properties are not binary; that is, if they can
1104take on more values than just C<True> and C<False>. For example, the
1105C<Bidi_Class> property (see L</"Bidirectional Character Types"> below),
1106can take on several different
1107values, such as C<Left>, C<Right>, C<Whitespace>, and others. To match these, one needs
1108to specify both the property name (C<Bidi_Class>), AND the value being
1109matched against
1110(C<Left>, C<Right>, I<etc.>). This is done, as in the examples above, by having the
1111two components separated by an equal sign (or interchangeably, a colon), like
1112C<\p{Bidi_Class: Left}>.
1113
1114=end original
1115
1116この形式は、特性が 2 値でない場合、つまり、単に C<True> と C<False> より多くの
1117値を取ることができる場合に必要です。
1118たとえば、C<Bidi_Class> 特性(L</"Bidirectional Character Types"> を参照)は、
1119C<Left>, C<Right>, C<Whitespace> などのさまざまな値を取ることができます。
1120これらにマッチングするには、特性名(C<Bidi_Class>)と、
1121マッチングする値 (C<Left>, C<Right> など) の両方を指定する必要があります。
1122これは、前述の例のように、二つの要素を等号
1123(または、C<\p{Biddi_Class:Left}> のように交換可能なコロン)で
1124区切ることによって、実行されます。
1125
1126=begin original
1127
1128All Unicode-defined character properties may be written in these compound forms
1129of C<\p{I<property>=I<value>}> or C<\p{I<property>:I<value>}>, but Perl provides some
1130additional properties that are written only in the single form, as well as
1131single-form short-cuts for all binary properties and certain others described
1132below, in which you may omit the property name and the equals or colon
1133separator.
1134
1135=end original
1136
1137すべての Unicode が定義した文字特性は、C<\p{I<property>=I<value>}> や
1138C<\p{I<property>:I<value>}> のような複合形式で書けますが、
1139Perl は特性名および等号やコロンの区切り文字を省略できるように、
1140単一形式でのみ書ける追加の特性や、全ての 2 値特性と一部の後述する
1141ものに対する単一形式のショートカットを提供します。
1142
1143=begin original
1144
1145Most Unicode character properties have at least two synonyms (or aliases if you
1146prefer): a short one that is easier to type and a longer one that is more
1147descriptive and hence easier to understand. Thus the C<"L"> and
1148C<"Letter"> properties above are equivalent and can be used
1149interchangeably. Likewise, C<"Upper"> is a synonym for C<"Uppercase">,
1150and we could have written C<\p{Uppercase}> equivalently as C<\p{Upper}>.
1151Also, there are typically various synonyms for the values the property
1152can be. For binary properties, C<"True"> has 3 synonyms: C<"T">,
1153C<"Yes">, and C<"Y">; and C<"False"> has correspondingly C<"F">,
1154C<"No">, and C<"N">. But be careful. A short form of a value for one
1155property may not mean the same thing as the short form spelled the same
1156for another.
1157Thus, for the C<L</General_Category>> property, C<"L"> means
1158C<"Letter">, but for the L<C<Bidi_Class>|/Bidirectional Character Types>
1159property, C<"L"> means C<"Left">. A complete list of properties and
1160synonyms is in L<perluniprops>.
1161
1162=end original
1163
1164ほとんどの Unicode 文字特性には、少なくとも二つの同義語
1165(またはあなたが好むなら別名)があります; 簡単に入力できる短いものと、
1166より長いけれども説明的で理解しやすいものです。
1167したがって、前述の C<"L"> および C<"Letter"> 特性は等価であり、
1168交換可能です。
1169同様に、C<"Upper"> は C<"Uppercase"> の同義語であり、C<\p{Uppercase}> は
1170等価に C<\p{Upper}> と書けます。
1171また、典型的には特性の値に対してさまざまな同義語があります。
11722 値特性の場合、C<"True"> には三つの同義語があります:
1173C<"T">, C<"Yes">, C<"Y">; C<"False"> には C<"F">, C<"No">, C<"N"> が
1174あります。
1175しかし注意してください。
1176ある特性に対する値の短い形式は、他の特性の同じ綴りの短い形式と同じものを
1177意味するとは限りません。
1178従って、C<L</General_Category>> 特性では C<"L"> は C<"Letter"> を
1179意味しますが、L<C<Bidi_Class>|/Bidirectional Character Types> 特性では、
1180C<"L"> は C<"Left"> を意味します。
1181特性および同義語の完全な一覧は L<perluniprops> にあります。
1182
1183=begin original
1184
1185Upper/lower case differences in property names and values are irrelevant;
1186thus C<\p{Upper}> means the same thing as C<\p{upper}> or even C<\p{UpPeR}>.
1187Similarly, you can add or subtract underscores anywhere in the middle of a
1188word, so that these are also equivalent to C<\p{U_p_p_e_r}>. And white space
1189is generally irrelevant adjacent to non-word characters, such as the
1190braces and the equals or colon separators, so C<\p{ Upper }> and
1191C<\p{ Upper_case : Y }> are equivalent to these as well. In fact, white
1192space and even hyphens can usually be added or deleted anywhere. So
1193even C<\p{ Up-per case = Yes}> is equivalent. All this is called
1194"loose-matching" by Unicode. The "name" property has some restrictions
1195on this due to a few outlier names. Full details are given in
1196L<https://www.unicode.org/reports/tr44/tr44-24.html#UAX44-LM2>.
1197
1198=end original
1199
1200特性名と値の大文字と小文字の違いは無関係です;
1201したがって C<\p{Upper}> は C<\p{upper}>, さらには C<\p{UpPeR}> とも同じことを
1202意味します。
1203同様に、一般的に単語の中のどこにでも下線を追加または削除できるので、
1204これらは C<\p{U_p_p_e_r}> とも等価です。
1205また、中かっこや等号、コロンなどの非単語文字に隣接した空白は無視されるので、
1206C<\p{ Upper }> and C<\p{ Upper_case : Y }> も等価です。
1207実際には、通常、空白とハイフンさえどこにでも追加または削除できます。
1208したがって、C<\p{Upper case=Yes}> ですらも等価です。
1209これはすべて Unicode で「緩いマッチング」と呼ばれます。
1210"name" 特性は、いくつかの特殊な名前のためにいくつかの制限があります。
1211完全な詳細は
1212L<https://www.unicode.org/reports/tr44/tr44-24.html#UAX44-LM2> にあります。
1213
1214=begin original
1215
1216The few places where stricter matching is
1217used is in the middle of numbers, the "name" property, and in the Perl
1218extension properties that begin or end with an underscore. Stricter
1219matching cares about white space (except adjacent to non-word
1220characters), hyphens, and non-interior underscores.
1221
1222=end original
1223
1224数少ない厳密なマッチングが採用されている場所は数値の中、
1225"name" 特性、下線で始まったり終わったりする Perl 拡張特性です。
1226より厳密なマッチングは空白(非単語文字に隣接するものを除く)、ハイフン、
1227非内部下線を考慮します。
1228
1229=begin original
1230
1231769You can also use negation in both C<\p{}> and C<\P{}> by introducing a caret
1232(C<^>) between the first brace and the property name: C<\p{^Tamil}> is
770(^) between the first brace and the property name: C<\p{^Tamil}> is
1233771equal to C<\P{Tamil}>.
1234772
1235773=end original
1236774
1237C<\p{}> と C<\P{}> の両方で、キャレット(C<^>) を最初のブレースと
775C<\p{}> と C<\P{}> の両方で、キャレット(^) を最初のブレースと
1238776特性名の間に置くことによって意味を反転することができます:
1239777C<\p{^Tamil}> は C<\P{Tamil}> と等価です。
1240778
1241779=begin original
1242780
1243Almost all properties are immune to case-insensitive matching. That is,
781B<NOTE: the properties, scripts, and blocks listed here are as of
1244adding a C</i> regular expression modifier does not change what they
782Unicode 5.0.0 in July 2006.>
1245match. There are two sets that are affected.
1246The first set is
1247C<Uppercase_Letter>,
1248C<Lowercase_Letter>,
1249and C<Titlecase_Letter>,
1250all of which match C<Cased_Letter> under C</i> matching.
1251And the second set is
1252C<Uppercase>,
1253C<Lowercase>,
1254and C<Titlecase>,
1255all of which match C<Cased> under C</i> matching.
1256This set also includes its subsets C<PosixUpper> and C<PosixLower> both
1257of which under C</i> match C<PosixAlpha>.
1258(The difference between these sets is that some things, such as Roman
1259numerals, come in both upper and lower case so they are C<Cased>, but
1260aren't considered letters, so they aren't C<Cased_Letter>'s.)
1261783
1262784=end original
1263785
1264ほとんど全ての特性は大文小文字を考慮したマチング影響を受けません。
786B<注意: ここでの特性、用、ブロクは 2006 年 7 月 Unicode 5.0.0 に
1265り、C</i> 正規表現修飾子を追加ることは、
787従っています。>
1266それらがマッチングするものを変えません。
1267影響を受ける二つの集合があります。
1268最初の集合は、
1269C<Uppercase_Letter>,
1270C<Lowercase_Letter>,
1271C<Titlecase_Letter>,
1272C</i> の下で C<Cased_Letter> にマッチングする全てです。
1273二番目の集合は、
1274C<Uppercase>,
1275C<Lowercase>,
1276C<Titlecase>,
1277C</i> マッチングの基で C<Cased> にマッチングする全てです。
1278この集合はまた、C</i> マッチングの基で C<PosixAlpha> にマッチングする
1279そのサブセット C<PosixUpper> と C<PosixLower> を含みます。
1280(これらの集合の違いは、ローマ数字のような一部のもので、
1281大文字と小文字の両方に含まれるので C<Cased> であるけれども、
1282しかし字と考えられないので、C<Cased_Letter> ではありません。)
1283788
1284=begin original
789=over 4
1285790
1286See L</Beyond Unicode code points> for special considerations when
791=item General Category
1287matching Unicode properties against non-Unicode code points.
1288792
1289=end original
1290
1291非 Unicode 符号位置に対して Unicode 特性をマッチングしたときの
1292特殊処理については L</Beyond Unicode code points> を参照してください。
1293
1294=head3 B<General_Category>
1295
1296793=begin original
1297794
1298Every Unicode character is assigned a general category, which is the "most
795Here are the basic Unicode General Category properties, followed by their
1299usual categorization of a character" (from
796long form. You can use either; C<\p{Lu}> and C<\p{UppercaseLetter}>,
1300L<https://www.unicode.org/reports/tr44>).
797for instance, are identical.
1301798
1302799=end original
1303800
1304全て Unicode 文字は一つの一般カテゴリに割り当てられています;
801以下に挙げるは、Unicode の一般カテゴリ特性(General Category properties) で、
1305これは「その文字の最も普通のカテゴライズ」
802長形式が並んでいます。
1306(L<https://www.unicode.org/reports/tr44> より)です。
803たとえば、C<\p{Lu}> と C<\p{UppercaseLetter}> は同じものとして
804扱うことができます。
1307805
1308=begin original
1309
1310The compound way of writing these is like C<\p{General_Category=Number}>
1311(short: C<\p{gc:n}>). But Perl furnishes shortcuts in which everything up
1312through the equal or colon separator is omitted. So you can instead just write
1313C<\pN>.
1314
1315=end original
1316
1317これらを書く複合的な方法は C<\p{General_Category=Number}>
1318(短縮形: C<\p{gc:n}>) のようなものです。
1319Perl は等号またはコロンの区切り文字までの全てを省略できる機能を
1320提供しています。
1321従って、代わりに単に C<\pN> と書けます。
1322
1323=begin original
1324
1325Here are the short and long forms of the values the C<General Category> property
1326can have:
1327
1328=end original
1329
1330以下は、Unicode の C<一般カテゴリ> 特性が持つことができる値の
1331短形式と長形式です:
1332
1333806 Short Long
1334807
1335808 L Letter
1336 LC, L& Cased_Letter (that is: [\p{Ll}\p{Lu}\p{Lt}])
809 LC CasedLetter
1337 Lu Uppercase_Letter
810 Lu UppercaseLetter
1338 Ll Lowercase_Letter
811 Ll LowercaseLetter
1339 Lt Titlecase_Letter
812 Lt TitlecaseLetter
1340 Lm Modifier_Letter
813 Lm ModifierLetter
1341 Lo Other_Letter
814 Lo OtherLetter
1342815
1343816 M Mark
1344 Mn Nonspacing_Mark
817 Mn NonspacingMark
1345 Mc Spacing_Mark
818 Mc SpacingMark
1346 Me Enclosing_Mark
819 Me EnclosingMark
1347820
1348821 N Number
1349 Nd Decimal_Number (also Digit)
822 Nd DecimalNumber
1350 Nl Letter_Number
823 Nl LetterNumber
1351 No Other_Number
824 No OtherNumber
1352825
1353 P Punctuation (also Punct)
826 P Punctuation
1354 Pc Connector_Punctuation
827 Pc ConnectorPunctuation
1355 Pd Dash_Punctuation
828 Pd DashPunctuation
1356 Ps Open_Punctuation
829 Ps OpenPunctuation
1357 Pe Close_Punctuation
830 Pe ClosePunctuation
1358 Pi Initial_Punctuation
831 Pi InitialPunctuation
1359832 (may behave like Ps or Pe depending on usage)
1360 Pf Final_Punctuation
833 Pf FinalPunctuation
1361834 (may behave like Ps or Pe depending on usage)
1362 Po Other_Punctuation
835 Po OtherPunctuation
1363836
1364837 S Symbol
1365 Sm Math_Symbol
838 Sm MathSymbol
1366 Sc Currency_Symbol
839 Sc CurrencySymbol
1367 Sk Modifier_Symbol
840 Sk ModifierSymbol
1368 So Other_Symbol
841 So OtherSymbol
1369842
1370843 Z Separator
1371 Zs Space_Separator
844 Zs SpaceSeparator
1372 Zl Line_Separator
845 Zl LineSeparator
1373 Zp Paragraph_Separator
846 Zp ParagraphSeparator
1374847
1375848 C Other
1376 Cc Control (also Cntrl)
849 Cc Control
1377850 Cf Format
1378 Cs Surrogate
851 Cs Surrogate (not usable)
1379 Co Private_Use
852 Co PrivateUse
1380853 Cn Unassigned
1381854
1382855=begin original
1383856
1384857Single-letter properties match all characters in any of the
1385858two-letter sub-properties starting with the same letter.
1386C<LC> and C<L&> are special: both are aliases for the set consisting of everything matched by C<Ll>, C<Lu>, and C<Lt>.
859C<LC> and C<L&> are special cases, which are aliases for the set of
860C<Ll>, C<Lu>, and C<Lt>.
1387861
1388862=end original
1389863
1390864単一文字の特性は同じ文字で始まる二文字の任意のサブ特性に含まれる
1391865すべての文字にマッチします。
1392C<LC> と C<L&> は特別です: 両方とも C<Ll>, C<Lu>, C<Lt>
866C<LC> と C<L&> は特別なケース、これは C<Ll>, C<Lu>, C<Lt> の別名です。
1393マッチングする全てからなる集合への別名です。
1394867
1395=head3 B<Bidirectional Character Types>
868=begin original
1396869
1397(B<双方向文字型>)
870Because Perl hides the need for the user to understand the internal
871representation of Unicode characters, there is no need to implement
872the somewhat messy concept of surrogates. C<Cs> is therefore not
873supported.
1398874
875=end original
876
877Perl はユーザーが Unicode 文字の内部表現について理解する必要が
878ないようにしているので、サロゲートの面倒なコンセプトについて
879実装する必要はありません。
880従って、C<Cs> はサポートされていません。
881
882=item Bidirectional Character Types
883
1399884=begin original
1400885
1401Because scripts differ in their directionality (Hebrew and Arabic are
886Because scripts differ in their directionality--Hebrew is
1402written right to left, for example) Unicode supplies a C<Bidi_Class> property.
887written right to left, for example--Unicode supplies these properties in
1403Some of the values this property can have are:
888the BidiClass class:
1404889
1405890=end original
1406891
1407用字はその方向性で異なるので (例えばヘブライ語とアラビア語は右から左に
892用字はその方向性で異なるので--たとえばヘブライ語は右から左に書きます --
1408書きます) Unicode は以下の特性を C<Bidi_Class> 特性で提供しています
893Unicode は以下の特性を BidiClass クラスで提供しています:
1409この特性が持つことができる値の一部は:
1410894
1411 Value Meaning
895 Property Meaning
1412896
1413897 L Left-to-Right
1414898 LRE Left-to-Right Embedding
1415899 LRO Left-to-Right Override
1416900 R Right-to-Left
1417 AL Arabic Letter
901 AL Right-to-Left Arabic
1418902 RLE Right-to-Left Embedding
1419903 RLO Right-to-Left Override
1420904 PDF Pop Directional Format
1421905 EN European Number
1422 ES European Separator
906 ES European Number Separator
1423 ET European Terminator
907 ET European Number Terminator
1424908 AN Arabic Number
1425 CS Common Separator
909 CS Common Number Separator
1426910 NSM Non-Spacing Mark
1427911 BN Boundary Neutral
1428912 B Paragraph Separator
1429913 S Segment Separator
1430914 WS Whitespace
1431915 ON Other Neutrals
1432916
1433917=begin original
1434918
1435This property is always written in the compound form.
919For example, C<\p{BidiClass:R}> matches characters that are normally
1436For example, C<\p{Bidi_Class:R}> matches characters that are normally
920written right to left.
1437written right to left. Unlike the
1438C<L</General_Category>> property, this
1439property can have more values added in a future Unicode release. Those
1440listed above comprised the complete set for many Unicode releases, but
1441others were added in Unicode 6.3; you can always find what the
1442current ones are in L<perluniprops>. And
1443L<https://www.unicode.org/reports/tr9/> describes how to use them.
1444921
1445922=end original
1446923
1447この特性は常に複合形式でかれます。
924たとえば、C<\p{BidiClass:R}> 右から左に書く文字にマッチします。
1448たとえば、C<\p{Bidi_Class:R}> は通常右から左に書く文字にマッチします。
1449C<L</General_Category>> 特性とは異なり、
1450この特性は将来リリースされる Unicode でさらに値が追加されるかもしれません。
1451これらの上述したものは何回もの Unicode のリリースの間完全な一覧でしたが、
1452その他の物は Unicode 6.3 で追加されたものです;
1453現在の内容についてはいつでも L<perluniprops> で確認できます。
1454これらの使い方については
1455L<https://www.unicode.org/reports/tr9/> に記述されています。
1456925
1457=head3 B<Scripts>
926=item Scripts
1458927
1459(B<用字>)
1460
1461928=begin original
1462929
1463The world's languages are written in many different scripts. This sentence
930The script names which can be used by C<\p{...}> and C<\P{...}>,
1464(unless you're reading it in translation) is written in Latin, while Russian is
931such as in C<\p{Latin}> or C<\p{Cyrillic}>, are as follows:
1465written in Cyrillic, and Greek is written in, well, Greek; Japanese mainly in
1466Hiragana or Katakana. There are many more.
1467932
1468933=end original
1469934
1470世界言語は多くの異った用字書かれています。
935C<\p{Latin}> や C<\p{Cyrillic}> よう、C<\p{...}> と C<\P{...}>
1471この文は(訳文を読んいない限り)ラテン文で書かれていますが、ロシア語
936使うのできる用以下の通り:
1472キリル文字で書かれています; そしてギリシャ語は、ええと、ギリシャ文字です;
1473日本語は主にひらがなやカタカナで書かれています。
1474もっとたくさんあります。
1475937
1476=begin original
938 Arabic
939 Armenian
940 Balinese
941 Bengali
942 Bopomofo
943 Braille
944 Buginese
945 Buhid
946 CanadianAboriginal
947 Cherokee
948 Coptic
949 Cuneiform
950 Cypriot
951 Cyrillic
952 Deseret
953 Devanagari
954 Ethiopic
955 Georgian
956 Glagolitic
957 Gothic
958 Greek
959 Gujarati
960 Gurmukhi
961 Han
962 Hangul
963 Hanunoo
964 Hebrew
965 Hiragana
966 Inherited
967 Kannada
968 Katakana
969 Kharoshthi
970 Khmer
971 Lao
972 Latin
973 Limbu
974 LinearB
975 Malayalam
976 Mongolian
977 Myanmar
978 NewTaiLue
979 Nko
980 Ogham
981 OldItalic
982 OldPersian
983 Oriya
984 Osmanya
985 PhagsPa
986 Phoenician
987 Runic
988 Shavian
989 Sinhala
990 SylotiNagri
991 Syriac
992 Tagalog
993 Tagbanwa
994 TaiLe
995 Tamil
996 Telugu
997 Thaana
998 Thai
999 Tibetan
1000 Tifinagh
1001 Ugaritic
1002 Yi
14771003
1478The Unicode C<Script> and C<Script_Extensions> properties give what
1004=item Extended property classes
1479script a given character is in. The C<Script_Extensions> property is an
1480improved version of C<Script>, as demonstrated below. Either property
1481can be specified with the compound form like
1482C<\p{Script=Hebrew}> (short: C<\p{sc=hebr}>), or
1483C<\p{Script_Extensions=Javanese}> (short: C<\p{scx=java}>).
1484In addition, Perl furnishes shortcuts for all
1485C<Script_Extensions> property names. You can omit everything up through
1486the equals (or colon), and simply write C<\p{Latin}> or C<\P{Cyrillic}>.
1487(This is not true for C<Script>, which is required to be
1488written in the compound form. Prior to Perl v5.26, the single form
1489returned the plain old C<Script> version, but was changed because
1490C<Script_Extensions> gives better results.)
14911005
1492=end original
1493
1494Unicode の C<Script> と C<Script_Extensions> 特性は、指定された
1495文字の中にある用字を示します。
1496C<Script_Extensions> 特性は、後述するように、
1497C<Script> の改良版です。
1498それぞれの用字は C<\p{Script=Hebrew}> (短縮: C<\p{sc=hebr}>)
1499または
1500C<\p{Script_Extensions=Javanese}> (short: C<\p{scx=java}>) のような
1501複合形式で指定できます。
1502さらに Perl は、すべての C<Script_Extensions> 用字のショートカットを
1503提供します。
1504等号(またはコロン)までのすべてを省略できます;
1505そして単に C<\p{Latin}> や C<\P{Cyrillic}> と書けます。
1506(これは C<Script> では正しくありません; これは
1507複合形式で書かれることを要求します。
1508Perl v5.26 より前は、単一形式は昔ながらの単純な
1509C<Script> 版を返していましたが、C<Script_Extensions> が
1510より良い結果を返すので、変更されました。)
1511
15121006=begin original
15131007
1514The difference between these two properties involves characters that are
1008Extended property classes can supplement the basic
1515used in multiple scripts. For example the digits '0' through '9' are
1009properties, defined by the F<PropList> Unicode database:
1516used in many parts of the world. These are placed in a script named
1517C<Common>. Other characters are used in just a few scripts. For
1518example, the C<"KATAKANA-HIRAGANA DOUBLE HYPHEN"> is used in both Japanese
1519scripts, Katakana and Hiragana, but nowhere else. The C<Script>
1520property places all characters that are used in multiple scripts in the
1521C<Common> script, while the C<Script_Extensions> property places those
1522that are used in only a few scripts into each of those scripts; while
1523still using C<Common> for those used in many scripts. Thus both these
1524match:
15251010
15261011=end original
15271012
1528これら二つの特性の違いは、複数用字で使われている文字に関係があります。
1013拡張特性クラス基本特性を補完しUnicode データベース
1529例えば、数字 '0' から '9' は世界中の大部分使われています
1014F<PropList>定義されています:
1530これらは C<Common> という名前の用字に置かれています。
1531その他の文字はほんのいくつかの用字でのみ使われています。
1532例えば、C<"KATAKANA-HIRAGANA DOUBLE HYPHEN"> は日本語の二つの用字
1533Katakana と Hiragana の両方で使われていますが、その他では使われていません。
1534C<Script> 特性は、C<Common> 用字にあって、複数のの用字で使われている
1535全ての文字に与えられています;
1536一方 C<Script_Extensions> 特性は、それらの用字それぞれのほんのいくつかの
1537用字でのみ使われているものに与えられます;
1538一方多くの用字で使われているものについては未だ C<Common> が使われています。
1539従ってこれらは両方ともマッチングし:
15401015
1541 "0" =~ /\p{sc=Common}/ # Matches
1016 ASCIIHexDigit
1542 "0" =~ /\p{scx=Common}/ # Matches
1017 BidiControl
1018 Dash
1019 Deprecated
1020 Diacritic
1021 Extender
1022 HexDigit
1023 Hyphen
1024 Ideographic
1025 IDSBinaryOperator
1026 IDSTrinaryOperator
1027 JoinControl
1028 LogicalOrderException
1029 NoncharacterCodePoint
1030 OtherAlphabetic
1031 OtherDefaultIgnorableCodePoint
1032 OtherGraphemeExtend
1033 OtherIDStart
1034 OtherIDContinue
1035 OtherLowercase
1036 OtherMath
1037 OtherUppercase
1038 PatternSyntax
1039 PatternWhiteSpace
1040 QuotationMark
1041 Radical
1042 SoftDotted
1043 STerm
1044 TerminalPunctuation
1045 UnifiedIdeograph
1046 VariationSelector
1047 WhiteSpace
15431048
15441049=begin original
15451050
1546and only the first of these match:
1051and there are further derived properties:
15471052
15481053=end original
15491054
1550そしてこれらは最初だけマッチングします:
1055の他にも派生た特性あります:
15511056
1552 "\N{KATAKANA-HIRAGANA DOUBLE HYPHEN}" =~ /\p{sc=Common} # Matches
1057 Alphabetic = Lu + Ll + Lt + Lm + Lo + Nl + OtherAlphabetic
1553 "\N{KATAKANA-HIRAGANA DOUBLE HYPHEN}" =~ /\p{scx=Common} # No match
1058 Lowercase = Ll + OtherLowercase
1059 Uppercase = Lu + OtherUppercase
1060 Math = Sm + OtherMath
15541061
1555=begin original
1062 IDStart = Lu + Ll + Lt + Lm + Lo + Nl + OtherIDStart
1063 IDContinue = IDStart + Mn + Mc + Nd + Pc + OtherIDContinue
15561064
1557And only the last two of these match:
1065 DefaultIgnorableCodePoint
1066 = OtherDefaultIgnorableCodePoint
1067 + Cf + Cc + Cs + Noncharacters + VariationSelector
1068 - WhiteSpace - FFF9..FFFB (Annotation Characters)
15581069
1559=end original
1070 Any = Any code points (i.e. U+0000 to U+10FFFF)
1071 Assigned = Any non-Cn code points (i.e. synonym for \P{Cn})
1072 Unassigned = Synonym for \p{Cn}
1073 ASCII = ASCII (i.e. U+0000 to U+007F)
15601074
1561それこれらは最後の二つだけがマッチングします:
1075 Common = Any character (or unassigned code point)
1076 not explicitly assigned to a script
15621077
1563 "\N{KATAKANA-HIRAGANA DOUBLE HYPHEN}" =~ /\p{sc=Hiragana} # No match
1078=item Use of "Is" Prefix
1564 "\N{KATAKANA-HIRAGANA DOUBLE HYPHEN}" =~ /\p{sc=Katakana} # No match
1565 "\N{KATAKANA-HIRAGANA DOUBLE HYPHEN}" =~ /\p{scx=Hiragana} # Matches
1566 "\N{KATAKANA-HIRAGANA DOUBLE HYPHEN}" =~ /\p{scx=Katakana} # Matches
15671079
15681080=begin original
15691081
1570C<Script_Extensions> is thus an improved C<Script>, in which there are
1082For backward compatibility (with Perl 5.6), all properties mentioned
1571fewer characters in the C<Common> script, and correspondingly more in
1083so far may have C<Is> prepended to their name, so C<\P{IsLu}>, for
1572other scripts. It is new in Unicode version 6.0, and its data are likely
1084example, is equal to C<\P{Lu}>.
1573to change significantly in later releases, as things get sorted out.
1574New code should probably be using C<Script_Extensions> and not plain
1575C<Script>. If you compile perl with a Unicode release that doesn't have
1576C<Script_Extensions>, the single form Perl extensions will instead refer
1577to the plain C<Script> property. If you compile with a version of
1578Unicode that doesn't have the C<Script> property, these extensions will
1579not be defined at all.
15801085
15811086=end original
15821087
1583ように C<Script_Extensions> は改良された C<Script> で、
1088(Perl 5.6 と)後方互換性のため、すべての特性はその名前の前に C<Is>
1584C<Common> 用字にある文字はより少な、それに応じて他の用字の文字は
1089ことができます。
1585より多くなっています。
1090したがって、C<\P{IsLu}> は C<\P{Lu}> と等価です。
1586これは Unicode バージョン 6.0 からの新しいもので、そのデータは
1587将来のリリースで整理されて大きく変更される可能性が高いです。
1588新しいコードはおそらく、単なる C<Script> ではなく
1589C<Script_Extensions> を使うべきです。
1590C<Script_Extensions> がない Unicode のリリースで perl を
1591コンパイルしている場合、単一形式の Perl 拡張は代わりに
1592単なる C<Script> 特性を参照します。
1593C<Script> 特性がないバージョンでコンパイルしている場合、
1594これらの拡張は何も定義されません。
15951091
1596=begin original
1092=item Blocks
15971093
1598(Actually, besides C<Common>, the C<Inherited> script, contains
1599characters that are used in multiple scripts. These are modifier
1600characters which inherit the script value
1601of the controlling character. Some of these are used in many scripts,
1602and so go into C<Inherited> in both C<Script> and C<Script_Extensions>.
1603Others are used in just a few scripts, so are in C<Inherited> in
1604C<Script>, but not in C<Script_Extensions>.)
1605
1606=end original
1607
1608(実際、C<Common> を除くと、C<Inherited> 用字は複数の用字で使われている
1609文字を含みます。
1610制御文字の用字の値を継承する文字のための修飾文字です。
1611その一部は多くの用字で使われているので、
1612C<Script> と C<Script_Extensions> の両方の中に
1613C<Inherited> が入っています。
1614その他のものはいくつかの用字でのみ使われているので、
1615C<Script> の C<Inherited> にはありますが、
1616C<Script_Extensions> にはありません。)
1617
16181094=begin original
16191095
1620It is worth stressing that there are several different sets of digits in
1621Unicode that are equivalent to 0-9 and are matchable by C<\d> in a
1622regular expression. If they are used in a single language only, they
1623are in that language's C<Script> and C<Script_Extensions>. If they are
1624used in more than one script, they will be in C<sc=Common>, but only
1625if they are used in many scripts should they be in C<scx=Common>.
1626
1627=end original
1628
1629Unicode には、0-9 と等価で、正規表現内で C<\d> にマッチングできる数字の
1630集合がいくつかあることは強調する価値があります。
1631それらが単一の言語だけで使われた場合、それらはその言語の
1632C<Script> と C<Script_Extensions> です。
1633これらが複数の用字で使われている場合、
1634それらは C<sc=Common> の中にありますが、
1635C<scx=Common> にあるべき多くの用字で使われている場合のみです。
1636
1637=begin original
1638
1639The explanation above has omitted some detail; refer to UAX#24 "Unicode
1640Script Property": L<https://www.unicode.org/reports/tr24>.
1641
1642=end original
1643
1644前述の説明は一部の詳細を省略しています;
1645UAX#24 "Unicode Script Property": L<https://www.unicode.org/reports/tr24> を
1646参照してください。
1647
1648=begin original
1649
1650A complete list of scripts and their shortcuts is in L<perluniprops>.
1651
1652=end original
1653
1654用字とその省略形の完全な一覧は L<perluniprops> にあります。
1655
1656=head3 B<Use of the C<"Is"> Prefix>
1657
1658(B<C<"Is"> 接頭辞の使用>)
1659
1660=begin original
1661
1662For backward compatibility (with ancient Perl 5.6), all properties writable
1663without using the compound form mentioned
1664so far may have C<Is> or C<Is_> prepended to their name, so C<\P{Is_Lu}>, for
1665example, is equal to C<\P{Lu}>, and C<\p{IsScript:Arabic}> is equal to
1666C<\p{Arabic}>.
1667
1668=end original
1669
1670(とても古い Perl 5.6 との)後方互換性のため、
1671これまでのところ記述している複合形式を使うことなく書き込み可能な
1672すべての特性はその名前の前に C<Is>
1673または C<Is_> を置くことができます; したがって、C<\P{Is_Lu}> は C<\P{Lu}> と
1674等価で、C<\p{IsScript:Arabic}> は C<\p{Arabic}> と等価です。
1675
1676=head3 B<Blocks>
1677
1678(B<ブロック>)
1679
1680=begin original
1681
16821096In addition to B<scripts>, Unicode also defines B<blocks> of
16831097characters. The difference between scripts and blocks is that the
16841098concept of scripts is closer to natural languages, while the concept
1685of blocks is more of an artificial grouping based on groups of Unicode
1099of blocks is more of an artificial grouping based on groups of 256
1686characters with consecutive ordinal values. For example, the C<"Basic Latin">
1100Unicode characters. For example, the C<Latin> script contains letters
1687block is all the characters whose ordinals are between 0 and 127, inclusive; in
1101from many blocks but does not contain all the characters from those
1688other words, the ASCII characters. The C<"Latin"> script contains some letters
1102blocks. It does not, for example, contain digits, because digits are
1689from this as well as several other blocks, like C<"Latin-1 Supplement">,
1103shared across many scripts. Digits and similar groups, like
1690C<"Latin Extended-A">, I<etc.>, but it does not contain all the characters from
1104punctuation, are in a category called C<Common>.
1691those blocks. It does not, for example, contain the digits 0-9, because
1692those digits are shared across many scripts, and hence are in the
1693C<Common> script.
16941105
16951106=end original
16961107
16971108B<用字> に加え、Unicode では文字の B<ブロック> を定義しています。
16981109用字とブロックの違いは、用字のコンセプトが自然言語に
1699密着したものであるのに対して、ブロックのコンセプトは連続した番号を持つ
1110密着したものであるのに対して、ブロックのコンセプトは 256 の
17001111Unicode 文字のグループに基づいたより人工的なグループ分けであることです。
1701たとえば、C<"Basic Latin"> ブロックは番号 0 から 127 まで全ての文字です;
1112たとえば、C<Latin> 用字は多くのブロックからの文字を含んいまが、
1702言い換えると ASCII 文字です。
1703C<"Latin"> 用字は、このブロックの文字と、C<"Latin-1 Supplement">,
1704C<"Latin Extended-A"> などのその他のいくつかのブロックの文字を含んでいますが、
17051113それらのブロックのすべての文字を含んではいません。
1706例を挙げると、数字 0-9 は多くの用字を越えて共有されているので、
1114例を挙げると、数字は多くの用字を越えて共有されているので、
1707(Latin 用字は)数字を含まないので、これらは C<Common> 用字にあります
1115(Latin 用字は)数字を含せん
1116数字と、句読点のような同様のグループは C<Common> と呼ばれる
1117カテゴリにあります。
17081118
17091119=begin original
17101120
1711For more about scripts versus blocks, see UAX#24 "Unicode Script Property":
1121For more about scripts, see the UAX#24 "Script Names":
1712L<https://www.unicode.org/reports/tr24>
17131122
17141123=end original
17151124
1716用字とブロックに違いに関する細につ
1125用字のより情報 UTR #24 "Script Names" を参照してください:
1717UAX#24 "Unicode Script Property"
1718L<https://www.unicode.org/reports/tr24> を参照してください。
17191126
1720=begin original
1127 http://www.unicode.org/reports/tr24/
17211128
1722The C<Script_Extensions> or C<Script> properties are likely to be the
1723ones you want to use when processing
1724natural language; the C<Block> property may occasionally be useful in working
1725with the nuts and bolts of Unicode.
1726
1727=end original
1728
1729C<Script_Extensions> や C<Script> 特性は自然言語を処理するときにおそらく
1730使いたいと思うようなものです;
1731C<Block> 特性は Unicode の基本的な部分で動作させるのに時々有用です。
1732
17331129=begin original
17341130
1735Block names are matched in the compound form, like C<\p{Block: Arrows}> or
1131For more about blocks, see:
1736C<\p{Blk=Hebrew}>. Unlike most other properties, only a few block names have a
1737Unicode-defined short name.
17381132
17391133=end original
17401134
1741ブロック名は C<\p{Block: Arrows}> や C<\p{Blk=Hebrew}> のような
1135ブロックについてのより詳しい情報は:
1742復号形式でマッチングします。
1743その他のほとんどの特性と違って、いくつかのブロック名だけが Unicode が
1744定義した短い名前を持ちます。
17451136
1746=begin original
1137 http://www.unicode.org/Public/UNIDATA/Blocks.txt
17471138
1748Perl also defines single form synonyms for the block property in cases
1749where these do not conflict with something else. But don't use any of
1750these, because they are unstable. Since these are Perl extensions, they
1751are subordinate to official Unicode property names; Unicode doesn't know
1752nor care about Perl's extensions. It may happen that a name that
1753currently means the Perl extension will later be changed without warning
1754to mean a different Unicode property in a future version of the perl
1755interpreter that uses a later Unicode release, and your code would no
1756longer work. The extensions are mentioned here for completeness: Take
1757the block name and prefix it with one of: C<In> (for example
1758C<\p{Blk=Arrows}> can currently be written as C<\p{In_Arrows}>); or
1759sometimes C<Is> (like C<\p{Is_Arrows}>); or sometimes no prefix at all
1760(C<\p{Arrows}>). As of this writing (Unicode 9.0) there are no
1761conflicts with using the C<In_> prefix, but there are plenty with the
1762other two forms. For example, C<\p{Is_Hebrew}> and C<\p{Hebrew}> mean
1763C<\p{Script_Extensions=Hebrew}> which is NOT the same thing as
1764C<\p{Blk=Hebrew}>. Our
1765advice used to be to use the C<In_> prefix as a single form way of
1766specifying a block. But Unicode 8.0 added properties whose names begin
1767with C<In>, and it's now clear that it's only luck that's so far
1768prevented a conflict. Using C<In> is only marginally less typing than
1769C<Blk:>, and the latter's meaning is clearer anyway, and guaranteed to
1770never conflict. So don't take chances. Use C<\p{Blk=foo}> for new
1771code. And be sure that block is what you really really want to do. In
1772most cases scripts are what you want instead.
1773
1774=end original
1775
1776Perl はまた、他のものと競合しない場合には、
1777ブロック特性に対して単一形式の同義語を定義します。
1778しかし、これらは不安定なので、使わないでください。
1779これらは Perl の拡張なので、公式の Unicode 特性名の下位にあたります;
1780Unicode は Perl の拡張を認識しませんし、気にしません。
1781現在は Perl 拡張を意味する名前が、将来のUnicodeリリースを使用する
1782perlインタプリタの将来のバージョンでは、警告なしに別の Unicode 特性を
1783意味するように変更され、コードが動作しなくなる可能性があります。
1784ここでは、完全性のために拡張について説明します:
1785ロック名の前に次のいずれかの接頭辞を付けます:
1786C<In> (例えば C<\p{Blk=Arrows}> は現在 C<\p{In_Arrows}> と書けます);
1787時々 C<Is> (C<\p{Is_Arrows}> のように);
1788時々全く接頭辞なし (C<\p{Arrows}>)。
1789この文書の執筆時点 (Unicode 9.0) では、C<In_> 接頭辞の使用と
1790競合することはありませんが、他の二つの形式では多くの競合があります。
1791例えば、C<\p{Is_Hebrew}> および C<\p{Hebrew}> は、
1792C<\p{Script_Extensions=Hebrew}> を意味しますが、C<\p{Blk=Hebrew}> と
1793同じものでは「ありません」。
1794以前勧めていたのは、ブロックを指定する単一形式として
1795C<In_> 接頭辞を使うことでした。
1796しかし Unicode 8.0 では、名前が C<In> で始まる特性が追加されたため、
1797今まで競合を回避できていたのは単に幸運なだけだったことが
1798明らかになりました。
1799C<In> を使用することは、C<Blk:> よりもわずかにタイプ数が少ないだけで、
1800とにかく後者の意味はより明確で、決して衝突しないことが保証されます。
1801だから、危険を冒さないでください。
1802新しいコードには C<\p{Blk=foo}> を使ってください。
1803そして、これが本当に本当にやりたいことであることを確認してください。
1804ほとんどの場合、本当に必要なものはそうではなく用字です。
1805
18061139=begin original
18071140
1808A complete list of blocks is in L<perluniprops>.
1141Block names are given with the C<In> prefix. For example, the
1142Katakana block is referenced via C<\p{InKatakana}>. The C<In>
1143prefix may be omitted if there is no naming conflict with a script
1144or any other property, but it is recommended that C<In> always be used
1145for block tests to avoid confusion.
18091146
18101147=end original
18111148
1812ブロックの完全な一覧L<perluniprops> にあります。
1149ブロックC<In> 接頭辞ととも与えられます。
1150たとえば、カタカナブロックは C<\p{InKatakana}> として参照されます。
1151C<In> 接頭辞は用字や他のプロパティと衝突しなければ省略することも
1152可能ですが、混乱のないブロックテストのために常に C<In> を使うことを
1153お勧めします。
18131154
1814=head3 B<Other Properties>
1815
1816(B<その他の特性>)
1817
18181155=begin original
18191156
1820There are many more properties than the very basic ones described here.
1157These block names are supported:
1821A complete list is in L<perluniprops>.
18221158
18231159=end original
18241160
1825ここで記述したとても基本的なもよりもとても多くの特性あります
1161以下ブロック名サポートされています:
1826完全な一覧は L<perluniprops> です。
18271162
1828=begin original
1163 InAegeanNumbers
1164 InAlphabeticPresentationForms
1165 InAncientGreekMusicalNotation
1166 InAncientGreekNumbers
1167 InArabic
1168 InArabicPresentationFormsA
1169 InArabicPresentationFormsB
1170 InArabicSupplement
1171 InArmenian
1172 InArrows
1173 InBalinese
1174 InBasicLatin
1175 InBengali
1176 InBlockElements
1177 InBopomofo
1178 InBopomofoExtended
1179 InBoxDrawing
1180 InBraillePatterns
1181 InBuginese
1182 InBuhid
1183 InByzantineMusicalSymbols
1184 InCJKCompatibility
1185 InCJKCompatibilityForms
1186 InCJKCompatibilityIdeographs
1187 InCJKCompatibilityIdeographsSupplement
1188 InCJKRadicalsSupplement
1189 InCJKStrokes
1190 InCJKSymbolsAndPunctuation
1191 InCJKUnifiedIdeographs
1192 InCJKUnifiedIdeographsExtensionA
1193 InCJKUnifiedIdeographsExtensionB
1194 InCherokee
1195 InCombiningDiacriticalMarks
1196 InCombiningDiacriticalMarksSupplement
1197 InCombiningDiacriticalMarksforSymbols
1198 InCombiningHalfMarks
1199 InControlPictures
1200 InCoptic
1201 InCountingRodNumerals
1202 InCuneiform
1203 InCuneiformNumbersAndPunctuation
1204 InCurrencySymbols
1205 InCypriotSyllabary
1206 InCyrillic
1207 InCyrillicSupplement
1208 InDeseret
1209 InDevanagari
1210 InDingbats
1211 InEnclosedAlphanumerics
1212 InEnclosedCJKLettersAndMonths
1213 InEthiopic
1214 InEthiopicExtended
1215 InEthiopicSupplement
1216 InGeneralPunctuation
1217 InGeometricShapes
1218 InGeorgian
1219 InGeorgianSupplement
1220 InGlagolitic
1221 InGothic
1222 InGreekExtended
1223 InGreekAndCoptic
1224 InGujarati
1225 InGurmukhi
1226 InHalfwidthAndFullwidthForms
1227 InHangulCompatibilityJamo
1228 InHangulJamo
1229 InHangulSyllables
1230 InHanunoo
1231 InHebrew
1232 InHighPrivateUseSurrogates
1233 InHighSurrogates
1234 InHiragana
1235 InIPAExtensions
1236 InIdeographicDescriptionCharacters
1237 InKanbun
1238 InKangxiRadicals
1239 InKannada
1240 InKatakana
1241 InKatakanaPhoneticExtensions
1242 InKharoshthi
1243 InKhmer
1244 InKhmerSymbols
1245 InLao
1246 InLatin1Supplement
1247 InLatinExtendedA
1248 InLatinExtendedAdditional
1249 InLatinExtendedB
1250 InLatinExtendedC
1251 InLatinExtendedD
1252 InLetterlikeSymbols
1253 InLimbu
1254 InLinearBIdeograms
1255 InLinearBSyllabary
1256 InLowSurrogates
1257 InMalayalam
1258 InMathematicalAlphanumericSymbols
1259 InMathematicalOperators
1260 InMiscellaneousMathematicalSymbolsA
1261 InMiscellaneousMathematicalSymbolsB
1262 InMiscellaneousSymbols
1263 InMiscellaneousSymbolsAndArrows
1264 InMiscellaneousTechnical
1265 InModifierToneLetters
1266 InMongolian
1267 InMusicalSymbols
1268 InMyanmar
1269 InNKo
1270 InNewTaiLue
1271 InNumberForms
1272 InOgham
1273 InOldItalic
1274 InOldPersian
1275 InOpticalCharacterRecognition
1276 InOriya
1277 InOsmanya
1278 InPhagspa
1279 InPhoenician
1280 InPhoneticExtensions
1281 InPhoneticExtensionsSupplement
1282 InPrivateUseArea
1283 InRunic
1284 InShavian
1285 InSinhala
1286 InSmallFormVariants
1287 InSpacingModifierLetters
1288 InSpecials
1289 InSuperscriptsAndSubscripts
1290 InSupplementalArrowsA
1291 InSupplementalArrowsB
1292 InSupplementalMathematicalOperators
1293 InSupplementalPunctuation
1294 InSupplementaryPrivateUseAreaA
1295 InSupplementaryPrivateUseAreaB
1296 InSylotiNagri
1297 InSyriac
1298 InTagalog
1299 InTagbanwa
1300 InTags
1301 InTaiLe
1302 InTaiXuanJingSymbols
1303 InTamil
1304 InTelugu
1305 InThaana
1306 InThai
1307 InTibetan
1308 InTifinagh
1309 InUgaritic
1310 InUnifiedCanadianAboriginalSyllabics
1311 InVariationSelectors
1312 InVariationSelectorsSupplement
1313 InVerticalForms
1314 InYiRadicals
1315 InYiSyllables
1316 InYijingHexagramSymbols
18291317
1830Unicode defines all its properties in the compound form, so all single-form
1831properties are Perl extensions. Most of these are just synonyms for the
1832Unicode ones, but some are genuine extensions, including several that are in
1833the compound form. And quite a few of these are actually recommended by Unicode
1834(in L<https://www.unicode.org/reports/tr18>).
1835
1836=end original
1837
1838Unicode は、複合形式ですべての特性を定義するので、
1839単一形式の特性はすべて Perl 拡張になります。
1840これらのほとんどは Unicode のものの同義語にすぎませんが、いくつかは
1841本物の拡張であり、複合形式のものもあります。
1842そしてこれらのいくつかは実際に Unicode
1843(L<https://www.unicode.org/reports/tr18>)で推奨されています。
1844
1845=begin original
1846
1847This section gives some details on all extensions that aren't just
1848synonyms for compound-form Unicode properties
1849(for those properties, you'll have to refer to the
1850L<Unicode Standard|https://www.unicode.org/reports/tr44>.
1851
1852=end original
1853
1854この節では、単に複合形式の Unicode 特性の同義語ではないすべての
1855拡張機能について詳しく説明します (これらの特性については、
1856L<Unicode Standard https://www.unicode.org/reports/tr44> を
1857参照してください)。
1858
1859=over
1860
1861=item B<C<\p{All}>>
1862
1863=begin original
1864
1865This matches every possible code point. It is equivalent to C<qr/./s>.
1866Unlike all the other non-user-defined C<\p{}> property matches, no
1867warning is ever generated if this is property is matched against a
1868non-Unicode code point (see L</Beyond Unicode code points> below).
1869
1870=end original
1871
1872これは全ての符号位置にマッチングします。
1873これは C<qr/./s> と等価です。
1874その他全てのユーザー定義でない C<\p{}> 特性のマッチングと異なり、
1875この特性はたとえ非 Unicode 符号位置に対してマッチングしても警告は
1876発生しません (後述する L</Beyond Unicode code points> 参照)。
1877
1878=item B<C<\p{Alnum}>>
1879
1880=begin original
1881
1882This matches any C<\p{Alphabetic}> or C<\p{Decimal_Number}> character.
1883
1884=end original
1885
1886これは任意の C<\p{Alphabetic}> または C<\p{Decimal_Number}> 文字に
1887マッチングします。
1888
1889=item B<C<\p{Any}>>
1890
1891=begin original
1892
1893This matches any of the 1_114_112 Unicode code points. It is a synonym
1894for C<\p{Unicode}>.
1895
1896=end original
1897
1898これは任意の 1_114_112 Unicode 符号位置にマッチングします。
1899これは C<\p{Unicode}> の同義語です。
1900
1901=item B<C<\p{ASCII}>>
1902
1903=begin original
1904
1905This matches any of the 128 characters in the US-ASCII character set,
1906which is a subset of Unicode.
1907
1908=end original
1909
1910これは、Unicode のサブセットである、US-ASCII 文字集合の 128 文字に
1911マッチングします。
1912
1913=item B<C<\p{Assigned}>>
1914
1915=begin original
1916
1917This matches any assigned code point; that is, any code point whose L<general
1918category|/General_Category> is not C<Unassigned> (or equivalently, not C<Cn>).
1919
1920=end original
1921
1922これは任意の割り当てられた符号位置にマッチングします; つまり、
1923L<general category|/General_Category> が
1924C<Unassigned> ではない(または同等に C<Cn> ではない) 符号位置です。
1925
1926=item B<C<\p{Blank}>>
1927
1928=begin original
1929
1930This is the same as C<\h> and C<\p{HorizSpace}>: A character that changes the
1931spacing horizontally.
1932
1933=end original
1934
1935これは C<\h> および C<\p{HorizSpace}> と同じです: スペースを垂直に変更する
1936文字です。
1937
1938=item B<C<\p{Decomposition_Type: Non_Canonical}>> (Short: C<\p{Dt=NonCanon}>)
1939
1940=begin original
1941
1942Matches a character that has any of the non-canonical decomposition
1943types. Canonical decompositions are introduced in the
1944L</Extended Grapheme Clusters (Logical characters)> section above.
1945However, many more characters have a different type of decomposition,
1946generically called "compatible" decompositions, or "non-canonical". The
1947sequences that form these decompositions are not considered canonically
1948equivalent to the pre-composed character. An example is the
1949C<"SUPERSCRIPT ONE">. It is somewhat like a regular digit 1, but not
1950exactly; its decomposition into the digit 1 is called a "compatible"
1951decomposition, specifically a "super" (for "superscript") decomposition.
1952There are several such compatibility decompositions (see
1953L<https://www.unicode.org/reports/tr44>). S<C<\p{Dt: Non_Canon}>> is a
1954Perl extension that uses just one name to refer to the union of all of
1955them.
1956
1957=end original
1958
1959非正準分解型の文字にマッチングします。
1960正準分解は前述の L</Extended Grapheme Clusters (Logical characters)> 節で
1961説明しました。
1962しかし、多くの文字は異なる種類の分解を持ち、
1963一般的に「互換」分解あるいは「非正準」分解と呼ばれます。
1964これらの分解を形成する並びは合成済文字への正準等価ではないと考えられます。
1965例えば、C<"SUPERSCRIPT ONE"> です。
1966これは普通の数字 1 のようなものですが、正確ではありません;
1967これの数字 1 への分解は
1968「互換」分解と呼ばれ、特に「スーパー」("superscript" から)分解と呼ばれます。
1969このような互換分解(L<https://www.unicode.org/reports/tr44>を参照)は
1970いくつかあります。
1971S<C<\p{Dt: Non_Canon}>> は、これら全ての和集合を一つの名前で参照するために
1972使う Perl 拡張です。
1973
1974=begin original
1975
1976Most Unicode characters don't have a decomposition, so their
1977decomposition type is C<"None">. Hence, C<Non_Canonical> is equivalent
1978to
1979
1980=end original
1981
1982ほとんどの Unicode 文字は分解を持たないので、それらの分解型は C<"None"> です。
1983従って、C<Non_Canonical> は次と等価です:
1984
1985 qr/(?[ \P{DT=Canonical} - \p{DT=None} ])/
1986
1987=begin original
1988
1989(Note that one of the non-canonical decompositions is named "compat",
1990which could perhaps have been better named "miscellaneous". It includes
1991just the things that Unicode couldn't figure out a better generic name
1992for.)
1993
1994=end original
1995
1996(非正準分解の一つは "compat" という名前で、おそらく
1997"miscellaneous" という名前の方がよかったものです。
1998これは、Unicode がよりよい名前を見つけられなかったものを
1999含んでいます。)
2000
2001=item B<C<\p{Graph}>>
2002
2003=begin original
2004
2005Matches any character that is graphic. Theoretically, this means a character
2006that on a printer would cause ink to be used.
2007
2008=end original
2009
2010任意の図形文字にマッチングします。
2011理論的には、これはプリンタがインクを使うことになる文字を意味します。
2012
2013=item B<C<\p{HorizSpace}>>
2014
2015=begin original
2016
2017This is the same as C<\h> and C<\p{Blank}>: a character that changes the
2018spacing horizontally.
2019
2020=end original
2021
2022これは C<\h> や C<\p{Blank}> と同じです:
2023スペースを垂直に変更するものです。
2024
2025=item B<C<\p{In=*}>>
2026
2027=begin original
2028
2029This is a synonym for C<\p{Present_In=*}>
2030
2031=end original
2032
2033これは C<\p{Present_In=*}> の同義語です。
2034
2035=item B<C<\p{PerlSpace}>>
2036
2037=begin original
2038
2039This is the same as C<\s>, restricted to ASCII, namely C<S<[ \f\n\r\t]>>
2040and starting in Perl v5.18, a vertical tab.
2041
2042=end original
2043
2044これは C<\s> と同じで、ASCII に制限されます; つまり C<S<[ \f\n\r\t]>>、
2045および、Perl v5.18 から垂直タブ、です。
2046
2047=begin original
2048
2049Mnemonic: Perl's (original) space
2050
2051=end original
2052
2053記憶法: Perl の (元々の) スペース
2054
2055=item B<C<\p{PerlWord}>>
2056
2057=begin original
2058
2059This is the same as C<\w>, restricted to ASCII, namely C<[A-Za-z0-9_]>
2060
2061=end original
2062
2063これは C<\w> と同じで ASCII に制限されます; つまり C<[A-Za-z0-9_]> です。
2064
2065=begin original
2066
2067Mnemonic: Perl's (original) word.
2068
2069=end original
2070
2071記憶法: Perl の (元々の) 単語。
2072
2073=item B<C<\p{Posix...}>>
2074
2075=begin original
2076
2077There are several of these, which are equivalents, using the C<\p{}>
2078notation, for Posix classes and are described in
2079L<perlrecharclass/POSIX Character Classes>.
2080
2081=end original
2082
2083これらのいくつかには Posix クラスのための C<\p{}> 記法を使った
2084等価物があります; これらは
2085L<perlrecharclass/POSIX Character Classes> に記述されています。
2086
2087=item B<C<\p{Present_In: *}>> (Short: C<\p{In=*}>)
2088
2089=begin original
2090
2091This property is used when you need to know in what Unicode version(s) a
2092character is.
2093
2094=end original
2095
2096この特性は、この文字の Unicode バージョンを知る必要があるときに使われます。
2097
2098=begin original
2099
2100The "*" above stands for some Unicode version number, such as
2101C<1.1> or C<12.0>; or the "*" can also be C<Unassigned>. This property will
2102match the code points whose final disposition has been settled as of the
2103Unicode release given by the version number; C<\p{Present_In: Unassigned}>
2104will match those code points whose meaning has yet to be assigned.
2105
2106=end original
2107
2108前述の "*" は、C<1.1> や C<12.0> のような Unicode バージョン番号です;
2109あるいは "*" は C<Unassigned> も取ります。
2110この特性は、最終的な配置がバージョン番号によって指定された Unicode リリースに
2111設定された符号位置にマッチングします;
2112C<\p{Present_In: Unassigned}> は、まだ意味が割り当てられていない符号位置に
2113マッチングします。
2114
2115=begin original
2116
2117For example, C<U+0041> C<"LATIN CAPITAL LETTER A"> was present in the very first
2118Unicode release available, which is C<1.1>, so this property is true for all
2119valid "*" versions. On the other hand, C<U+1EFF> was not assigned until version
21205.1 when it became C<"LATIN SMALL LETTER Y WITH LOOP">, so the only "*" that
2121would match it are 5.1, 5.2, and later.
2122
2123=end original
2124
2125たとえば、C<U+0041> C<"LATIN CAPITAL LETTER A"> は、使用可能な
2126最初の Unicode リリースである C<1.1> から存在しているので、
2127この特性はすべての有効な "*" バージョンに対して真です。
2128一方、C<U+1EFF> は、これが C<"LATIN SMALL LETTER Y WITH LOOP"> になった
2129バージョン 5.1 まで割り当てられていなかったので、
2130これにマッチングする "*" は 5.1, 5.2, およびそれ以降です。
2131
2132=begin original
2133
2134Unicode furnishes the C<Age> property from which this is derived. The problem
2135with Age is that a strict interpretation of it (which Perl takes) has it
2136matching the precise release a code point's meaning is introduced in. Thus
2137C<U+0041> would match only 1.1; and C<U+1EFF> only 5.1. This is not usually what
2138you want.
2139
2140=end original
2141
2142Unicodeは、C<Age> 特性を、これから派生したものから提供します。
2143Age の問題は、(Perl が行う) 厳密な解釈によって、符号位置の
2144意味が導入された正確なリリースと一致することです。
2145したがって、C<U+0041> は、1.1 のみにマッチングし、C<U+1eff> は 5.1 とのみ
2146マッチングします。
2147これは通常、あなたが望むものではありません。
2148
2149=begin original
2150
2151Some non-Perl implementations of the Age property may change its meaning to be
2152the same as the Perl C<Present_In> property; just be aware of that.
2153
2154=end original
2155
2156Age 特性の非 Perl 実装の中には、Perl の C<Present_In> 特性と
2157同じ意味を持つように変更しているものがあります; 知っておいてください。
2158
2159=begin original
2160
2161Another confusion with both these properties is that the definition is not
2162that the code point has been I<assigned>, but that the meaning of the code point
2163has been I<determined>. This is because 66 code points will always be
2164unassigned, and so the C<Age> for them is the Unicode version in which the decision
2165to make them so was made. For example, C<U+FDD0> is to be permanently
2166unassigned to a character, and the decision to do that was made in version 3.1,
2167so C<\p{Age=3.1}> matches this character, as also does C<\p{Present_In: 3.1}> and up.
2168
2169=end original
2170
2171これらの特性に関するもう一つの混乱は、定義は
2172この符号位置が I<割り当てられた> ということではなく、
2173符号位置の意味が I<決定された> ということです。
2174これは、66 の符号位置が常に割り当てられなくなり、
2175それらに対する C<Age> はそう決定された Unicode のバージョンだからです。
2176たとえば、C<U+FDD0> は永続的に文字が割り当てられないことなっていて、
2177この決定はバージョン 3.1 で行われたので、
2178したがって C<\p{Age=3.1}> はこの文字にマッチングし、
2179C<\p{Present_In:3.1}> 以上もマッチングします。
2180
2181=item B<C<\p{Print}>>
2182
2183=begin original
2184
2185This matches any character that is graphical or blank, except controls.
2186
2187=end original
2188
2189制御文字を除く、任意の図形文字か空白にマッチングします。
2190
2191=item B<C<\p{SpacePerl}>>
2192
2193=begin original
2194
2195This is the same as C<\s>, including beyond ASCII.
2196
2197=end original
2198
2199これは C<\s> は同様で、ASCII の範囲外を含みます。
2200
2201=begin original
2202
2203Mnemonic: Space, as modified by Perl. (It doesn't include the vertical tab
2204until v5.18, which both the Posix standard and Unicode consider white space.)
2205
2206=end original
2207
2208記憶法: スペース、Perl によって修正。
2209(これは、v5.18 までは、Posix 標準と Unicode の両方が空白と考える
2210垂直タブを含みません。)
2211
2212=item B<C<\p{Title}>> and B<C<\p{Titlecase}>>
2213
2214(B<C<\p{Title}>> と B<C<\p{Titlecase}>>)
2215
2216=begin original
2217
2218Under case-sensitive matching, these both match the same code points as
2219C<\p{General Category=Titlecase_Letter}> (C<\p{gc=lt}>). The difference
2220is that under C</i> caseless matching, these match the same as
2221C<\p{Cased}>, whereas C<\p{gc=lt}> matches C<\p{Cased_Letter>).
2222
2223=end original
2224
2225大文字小文字を無視するマッチングの下では、これらの両方は
2226C<\p{General Category=Titlecase_Letter}> (C<\p{gc=lt}>) として
2227同じ符号位置にマッチングします。
2228違いは、C</i> 大文字小文字無視マッチングでは、
2229これらのマッチングは C<\p{Cased}> と同じで、
2230C<\p{gc=lt}> は C<\p{Cased_Letter>) にマッチングすると言うことです。
2231
2232=item B<C<\p{Unicode}>>
2233
2234=begin original
2235
2236This matches any of the 1_114_112 Unicode code points.
2237C<\p{Any}>.
2238
2239=end original
2240
2241これは任意の 1_114_112 Unicode 符号位置にマッチングします。
2242これは C<\p{Any}> の同義語です。
2243
2244=item B<C<\p{VertSpace}>>
2245
2246=begin original
2247
2248This is the same as C<\v>: A character that changes the spacing vertically.
2249
2250=end original
2251
2252これは C<\v> と同じです: 垂直の空白を変更する文字です。
2253
2254=item B<C<\p{Word}>>
2255
2256=begin original
2257
2258This is the same as C<\w>, including over 100_000 characters beyond ASCII.
2259
2260=end original
2261
2262これは C<\w> と同じで、ASCII 範囲外の 100_000 を超える文字を含みます。
2263
2264=item B<C<\p{XPosix...}>>
2265
2266=begin original
2267
2268There are several of these, which are the standard Posix classes
2269extended to the full Unicode range. They are described in
2270L<perlrecharclass/POSIX Character Classes>.
2271
2272=end original
2273
2274これらのいくつかには、完全な Unicode の範囲に拡張された標準 Posix クラスが
2275あります; これらは
2276L<perlrecharclass/POSIX Character Classes> に記述されています。
2277
22781318=back
22791319
2280=head2 Comparison of C<\N{...}> and C<\p{name=...}>
2281
2282=begin original
2283
2284Starting in Perl 5.32, you can specify a character by its name in
2285regular expression patterns using C<\p{name=...}>. This is in addition
2286to the longstanding method of using C<\N{...}>. The following
2287summarizes the differences between these two:
2288
2289=end original
2290
2291Perl 5.32 から、C<\p{name=...}> を使って、正規表現パターン内の
2292名前で文字を指定できます。
2293これは、C<\N{...}> を使う長年の方法に追加されます。
2294次に、この二つの違いをまとめます:
2295
2296 \N{...} \p{Name=...}
2297 can interpolate only with eval yes [1]
2298 custom names yes no [2]
2299 name aliases yes yes [3]
2300 named sequences yes yes [4]
2301 name value parsing exact Unicode loose [5]
2302
2303=over
2304
2305=item [1]
2306
2307=begin original
2308
2309The ability to interpolate means you can do something like
2310
2311=end original
2312
2313展開能力とは、次のようなことをして:
2314
2315 qr/\p{na=latin capital letter $which}/
2316
2317=begin original
2318
2319and specify C<$which> elsewhere.
2320
2321=end original
2322
2323C<$which> を別の場所で指定するということです。
2324
2325=item [2]
2326
2327=begin original
2328
2329You can create your own names for characters, and override official
2330ones when using C<\N{...}>. See L<charnames/CUSTOM ALIASES>.
2331
2332=end original
2333
2334文字のための独自の名前を作り、C<\N{...}> を使うときに公式のものを
2335上書きできますう。
2336L<charnames/CUSTOM ALIASES> を参照してください。
2337
2338=item [3]
2339
2340=begin original
2341
2342Some characters have multiple names (synonyms).
2343
2344=end original
2345
2346一部の文字は複数の名前(同義語)を持ちます。
2347
2348=item [4]
2349
2350=begin original
2351
2352Some particular sequences of characters are given a single name, in
2353addition to their individual ones.
2354
2355=end original
2356
2357一部の特別な文字の並びは、個々の名前に加えて、単一の名前を
2358与えられています。
2359
2360=item [5]
2361
2362=begin original
2363
2364Exact name value matching means you have to specify case, hyphens,
2365underscores, and spaces precisely in the name you want. Loose matching
2366follows the Unicode rules
2367L<https://www.unicode.org/reports/tr44/tr44-24.html#UAX44-LM2>,
2368where these are mostly irrelevant. Except for a few outlier character
2369names, these are the same rules as are already used for any other
2370C<\p{...}> property.
2371
2372=end original
2373
2374正確な名前の値のマッチングとは、大文字と小文字、ハイフン、アンダースコア、
2375およびスペースを正確に名前に指定する必要があることを意味します。
2376緩いマッチングは Unicode 規則
2377L<https://www.unicode.org/reports/tr44/tr44-24.html#UAX44-LM2> に従いますが、
2378これらはほとんど無関係です。
2379少数の特殊な文字名を除いて、これらは他の C<\p{...}> 特性に
2380すでに使われている規則と同じです。
2381
2382=back
2383
2384=head2 Wildcards in Property Values
2385
2386(特性値でのワイルドカード)
2387
2388=begin original
2389
2390Starting in Perl 5.30, it is possible to do something like this:
2391
2392=end original
2393
2394Perl 5.30 から、次のようなことが出来るようになりました:
2395
2396 qr!\p{numeric_value=/\A[0-5]\z/}!
2397
2398=begin original
2399
2400or, by abbreviating and adding C</x>,
2401
2402=end original
2403
2404あるいは、省略と C</x> の追加によって:
2405
2406 qr! \p{nv= /(?x) \A [0-5] \z / }!
2407
2408=begin original
2409
2410This matches all code points whose numeric value is one of 0, 1, 2, 3,
24114, or 5. This particular example could instead have been written as
2412
2413=end original
2414
2415これは値が 0, 1, 2, 3, 4, 5 のいずれかである全ての符号位置に
2416マッチングします。
2417この特定の例は代わりに次のように書くことも出来ます:
2418
2419 qr! \A [ \p{nv=0}\p{nv=1}\p{nv=2}\p{nv=3}\p{nv=4}\p{nv=5} ] \z !xx
2420
2421=begin original
2422
2423in earlier perls, so in this case this feature just makes things easier
2424and shorter to write. If we hadn't included the C<\A> and C<\z>, these
2425would have matched things like C<1E<sol>2> because that contains a 1 (as
2426well as a 2). As written, it matches things like subscripts that have
2427these numeric values. If we only wanted the decimal digits with those
2428numeric values, we could say,
2429
2430=end original
2431
2432以前の perl でも書けます; 従ってこの例ではこの機能は単により簡単に
2433短く書けると言うだけです。
2434C<\A> と C<\z> を含めていないと、
2435これらは C<1E<sol>2> のようなものにもマッチングします;
2436(2 と同様) 1 を含んでいるからです。
2437書かれているように、それはこれらの数値を持つ添字のようなものに
2438マッチングします。
2439もしそれらの数値を持つ 10 進数だけが欲しいのであれば、
2440次のように書けます:
2441
2442 qr! (?[ \d & \p{nv=/[0-5]/ ]) }!x
2443
2444=begin original
2445
2446The C<\d> gets rid of needing to anchor the pattern, since it forces the
2447result to only match C<[0-9]>, and the C<[0-5]> further restricts it.
2448
2449=end original
2450
2451C<\d> はパターンにアンカーをする必要性を取り除きます;
2452これは C<[0-9]> のみにマッチングすることを強制し、
2453C<[0-5]> はさらにそれを制限するからです。
2454
2455=begin original
2456
2457The text in the above examples enclosed between the C<"E<sol>">
2458characters can be just about any regular expression. It is independent
2459of the main pattern, so doesn't share any capturing groups, I<etc>. The
2460delimiters for it must be ASCII punctuation, but it may NOT be
2461delimited by C<"{">, nor C<"}"> nor contain a literal C<"}">, as that
2462delimits the end of the enclosing C<\p{}>. Like any pattern, certain
2463other delimiters are terminated by their mirror images. These are
2464C<"(">, C<"[>", and C<"E<lt>">. If the delimiter is any of C<"-">,
2465C<"_">, C<"+">, or C<"\">, or is the same delimiter as is used for the
2466enclosing pattern, it must be preceded by a backslash escape, both
2467fore and aft.
2468
2469=end original
2470
2471C<"E<sol>"> 文字で囲まれた前述の例のテキストは、任意の
2472正規表現にすることができます。
2473これはメインパターンから独立しているため、捕捉グループなどを
2474共有しません。
2475区切り文字は ASCII 句読点でなければなりませんが、C<"{"> や
2476C<"}"> で区切られたり、リテラル C<"}"> を含んだりすることはできません;
2477これは、囲まれた C<\p{}> の終わりを区切るためです。
2478他のパターンと同様に、特定の区切り文字は鏡像で終了します。
2479これらは C<"(">, C<"[>", C<"E<lt>"> です。
2480区切り文字が C<"-">, C<"_">, C<"+">, C<"\"> のいずれかである、
2481または囲まれたパターンに使用されている区切り文字と同じ場合、
2482前後に逆スラッシュエスケープを付けなければなりません。
2483
2484=begin original
2485
2486Beware of using C<"$"> to indicate to match the end of the string. It
2487can too easily be interpreted as being a punctuation variable, like
2488C<$/>.
2489
2490=end original
2491
2492文字列の末尾を示すのに C<"$"> を使う場合は注意してください。
2493これはとても簡単に C<$/> のような句読点変数として解釈されます。
2494
2495=begin original
2496
2497No modifiers may follow the final delimiter. Instead, use
2498L<perlre/(?adlupimnsx-imnsx)> and/or
2499L<perlre/(?adluimnsx-imnsx:pattern)> to specify modifiers.
2500However, certain modifiers are illegal in your wildcard subpattern.
2501The only character set modifier specifiable is C</aa>;
2502any other character set, and C<-m>, and C<p>, and C<s> are all illegal.
2503Specifying modifiers like C<qr/.../gc> that aren't legal in the
2504C<(?...)> notation normally raise a warning, but with wildcard
2505subpatterns, their use is an error. The C<m> modifier is ineffective;
2506everything that matches will be a single line.
2507
2508=end original
2509
2510最後の区切り文字の後に修飾子を置くことは出来ません。
2511修飾子を指定するには代わりに
2512L<perlre/(?adlupimnsx-imnsx)> または
2513L<perlre/(?adluimnsx-imnsx:pattern)> を使ってください。
2514しかし、一部の修飾子はワイルドカードサブパターンでは不正です。
2515指定できる唯一の文字集合修飾子は C</aa> です;
2516その他の文字集合、および C<-m>, C<p>, C<s> は全て不正です。
2517Specifying modifiers like
2518C<(?...)> 記法で、C<qr/.../gc> のような正当でない修飾子を指定すると、
2519通常は警告が発生しますが、ワイルドカードサブパターンでは、
2520これらの使用はエラーです。
2521C<m> 修飾子は影響しません; マッチングする全てのものは単一行です。
2522
2523=begin original
2524
2525By default, your pattern is matched case-insensitively, as if C</i> had
2526been specified. You can change this by saying C<(?-i)> in your pattern.
2527
2528=end original
2529
2530デフォルトでは、パターンは、C</i> が指定されているかのように、
2531大文字小文字を無視してマッチングします。
2532パターンに C<(?-i)> と書くことでこれを変更できます。
2533
2534=begin original
2535
2536There are also certain operations that are illegal. You can't nest
2537C<\p{...}> and C<\P{...}> calls within a wildcard subpattern, and C<\G>
2538doesn't make sense, so is also prohibited.
2539
2540=end original
2541
2542不正である操作もあります。
2543ワイルドカードサブパターンの中で C<\p{...}> と C<\P{...}> を
2544ネストすることはできず、
2545C<\G> は意味がないので禁止されます。
2546
2547
2548=begin original
2549
2550And the C<*> quantifier (or its equivalent C<(0,}>) is illegal.
2551
2552=end original
2553
2554そして C<*> 量指定子 (およびその等価物である C<(0,}>) は不正です。
2555
2556=begin original
2557
2558This feature is not available when the left-hand side is prefixed by
2559C<Is_>, nor for any form that is marked as "Discouraged" in
2560L<perluniprops/Discouraged>.
2561
2562=end original
2563
2564この機能は、左側が C<Is_> を前置されているか、
2565L<perluniprops/Discouraged> で "Discouraged" とマークされている
2566形式では利用できません。
2567
2568=begin original
2569
2570This experimental feature has been added to begin to implement
2571L<https://www.unicode.org/reports/tr18/#Wildcard_Properties>. Using it
2572will raise a (default-on) warning in the
2573C<experimental::uniprop_wildcards> category. We reserve the right to
2574change its operation as we gain experience.
2575
2576=end original
2577
2578この実験的な機能は、
2579L<https://www.unicode.org/reports/tr18/#Wildcard_Properties> の実装を
2580始めるために追加されました。
2581この機能を使うと、C<experimental::uniprop_wildcards> カテゴリで
2582(デフォルトでオンの)警告が発生します。
2583私たちは、経験を積むにつれて、その運用を変更する権利を留保します。
2584
2585=begin original
2586
2587Your subpattern can be just about anything, but for it to have some
2588utility, it should match when called with either or both of
2589a) the full name of the property value with underscores (and/or spaces
2590in the Block property) and some things uppercase; or b) the property
2591value in all lowercase with spaces and underscores squeezed out. For
2592example,
2593
2594=end original
2595
2596サブパターンはどんなものでも構いませんが、サブパターンに何らかの
2597有用性を持たせるためには、a) 特性値の完全名に
2598下線(または Block 特性内のスペース)を使い、
2599一部を大文字にした場合、または b) 特性値をすべて小文字にし、
2600スペースと下線を削除した場合のいずれか、または両方を
2601使って呼び出されたときにマッチングする必要があります。
2602例えば:
2603
2604 qr!\p{Blk=/Old I.*/}!
2605 qr!\p{Blk=/oldi.*/}!
2606
2607=begin original
2608
2609would match the same things.
2610
2611=end original
2612
2613これは同じものにマッチングします。
2614
2615=begin original
2616
2617Another example that shows that within C<\p{...}>, C</x> isn't needed to
2618have spaces:
2619
2620=end original
2621
2622C<\p{...}> の内部を見せるもう一つの例として、C</x> はスペースを
2623持つ必要はありません。
2624
2625 qr!\p{scx= /Hebrew|Greek/ }!
2626
2627=begin original
2628
2629To be safe, we should have anchored the above example, to prevent
2630matches for something like C<Hebrew_Braille>, but there aren't
2631any script names like that, so far.
2632A warning is issued if none of the legal values for a property are
2633matched by your pattern. It's likely that a future release will raise a
2634warning if your pattern ends up causing every possible code point to
2635match.
2636
2637=end original
2638
2639安全のために、前述の例では、C<Hebrew_Braille> のようなものに
2640マッチングするのを防ぐために、アンカーを使っていますが、
2641今のところそのような名前の用字名はありません。
2642パターンと一致する有効な特性の値がない場合は、警告が発生します。
2643将来のリリースでは、パターンが全ての符号位置にマッチングするように
2644なった場合に警告が発生する予定です。
2645
2646=begin original
2647
2648Starting in 5.32, the Name, Name Aliases, and Named Sequences properties
2649are allowed to be matched. They are considered to be a single
2650combination property, just as has long been the case for C<\N{}>. Loose
2651matching doesn't work in exactly the same way for these as it does for
2652the values of other properties. The rules are given in
2653L<https://www.unicode.org/reports/tr44/tr44-24.html#UAX44-LM2>. As a
2654result, Perl doesn't try loose matching for you, like it does in other
2655properties. All letters in names are uppercase, but you can add C<(?i)>
2656to your subpattern to ignore case. If you're uncertain where a blank
2657is, you can use C< ?> in your subpattern. No character name contains an
2658underscore, so don't bother trying to match one. The use of hyphens is
2659particularly problematic; refer to the above link. But note that, as of
2660Unicode 13.0, the only script in modern usage which has weirdnesses with
2661these is Tibetan; also the two Korean characters U+116C HANGUL JUNGSEONG
2662OE and U+1180 HANGUL JUNGSEONG O-E. Unicode makes no promises to not
2663add hyphen-problematic names in the future.
2664
2665=end original
2666
26675.32 から、Name, Name Aliases, Named Sequences の
2668各特性をマッチングさせることができます。
2669これらの特性は、中年の C<\N{}> の場合と同様に、
2670単一の組み合わせ特性と見なされます。
2671緩いマッチングは、他の特性の値とまったく同じようには機能しません。
2672規則は L<https://www.unicode.org/reports/tr44/tr44-24.html#UAX44-LM2> に
2673記載されています。
2674結果として、Perl は他の特性のように緩いマッチングを試みません。
2675名前のすべての文字は大文字ですが、サブパターンに C<(?i)> を追加して
2676大文字と小文字を無視することができます。
2677空白がどこにあるかわからない場合は、サブパターンでC< ?>を使用できます。
2678下線を含む文字名はないので、わざわざマッチングさせようとしないでください。
2679ハイフンの使用は特に問題があります: 前述のリンクを参照してください。
2680ただし、Unicode 13.0 の時点で、現在使われている用字の中で、
2681これらに奇妙な点があるのはチベット語だけであることに注意してください;
2682また、U+116C HANGUL JUNGSEONG OEとU+1180 HANGUL JUNGSEONG O-Eという
2683二つの韓国語文字もあります。
2684Unicodeは、将来的にハイフンの問題のある名前を追加しないという
2685約束はしていません。
2686
2687=begin original
2688
2689Using wildcards on these is resource intensive, given the hundreds of
2690thousands of legal names that must be checked against.
2691
2692=end original
2693
2694これらにワイルドカードを使うと、
2695チェックされなければならない有効な名前が数十万あるので。
2696リソースを大量に消費します。
2697
2698=begin original
2699
2700An example of using Name property wildcards is
2701
2702=end original
2703
2704Name 特性ワイルドカードを使う例は:
2705
2706 qr!\p{name=/(SMILING|GRINNING) FACE/}!
2707
2708=begin original
2709
2710Another is
2711
2712=end original
2713
2714もう一つは:
2715
2716 qr/(?[ \p{name=\/CJK\/} - \p{ideographic} ])/
2717
2718=begin original
2719
2720which is the 200-ish (as of Unicode 13.0) CJK characters that aren't
2721ideographs.
2722
2723=end original
2724
2725これは (Unicode 13.0 の時点で) 200 ほどの、表意文字でない CJK 文字です。
2726
2727=begin original
2728
2729There are certain properties that wildcard subpatterns don't currently
2730work with. These are:
2731
2732=end original
2733
2734現在ワイルドカードサブパターンが動作しない特性がいくつかあります。
2735それは:
2736
2737 Bidi Mirroring Glyph
2738 Bidi Paired Bracket
2739 Case Folding
2740 Decomposition Mapping
2741 Equivalent Unified Ideograph
2742 Lowercase Mapping
2743 NFKC Case Fold
2744 Titlecase Mapping
2745 Uppercase Mapping
2746
2747=begin original
2748
2749Nor is the C<@I<unicode_property>@> form implemented.
2750
2751=end original
2752
2753また、C<@I<unicode_property>@> 形式も実装されていません。
2754
2755=begin original
2756
2757Here's a complete example of matching IPV4 internet protocol addresses
2758in any (single) script
2759
2760=end original
2761
2762以下は、(単一の) スクリプトで IPV4 インターネットプロトコルアドレスに
2763マッチングする完全な例です:
2764
2765 no warnings 'experimental::uniprop_wildcards';
2766
2767 # Can match a substring, so this intermediate regex needs to have
2768 # context or anchoring in its final use. Using nt=de yields decimal
2769 # digits. When specifying a subset of these, we must include \d to
2770 # prevent things like U+00B2 SUPERSCRIPT TWO from matching
2771 my $zero_through_255 =
2772 qr/ \b (*sr: # All from same sript
2773 (?[ \p{nv=0} & \d ])* # Optional leading zeros
2774 ( # Then one of:
2775 \d{1,2} # 0 - 99
2776 | (?[ \p{nv=1} & \d ]) \d{2} # 100 - 199
2777 | (?[ \p{nv=2} & \d ])
2778 ( (?[ \p{nv=:[0-4]:} & \d ]) \d # 200 - 249
2779 | (?[ \p{nv=5} & \d ])
2780 (?[ \p{nv=:[0-5]:} & \d ]) # 250 - 255
2781 )
2782 )
2783 )
2784 \b
2785 /x;
2786
2787 my $ipv4 = qr/ \A (*sr: $zero_through_255
2788 (?: [.] $zero_through_255 ) {3}
2789 )
2790 \z
2791 /x;
2792
27931320=head2 User-Defined Character Properties
27941321
27951322(ユーザ定義文字特性)
27961323
27971324=begin original
27981325
2799You can define your own binary character properties by defining subroutines
1326You can define your own character properties by defining subroutines
2800whose names begin with C<"In"> or C<"Is">. (The regex sets feature
1327whose names begin with "In" or "Is". The subroutines can be defined in
2801L<perlre/(?[ ])> provides an alternative which allows more complex
1328any package. The user-defined properties can be used in the regular
2802definitions.) The subroutines can be defined in any
1329expression C<\p> and C<\P> constructs; if you are using a user-defined
2803package. They override any Unicode properties expressed as the same
1330property from a package other than the one you are in, you must specify
2804names. The user-defined properties can be used in the regular
1331its package in the C<\p> or C<\P> construct.
2805expression
2806C<\p{}> and C<\P{}> constructs; if you are using a user-defined property from a
2807package other than the one you are in, you must specify its package in the
2808C<\p{}> or C<\P{}> construct.
28091332
28101333=end original
28111334
2812あなた自身の 2 値文字特性を、C<"In"> または C<"Is"> で始まる名前の
1335あなた自身の文字特性を、"In" または "Is" で始まる名前のサブルーチンを
2813サブルーチンを定義することによって持つことができます。
1336定義することによって持つことができます。
2814(正規表現集合機能 L<perlre/(?[ ])> はより複雑な定義を可能にする選択肢を
2815提供します。)
28161337そのサブルーチンは任意のパッケージで定義することができます。
2817これら同じ名前を持つ Unicode 属性を上書ます。
1338ユーザー定義特性正規表現の C<\p> 構造や C<\P> 構造で使うことができます。
2818ユーザー定義特性は正規表現の C<\p{}> 構造や C<\P{}> 構造で使うことができます;
28191339もしユーザー定義特性をそれがあるパッケージ以外で使いたいのであれば、
2820パッケージ名を C<\p{}> (もしくは C<\P{}>)のために指定する必要があります。
1340パッケージ名を C<\p> (もしくは C<\P>)のために指定する必要があります。
28211341
28221342 # assuming property IsForeign defined in Lang::
28231343 package main; # property package name required
28241344 if ($txt =~ /\p{Lang::IsForeign}+/) { ... }
28251345
28261346 package Lang; # property package name not required
28271347 if ($txt =~ /\p{IsForeign}+/) { ... }
28281348
1349
28291350=begin original
28301351
28311352Note that the effect is compile-time and immutable once defined.
2832However, the subroutines are passed a single parameter, which is 0 if
2833case-sensitive matching is in effect and non-zero if caseless matching
2834is in effect. The subroutine may return different values depending on
2835the value of the flag, and one set of values will immutably be in effect
2836for all case-sensitive matches, and the other set for all case-insensitive
2837matches.
28381353
28391354=end original
28401355
28411356この効果はコンパイル時のもので、一度定義してしまったら
28421357変更できないことに注意してください。
2843しかし、サブルーチンは一つの引数を取ります;
2844大文字小文字を認識するマッチングが有効の場合は 0 となり、
2845大文字小文字を無視するマッチングが有効の場合は非 0 となります。
2846サブルーチンはフラグの値に依存して異なった値を返すことがあり、
2847ある集合の値は全ての大文字小文字を認識するマッチングで変わらず有効になり、
2848もう一つの集合は大文字小文字を無視するマッチングで有効になります。
28491358
28501359=begin original
28511360
2852Note that if the regular expression is tainted, then Perl will die rather
2853than calling the subroutine when the name of the subroutine is
2854determined by the tainted data.
2855
2856=end original
2857
2858正規表現が汚染されている場合、Perl はサブルーチンの呼び出し時ではなく、
2859サブルーチンの名前が汚染されたデータによって決定された時点で
2860die することに注意してください。
2861
2862=begin original
2863
28641361The subroutines must return a specially-formatted string, with one
28651362or more newline-separated lines. Each line must be one of the following:
28661363
28671364=end original
28681365
28691366サブルーチンは、ひとつ以上の改行で区切られた特定の形式の文字列を
28701367返さなければなりません。
28711368各行は以下のいずれかの形式でなければなりません:
28721369
28731370=over 4
28741371
28751372=item *
28761373
28771374=begin original
28781375
2879A single hexadecimal number denoting a code point to include.
1376A single hexadecimal number denoting a Unicode code point to include.
28801377
28811378=end original
28821379
2883含まれる符号位置を示す 1 つの 16 進数。
1380含まれる Unicode 符号位置を示す 1 つの 16 進数。
28841381
28851382=item *
28861383
28871384=begin original
28881385
28891386Two hexadecimal numbers separated by horizontal whitespace (space or
2890tabular characters) denoting a range of code points to include. The
1387tabular characters) denoting a range of Unicode code points to include.
2891second number must not be smaller than the first.
28921388
28931389=end original
28941390
2895含まれる符号位置の範囲を示す、
1391含まれる Unicode の符号位置の範囲を示す、
28961392水平的空白(スペースもしくはタブ)によって区切られる 2 つの 16 進数。
28972 番目の数字は最初の数字より小さくてはいけません。
28981393
28991394=item *
29001395
29011396=begin original
29021397
2903Something to include, prefixed by C<"+">: a built-in character
1398Something to include, prefixed by "+": a built-in character
2904property (prefixed by C<"utf8::">) or a fully qualified (including package
1399property (prefixed by "utf8::") or a user-defined character property,
2905name) user-defined character property,
29061400to represent all the characters in that property; two hexadecimal code
29071401points for a range; or a single hexadecimal code point.
29081402
29091403=end original
29101404
2911(C<"+"> を前置して) その特性に含めるもの:
1405("+" を前置して) その特性に含めるもの:
2912(C<"utf8::"> が前置された) 組み込みの文字特性もしくは
1406("utf8::" が前置された) 組み込みの文字特性もしくはユーザー定義の文字特性;
2913(パッケージ名を含めた)完全修飾されたユーザー定義の文字特性;
29141407範囲のための 2 つの 16 進符号位置; あるいは単一の 16 進符号位置。
29151408
29161409=item *
29171410
29181411=begin original
29191412
2920Something to exclude, prefixed by C<"-">: an existing character
1413Something to exclude, prefixed by "-": an existing character
2921property (prefixed by C<"utf8::">) or a fully qualified (including package
1414property (prefixed by "utf8::") or a user-defined character property,
2922name) user-defined character property,
29231415to represent all the characters in that property; two hexadecimal code
29241416points for a range; or a single hexadecimal code point.
29251417
29261418=end original
29271419
2928(C<"-"> を前置して) その特性から除外するもの:
1420("-" を前置して) その特性から除外するもの:
2929(C<"utf8::"> が前置された) 組み込みの文字特性もしくは
1421("utf8::" が前置された) 組み込みの文字特性もしくはユーザー定義の文字特性;
2930(パッケージ名を含めた)完全修飾されたユーザー定義の文字特性;
29311422範囲のための 2 つの 16 進符号位置; あるいは単一の 16 進符号位置。
29321423
29331424=item *
29341425
29351426=begin original
29361427
2937Something to negate, prefixed C<"!">: an existing character
1428Something to negate, prefixed "!": an existing character
2938property (prefixed by C<"utf8::">) or a fully qualified (including package
1429property (prefixed by "utf8::") or a user-defined character property,
2939name) user-defined character property,
29401430to represent all the characters in that property; two hexadecimal code
29411431points for a range; or a single hexadecimal code point.
29421432
29431433=end original
29441434
2945(C<"!"> を前置して)否定を取るもの:
1435("!" を前置して)否定を取るもの:
2946(C<"utf8::"> が前置された) 組み込みの文字特性もしくは
1436("utf8::" が前置された) 組み込みの文字特性もしくはユーザー定義の文字特性;
2947(パッケージ名を含めた)完全修飾されたユーザー定義の文字特性;
29481437範囲のための 2 つの 16 進符号位置; あるいは単一の 16 進符号位置。
29491438
29501439=item *
29511440
29521441=begin original
29531442
2954Something to intersect with, prefixed by C<"&">: an existing character
1443Something to intersect with, prefixed by "&": an existing character
2955property (prefixed by C<"utf8::">) or a fully qualified (including package
1444property (prefixed by "utf8::") or a user-defined character property,
2956name) user-defined character property,
29571445for all the characters except the characters in the property; two
29581446hexadecimal code points for a range; or a single hexadecimal code point.
29591447
29601448=end original
29611449
2962(C<"&"> を前置して)共通集合を取るもの:
1450("&" を前置して)共通集合を取るもの:
29631451特性にある文字以外の全ての文字のための
2964(C<"utf8::"> が前置された) 既に存在する文字特性または
1452("utf8::" が前置された) 既に存在する文字特性またはユーザー定義文字特性;
2965(パッケージ名を含めた)完全修飾されたユーザー定義文字特性;
29661453範囲のための 2 つの 16 進符号位置; あるいは単一の 16 進符号位置。
29671454
29681455=back
29691456
29701457=begin original
29711458
29721459For example, to define a property that covers both the Japanese
29731460syllabaries (hiragana and katakana), you can define
29741461
29751462=end original
29761463
29771464例えば、両方の日本語の音節(ひらがなとカタカナ)を対象とする特性を
29781465定義するには、以下のように定義します
29791466
29801467 sub InKana {
2981 return <<END;
1468 return <<END;
29821469 3040\t309F
29831470 30A0\t30FF
29841471 END
29851472 }
29861473
29871474=begin original
29881475
29891476Imagine that the here-doc end marker is at the beginning of the line.
29901477Now you can use C<\p{InKana}> and C<\P{InKana}>.
29911478
29921479=end original
29931480
29941481ヒアドキュメントの終端マーカーは行の先頭に置かれることを思い出してください。
29951482これで、C<\p{InKana}> や C<\P{InKana}> を使うことができます。
29961483
29971484=begin original
29981485
29991486You could also have used the existing block property names:
30001487
30011488=end original
30021489
30031490すでに存在しているブロック特性名を使うこともできます:
30041491
30051492 sub InKana {
3006 return <<'END';
1493 return <<'END';
30071494 +utf8::InHiragana
30081495 +utf8::InKatakana
30091496 END
30101497 }
30111498
30121499=begin original
30131500
30141501Suppose you wanted to match only the allocated characters,
30151502not the raw block ranges: in other words, you want to remove
3016the unassigned characters:
1503the non-characters:
30171504
30181505=end original
30191506
30201507生のブロック範囲ではなく、割り当てられた文字のみにマッチさせたいと
3021考えているとしましょう: 言い換えれば、未割り当て文字を
1508考えているとしましょう: 言い換えれば、文字以外のもの
30221509取り除きたいということです:
30231510
30241511 sub InKana {
3025 return <<'END';
1512 return <<'END';
30261513 +utf8::InHiragana
30271514 +utf8::InKatakana
30281515 -utf8::IsCn
30291516 END
30301517 }
30311518
30321519=begin original
30331520
30341521The negation is useful for defining (surprise!) negated classes.
30351522
30361523=end original
30371524
30381525否定は否定クラスを定義するのに便利です。
30391526
30401527 sub InNotKana {
3041 return <<'END';
1528 return <<'END';
30421529 !utf8::InHiragana
30431530 -utf8::InKatakana
30441531 +utf8::IsCn
30451532 END
30461533 }
30471534
30481535=begin original
30491536
3050This will match all non-Unicode code points, since every one of them is
1537Intersection is useful for getting the common characters matched by
3051not in Kana. You can use intersection to exclude these, if desired, as
1538two (or more) classes.
3052this modified example shows:
30531539
30541540=end original
30551541
3056これは全ての非 Unicode 符号位置にマッチングしま;
1542共通集合(intersection)は二つ以上のクラスにマッチする共通の文字を得るのに
3057これらのどれも Kana ではないからです。
1543便利です。
3058もし必要なら、この修正された例にように、これらを除外するために
3059共通集合を使えます:
30601544
3061 sub InNotKana {
1545 sub InFooAndBar {
30621546 return <<'END';
3063 !utf8::InHiragana
1547 +main::Foo
3064 -utf8::InKatakana
1548 &main::Bar
3065 +utf8::IsCn
3066 &utf8::Any
30671549 END
30681550 }
30691551
30701552=begin original
30711553
3072C<&utf8::Any> must be the last line in the definition.
1554It's important to remember not to use "&" for the first set -- that
1555would be intersecting with nothing (resulting in an empty set).
30731556
30741557=end original
30751558
3076C<&utf8::Any> は定義の行でりません。
1559集合に "&" を使わいということを忘れないでください --
1560そうしてしまうと空との共通集合を取ってしまいます(結果は空集合です)。
30771561
1562=head2 User-Defined Case Mappings
1563
1564(ユーザ定義の大文字・小文字の対応関係)
1565
30781566=begin original
30791567
3080Intersection is used generally for getting the common characters matched
1568You can also define your own mappings to be used in the lc(),
3081by two (or more) classes. It's important to remember not to use C<"&"> for
1569lcfirst(), uc(), and ucfirst() (or their string-inlined versions).
3082the first set; that would be intersecting with nothing, resulting in an
1570The principle is similar to that of user-defined character
3083empty set. (Similarly using C<"-"> for the first set does nothing).
1571properties: to define subroutines in the C<main> package
1572with names like C<ToLower> (for lc() and lcfirst()), C<ToTitle> (for
1573the first character in ucfirst()), and C<ToUpper> (for uc(), and the
1574rest of the characters in ucfirst()).
30841575
30851576=end original
30861577
3087共通集合は一般的二つ(またはそれ以上)クラスによってマッチングする
1578同様、lc()、lcfirst()、uc()、ucfirst() (あるいはその文字列組み込み版)で
3088共通文字ために使われます。
1579あなた自身対応関係定義すこともできます。
3089最初の集合に C<"&"> を使わないことを覚えておくこと重要です;
1580原則
3090これは空集合と共通集を取るので、結果空集合になります
1581ユーザー定義文字特性合とます: C<ToLower> (lc() と lcfirst()用),
3091(同様に、最初の集合に C<"-"> を使っても何もしません)
1582C<ToTitle> (ucfirst() の最初の文字用), C<ToUpper> (uc() 用と ucfirst() の
1583残りの文字用) のような名前のサブルーチンを C<main> パッケージで定義します。
30921584
30931585=begin original
30941586
3095Unlike non-user-defined C<\p{}> property matches, no warning is ever
1587The string returned by the subroutines needs now to be three
3096generated if these properties are matched against a non-Unicode code
1588hexadecimal numbers separated by tabulators: start of the source
3097point (see L</Beyond Unicode code points> below).
1589range, end of the source range, and start of the destination range.
1590For example:
30981591
30991592=end original
31001593
3101ザー定義ない C<\p{}> 特性マッチングと異なり、
1594サブルチンから返される文字列はタブ区切られた 3 16 進数を
3102この特性はたえ非 Unicode 符号位置に対してマッチングしても警告は
1595必要します: ソースの範囲の始まり、ソースの範囲の終わり、そして
3103発生しせん (後述る L</Beyond Unicode code points> 参照)
1596デスティネーション範囲の始りです。
1597例を挙げましょう:
31041598
3105=head2 User-Defined Case Mappings (for serious hackers only)
1599 sub ToUpper {
1600 return <<END;
1601 0061\t0063\t0041
1602 END
1603 }
31061604
3107(ユーザ定義の大文字・小文字の対応関係(真剣なハッカー専用))
1605=begin original
31081606
1607defines an uc() mapping that causes only the characters "a", "b", and
1608"c" to be mapped to "A", "B", "C", all other characters will remain
1609unchanged.
1610
1611=end original
1612
1613これは、"a", "b", "c" の文字のみを "A", "B", "C" にマッピングして
1614その他のすべての文字は変更しないという uc() のマッピングを定義しています。
1615
31091616=begin original
31101617
3111B<This feature has been removed as of Perl 5.16.>
1618If there is no source range to speak of, that is, the mapping is from
3112The CPAN module C<L<Unicode::Casing>> provides better functionality without
1619a single character to another single character, leave the end of the
3113the drawbacks that this feature had. If you are using a Perl earlier
1620source range empty, but the two tabulator characters are still needed.
3114than 5.16, this feature was most fully documented in the 5.14 version of
1621For example:
3115this pod:
3116L<http://perldoc.perl.org/5.14.0/perlunicode.html#User-Defined-Case-Mappings-%28for-serious-hackers-only%29>
31171622
31181623=end original
31191624
3120B<こ機能は Perl 5.16 で削除されました。>
1625もしソース範囲に言及することがなけば、つり、対応関係が単一の
3121CPAN モジュール C<L<Unicode::Casing>> はこ機能が持てい欠点しに
1626文字から別単一の文字に変換するものであったならば、ソースの範囲の
3122りよい機能を提供します。
1627終わは空のままでよいけれども二つのタブは必要です。
31235.16 より前の Perl 使っている場合、この機能は 5.14 版のこの pod に
1628挙げましょう:
3124もっともよく文書化されています:
3125L<http://perldoc.perl.org/5.14.0/perlunicode.html#User-Defined-Case-Mappings-%28for-serious-hackers-only%29>
31261629
1630 sub ToLower {
1631 return <<END;
1632 0041\t\t0061
1633 END
1634 }
1635
1636=begin original
1637
1638defines a lc() mapping that causes only "A" to be mapped to "a", all
1639other characters will remain unchanged.
1640
1641=end original
1642
1643"A" を "a" にマッピングしてその他のすべての文字は変更しない lc() の
1644マッピングを定義しています。
1645
1646=begin original
1647
1648(For serious hackers only) If you want to introspect the default
1649mappings, you can find the data in the directory
1650C<$Config{privlib}>/F<unicore/To/>. The mapping data is returned as
1651the here-document, and the C<utf8::ToSpecFoo> are special exception
1652mappings derived from <$Config{privlib}>/F<unicore/SpecialCasing.txt>.
1653The C<Digit> and C<Fold> mappings that one can see in the directory
1654are not directly user-accessible, one can use either the
1655C<Unicode::UCD> module, or just match case-insensitively (that's when
1656the C<Fold> mapping is used).
1657
1658=end original
1659
1660(真剣なハッカー専用) デフォルトのマッピングを内省したいのなら、
1661C<$Config{privlib}>/F<unicore/To/> というディレクトリにデータを
1662見つけ出すことができます。
1663マッピングデータはヒアドキュメントとして返され、C<utf8::ToSpecFoo> は
1664C<$Config{privlib}>/F<unicore/SpecialCasing.txt> から派生した特殊な
1665例外マッピングです。
1666そのディレクトリで見つけることのできる C<Digit> と C<Fold> のマッピングは
1667ユーザーがダイレクトにアクセスできず、C<Unicode::UCD> モジュールを使うか
1668大小文字を無視してマッピングします(C<Fold> マッピングが使われているとき)。
1669
1670=begin original
1671
1672A final note on the user-defined case mappings: they will be used
1673only if the scalar has been marked as having Unicode characters.
1674Old byte-style strings will not be affected.
1675
1676=end original
1677
1678ユーザー定義の大文字・小文字の対応関係に関する最後の注意: これらはスカラが
1679Unicode 文字としてマークされているときにのみ使われます。
1680古いバイト形式の文字列には影響を及ぼしません。
1681
31271682=head2 Character Encodings for Input and Output
31281683
31291684(入出力のための文字エンコーディング)
31301685
31311686=begin original
31321687
31331688See L<Encode>.
31341689
31351690=end original
31361691
31371692L<Encode> を参照してください。
31381693
31391694=head2 Unicode Regular Expression Support Level
31401695
31411696(Unicode 正規表現対応レベル)
31421697
31431698=begin original
31441699
3145The following list of Unicode supported features for regular expressions describes
1700The following list of Unicode support for regular expressions describes
3146all features currently directly supported by core Perl. The references
1701all the features currently supported. The references to "Level N"
3147to "Level I<N>" and the section numbers refer to
1702and the section numbers refer to the Unicode Technical Standard #18,
3148L<UTS#18 "Unicode Regular Expressions"|https://www.unicode.org/reports/tr18>,
1703"Unicode Regular Expressions", version 11, in May 2005.
3149version 18, October 2016.
31501704
31511705=end original
31521706
3153以下に挙げるリストは、現在コア Perl が直接対応している全ての機能を記述する、
1707以下に挙げるリストは、現在対応している全ての機能を記述する、
31541708正規表現のための Unicode 対応のリストです。
3155"Level I<N>" に対する参照とセクション番号は
1709"Level N" に対する参照とセクション番号は
3156L<UTS#18 "Unicode Regular Expressions"|https://www.unicode.org/reports/tr18>,
1710Unicode Technical Standard #18,
31572016 10 月のバージョン 18 を参照しています。
1711"Unicode Regular Expressions", version 11, in May 2005
1712を参照しています。
31581713
3159=head3 Level 1 - Basic Unicode Support
3160
3161 RL1.1 Hex Notation - Done [1]
3162 RL1.2 Properties - Done [2]
3163 RL1.2a Compatibility Properties - Done [3]
3164 RL1.3 Subtraction and Intersection - Done [4]
3165 RL1.4 Simple Word Boundaries - Done [5]
3166 RL1.5 Simple Loose Matches - Done [6]
3167 RL1.6 Line Boundaries - Partial [7]
3168 RL1.7 Supplementary Code Points - Done [8]
3169
31701714=over 4
31711715
3172=item [1] C<\N{U+...}> and C<\x{...}>
1716=item *
31731717
3174=item [2]
1718Level 1 - Basic Unicode Support
3175C<\p{...}> C<\P{...}>. This requirement is for a minimal list of
3176properties. Perl supports these. See R2.7 for other properties.
31771719
3178([2] C<\p{...}> C<\P{...}>。この要求は最小限の特性の一覧に対するものです。Perl はこれらに対応しています。その他の特性については R2.7 を参照してください。)
1720 RL1.1 Hex Notation - done [1]
1721 RL1.2 Properties - done [2][3]
1722 RL1.2a Compatibility Properties - done [4]
1723 RL1.3 Subtraction and Intersection - MISSING [5]
1724 RL1.4 Simple Word Boundaries - done [6]
1725 RL1.5 Simple Loose Matches - done [7]
1726 RL1.6 Line Boundaries - MISSING [8]
1727 RL1.7 Supplementary Code Points - done [9]
31791728
3180=item [3]
1729 [1] \x{...}
3181Perl has C<\d> C<\D> C<\s> C<\S> C<\w> C<\W> C<\X> C<[:I<prop>:]>
1730 [2] \p{...} \P{...}
3182C<[:^I<prop>:]>, plus all the properties specified by
1731 [3] supports not only minimal list (general category, scripts,
3183L<https://www.unicode.org/reports/tr18/#Compatibility_Properties>. These
1732 Alphabetic, Lowercase, Uppercase, WhiteSpace,
3184are described above in L</Other Properties>
1733 NoncharacterCodePoint, DefaultIgnorableCodePoint, Any,
1734 ASCII, Assigned), but also bidirectional types, blocks, etc.
1735 (see L</"Unicode Character Properties">)
1736 [4] \d \D \s \S \w \W \X [:prop:] [:^prop:]
1737 [5] can use regular expression look-ahead [a] or
1738 user-defined character properties [b] to emulate set operations
1739 [6] \b \B
1740 [7] note that Perl does Full case-folding in matching, not Simple:
1741 for example U+1F88 is equivalent with U+1F00 U+03B9,
1742 not with 1F80. This difference matters for certain Greek
1743 capital letters with certain modifiers: the Full case-folding
1744 decomposes the letter, while the Simple case-folding would map
1745 it to a single character.
1746 [8] should do ^ and $ also on U+000B (\v in C), FF (\f), CR (\r),
1747 CRLF (\r\n), NEL (U+0085), LS (U+2028), and PS (U+2029);
1748 should also affect <>, $., and script line numbers;
1749 should not split lines within CRLF [c] (i.e. there is no empty
1750 line between \r and \n)
1751 [9] UTF-8/UTF-EBDDIC used in perl allows not only U+10000 to U+10FFFF
1752 but also beyond U+10FFFF [d]
31851753
3186(Perl は C<\d> C<\D> C<\s> C<\S> C<\w> C<\W> C<\X> C<[:I<prop>:]> C<[:^I<prop>:]> に加えて、L<https://www.unicode.org/reports/tr18/#Compatibility_Properties> で指定されている全ての特性を持ちます。これらは前述の L</Other Properties> に記されています。)
3187
3188=item [4]
3189
31901754=begin original
31911755
3192The regex sets feature C<"(?[...])"> starting in v5.18 accomplishes
1756[a] You can mimic class subtraction using lookahead.
3193this. See L<perlre/(?[ ])>.
1757For example, what UTS#18 might write as
31941758
31951759=end original
31961760
3197v5.18 からの正規表現集合機能 C<"(?[...])"> がこれ行います。
1761[a] class subtraction 先読みを使って模倣することができます。
3198L<perlre/(?[ ])> を参照してください。
1762たとえば、以下の UTR #18 は
31991763
3200=item [5]
1764 [{Greek}-[{UNASSIGNED}]]
3201C<\b> C<\B> meet most, but not all, the details of this requirement, but
3202C<\b{wb}> and C<\B{wb}> do, as well as the stricter R2.3.
32031765
3204=item [6]
3205
32061766=begin original
32071767
3208Note that Perl does Full case-folding in matching, not Simple:
1768in Perl can be written as:
32091769
32101770=end original
32111771
3212Perl はマッチング Simple はなく Full 大文字小文字畳み込みを
1772以下のように Perl で記述きます:
3213行うことに注意してください:
32141773
1774 (?!\p{Unassigned})\p{InGreekAndCoptic}
1775 (?=\p{Assigned})\p{InGreekAndCoptic}
1776
32151777=begin original
32161778
3217For example C<U+1F88> is equivalent to C<U+1F00 U+03B9>, instead of just
1779But in this particular example, you probably really want
3218C<U+1F80>. This difference matters mainly for certain Greek capital
3219letters with certain modifiers: the Full case-folding decomposes the
3220letter, while the Simple case-folding would map it to a single
3221character.
32221780
32231781=end original
32241782
3225えば C<U+1F88> る C<U+1F80> ではなく C<U+1F00 U+03B9> と等価す。
1783しかし、この特定の、あたが実際に望んいたの次のものしょう
3226この違いは、主にある種の修飾子付きのある種のギリシャ大文字に対して
3227問題になります: Full 大文字小文字畳み込みは文字を分解しますが、
3228Simple 大文字小文字畳み込みはそれを単一文字にマッピングします。
32291784
3230=item [7]
1785 \p{GreekAndCoptic}
32311786
32321787=begin original
32331788
3234The reason this is considered to be only partially implemented is that
1789which will match assigned characters known to be part of the Greek script.
3235Perl has L<C<qrE<sol>\b{lb}E<sol>>|perlrebackslash/\b{lb}> and
3236C<L<Unicode::LineBreak>> that are conformant with
3237L<UAX#14 "Unicode Line Breaking Algorithm"|https://www.unicode.org/reports/tr14>.
3238The regular expression construct provides default behavior, while the
3239heavier-weight module provides customizable line breaking.
32401790
32411791=end original
32421792
3243これが部分的にみ実装していると考えられる理由は、Perl
1793これは Greek 用字一部としてられてい assigned character にマッチします。
3244L<UAX#14 "Unicode Line Breaking Algorithm"|https://www.unicode.org/reports/tr14>
3245に準拠している
3246L<C<qrE<sol>\b{lb}E<sol>>|perlrebackslash/\b{lb}> と
3247C<L<Unicode::LineBreak>> があるからです。
3248正規表現構文はデフォルトの振る舞いを提供する一方、
3249この重量級モジュールは行区切りのカスタマイズを提供します。
32501794
32511795=begin original
32521796
3253But Perl treats C<\n> as the start- and end-line
1797Also see the Unicode::Regex::Set module, it does implement the full
3254delimiter, whereas Unicode specifies more characters that should be
1798UTS#18 grouping, intersection, union, and removal (subtraction) syntax.
3255so-interpreted.
32561799
32571800=end original
32581801
3259しかし Perl は C<\n> 行の先頭と末尾の区切り文字として
1802同様に Unicode::Regex::Set モジュール参照してくださ
3260一方 Unicode はそのように解釈するべきより多くの指定しています。
1803これは UTR #18のグルーピング、intersection、union, removal(substraction)構文を
1804フルに実装しています。
32611805
32621806=begin original
32631807
3264These are:
1808[b] '+' for union, '-' for removal (set-difference), '&' for intersection
1809(see L</"User-Defined Character Properties">)
32651810
32661811=end original
32671812
3268これ:
1813[b] 結合のために '+'、除去(差集合)のためには '-'、
1814共通集合のためには '&' です
1815(L</"User-Defined Character Properties"> を参照してください)
32691816
3270 VT U+000B (\v in C)
3271 FF U+000C (\f)
3272 CR U+000D (\r)
3273 NEL U+0085
3274 LS U+2028
3275 PS U+2029
3276
32771817=begin original
32781818
3279C<^> and C<$> in regular expression patterns are supposed to match all
1819[c] Try the C<:crlf> layer (see L<PerlIO>).
3280these, but don't.
3281These characters also don't, but should, affect C<< <> >> C<$.>, and
3282script line numbers.
32831820
32841821=end original
32851822
3286正規表現パターンの C<^> C<$> はこれら全にマッチングすることが
1823[c] C<:crlf> 層を試してください (L<PerlIO> を参照しください)。
3287想定されますが、マッチングしません。
3288これらの文字は、C<< <> >>, C<$.>, スクリプトの行番号にも影響を
3289与えるべきですが、与えません。
32901824
32911825=begin original
32921826
3293Also, lines should not be split within C<CRLF> (i.e. there is no
1827[d] Avoid C<use warning 'utf8';> (or say C<no warning 'utf8';>) to allow
3294empty line between C<\r> and C<\n>). For C<CRLF>, try the C<:crlf>
1828U+FFFF (C<\x{FFFF}>).
3295layer (see L<PerlIO>).
32961829
32971830=end original
32981831
3299また、C<CRLF> の中の行を分割しません (つまり C<\r> C<\n> の間に
1832[d] U+FFFF (C<\x{FFFF}>) を許可するために、C<use warning 'utf8';>
3300空行はありせん)。
1833しないでください (たは C<no warning 'utf8';> としてください)。
3301C<CRLF> については、C<:crlf> 層 (L<PerlIO> 参照) を試してください。
33021834
3303=item [8]
1835=item *
3304UTF-8/UTF-EBDDIC used in Perl allows not only C<U+10000> to
3305C<U+10FFFF> but also beyond C<U+10FFFF>
33061836
3307([8] Perl で使われる UTF-8/UTF-EBDDIC は C<U+10000> から C<U+10FFFF> だけでなく C<U+10FFFF> を超える値も認めません)
1837Level 2 - Extended Unicode Support
33081838
3309=back
1839 RL2.1 Canonical Equivalents - MISSING [10][11]
1840 RL2.2 Default Grapheme Clusters - MISSING [12][13]
1841 RL2.3 Default Word Boundaries - MISSING [14]
1842 RL2.4 Default Loose Matches - MISSING [15]
1843 RL2.5 Name Properties - MISSING [16]
1844 RL2.6 Wildcard Properties - MISSING
33101845
3311=head3 Level 2 - Extended Unicode Support
1846 [10] see UAX#15 "Unicode Normalization Forms"
1847 [11] have Unicode::Normalize but not integrated to regexes
1848 [12] have \X but at this level . should equal that
1849 [13] UAX#29 "Text Boundaries" considers CRLF and Hangul syllable
1850 clusters as a single grapheme cluster.
1851 [14] see UAX#29, Word Boundaries
1852 [15] see UAX#21 "Case Mappings"
1853 [16] have \N{...} but neither compute names of CJK Ideographs
1854 and Hangul Syllables nor use a loose match [e]
33121855
3313 RL2.1 Canonical Equivalents - Retracted [9]
1856=begin original
3314 by Unicode
3315 RL2.2 Extended Grapheme Clusters and - Partial [10]
3316 Character Classes with Strings
3317 RL2.3 Default Word Boundaries - Done [11]
3318 RL2.4 Default Case Conversion - Done
3319 RL2.5 Name Properties - Done
3320 RL2.6 Wildcards in Property Values - Partial [12]
3321 RL2.7 Full Properties - Partial [13]
3322 RL2.8 Optional Properties - Partial [14]
33231857
3324=over 4
1858[e] C<\N{...}> allows namespaces (see L<charnames>).
33251859
3326=item [9]
1860=end original
3327Unicode has rewritten this portion of UTS#18 to say that getting
3328canonical equivalence (see UAX#15
3329L<"Unicode Normalization Forms"|https://www.unicode.org/reports/tr15>)
3330is basically to be done at the programmer level. Use NFD to write
3331both your regular expressions and text to match them against (you
3332can use L<Unicode::Normalize>).
33331861
3334=item [10]
1862[e] C<\N{...}> は名前空間を許可します (L<charnames> を参照してください)。
3335Perl has C<\X> and C<\b{gcb}>. Unicode has retracted their "Grapheme
3336Cluster Mode", and recently added string properties, which Perl does not
3337yet support.
33381863
3339=item [11] see
1864=item *
3340L<UAX#29 "Unicode Text Segmentation"|https://www.unicode.org/reports/tr29>,
33411865
3342=item [12] see
1866Level 3 - Tailored Support
3343L</Wildcards in Property Values> above.
33441867
3345=item [13]
1868 RL3.1 Tailored Punctuation - MISSING
3346Perl supports all the properties in the Unicode Character Database
1869 RL3.2 Tailored Grapheme Clusters - MISSING [17][18]
3347(UCD). It does not yet support the listed properties that come from
1870 RL3.3 Tailored Word Boundaries - MISSING
3348other Unicode sources.
1871 RL3.4 Tailored Loose Matches - MISSING
1872 RL3.5 Tailored Ranges - MISSING
1873 RL3.6 Context Matching - MISSING [19]
1874 RL3.7 Incremental Matches - MISSING
1875 ( RL3.8 Unicode Set Sharing )
1876 RL3.9 Possible Match Sets - MISSING
1877 RL3.10 Folded Matching - MISSING [20]
1878 RL3.11 Submatchers - MISSING
33491879
3350=item [14]
1880 [17] see UAX#10 "Unicode Collation Algorithms"
3351The only optional property that Perl supports is Named Sequence. None
1881 [18] have Unicode::Collate but not integrated to regexes
3352of these properties are in the UCD.
1882 [19] have (?<=x) and (?=x), but look-aheads or look-behinds should see
1883 outside of the target substring
1884 [20] need insensitive matching for linguistic features other than case;
1885 for example, hiragana to katakana, wide and narrow, simplified Han
1886 to traditional Han (see UTR#30 "Character Foldings")
33531887
33541888=back
33551889
3356=head3 Level 3 - Tailored Support
3357
3358=begin original
3359
3360This has been retracted by Unicode.
3361
3362=end original
3363
3364これは Unicode によって取り下げられました。
3365
33661890=head2 Unicode Encodings
33671891
33681892(Unicode のエンコーディング)
33691893
33701894=begin original
33711895
33721896Unicode characters are assigned to I<code points>, which are abstract
33731897numbers. To use these numbers, various encodings are needed.
33741898
33751899=end original
33761900
33771901Unicode 文字は抽象的な数値である I<符号位置> にアサインされています。
33781902これらの数値を使うために、さまざまなエンコーディングが必要となります。
33791903
33801904=over 4
33811905
33821906=item *
33831907
33841908UTF-8
33851909
33861910=begin original
33871911
3388UTF-8 is a variable-length (1 to 4 bytes), byte-order independent
1912UTF-8 is a variable-length (1 to 6 bytes, current character allocations
3389encoding. In most of Perl's documentation, including elsewhere in this
1913require 4 bytes), byte-order independent encoding. For ASCII (and we
3390document, the term "UTF-8" means also "UTF-EBCDIC". But in this section,
1914really do mean 7-bit ASCII, not another 8-bit encoding), UTF-8 is
3391"UTF-8" refers only to the encoding used on ASCII platforms. It is a
1915transparent.
3392superset of 7-bit US-ASCII, so anything encoded in ASCII has the
3393identical representation when encoded in UTF-8.
33941916
33951917=end original
33961918
3397UTF-8 は可変長(1 から 4 バイト)で、
1919UTF-8 は可変長(1 から 6 バイト; 現在の文字配置では 4 バイトを要求します)で、
33981920バイトの並び順に依存しないエンコーディングです。
3399この文書の他の場所を含む Perl文書のほんど
1921ASCII(こでは 7-bit ASCII ことで、他の 8-bit エンコーディングとで
3400"UTF-8" いう用語は "UTF-EBCDIC" も意味します。
1922ありません)と UTF-8 は透過です。
3401しかしこの節では、
3402"UTF-8" は ASCII プラットフォームで使われているエンコーディングを
3403意味します。
3404これは 7 ビット US-ASCII のスーパーセットなので、
3405ASCII でエンコードされたものは全て UTF-8 でエンコードしたものと
3406同じ表現になります。
34071923
34081924=begin original
34091925
34101926The following table is from Unicode 3.2.
34111927
34121928=end original
34131929
34141930以下のテーブルは Unicode 3.2 のものです。
34151931
3416 Code Points 1st Byte 2nd Byte 3rd Byte 4th Byte
1932 Code Points 1st Byte 2nd Byte 3rd Byte 4th Byte
34171933
34181934 U+0000..U+007F 00..7F
3419 U+0080..U+07FF * C2..DF 80..BF
1935 U+0080..U+07FF C2..DF 80..BF
3420 U+0800..U+0FFF E0 * A0..BF 80..BF
1936 U+0800..U+0FFF E0 A0..BF 80..BF
34211937 U+1000..U+CFFF E1..EC 80..BF 80..BF
34221938 U+D000..U+D7FF ED 80..9F 80..BF
3423 U+D800..U+DFFF +++++ utf16 surrogates, not legal utf8 +++++
1939 U+D800..U+DFFF ******* ill-formed *******
34241940 U+E000..U+FFFF EE..EF 80..BF 80..BF
3425 U+10000..U+3FFFF F0 * 90..BF 80..BF 80..BF
1941 U+10000..U+3FFFF F0 90..BF 80..BF 80..BF
34261942 U+40000..U+FFFFF F1..F3 80..BF 80..BF 80..BF
34271943 U+100000..U+10FFFF F4 80..8F 80..BF 80..BF
34281944
34291945=begin original
34301946
3431Note the gaps marked by "*" before several of the byte entries above. These are
1947Note the C<A0..BF> in C<U+0800..U+0FFF>, the C<80..9F> in
3432caused by legal UTF-8 avoiding non-shortest encodings: it is technically
1948C<U+D000...U+D7FF>, the C<90..B>F in C<U+10000..U+3FFFF>, and the
3433possible to UTF-8-encode a single code point in different ways, but that is
1949C<80...8F> in C<U+100000..U+10FFFF>. The "gaps" are caused by legal
3434explicitly forbidden, and the shortest possible encoding should always be used
1950UTF-8 avoiding non-shortest encodings: it is technically possible to
3435(and that is what Perl does).
1951UTF-8-encode a single code point in different ways, but that is
1952explicitly forbidden, and the shortest possible encoding should always
1953be used. So that's what Perl does.
34361954
34371955=end original
34381956
3439上記で '*' マークが付いているいくつかバイトエントリ
1957C<U+0800..U+0FFF> C<A0..BF>、C<U+D000...U+D7FF> C<80..9F>、
3440隙間に注意してください。
1958C<U+10000..U+3FFFF> の中の C<90..BF>、C<U+100000..U+10FFFF> の中の
3441これらは、正当な UTF-8 が最短でないエンコードを避けるため
1959C<80...8F>注意してください。
1960この「隙間」は、正当な UTF-8 が最短でないエンコードを避けるために
34421961あります: 技術的には UTF-8 エンコードは一つの符号位置を複数の方法で
34431962表すことができますが、これは明示的に禁止されていて、可能な限り最短の
3444エンコードが常に使われます(そしてそれが Perl のすることです)
1963エンコードが常に使われます。
1964従って、Perl もそうします。
34451965
34461966=begin original
34471967
34481968Another way to look at it is via bits:
34491969
34501970=end original
34511971
34521972これを見るもう一つの方法はビット単位で見ることです:
34531973
3454 Code Points 1st Byte 2nd Byte 3rd Byte 4th Byte
1974 Code Points 1st Byte 2nd Byte 3rd Byte 4th Byte
34551975
3456 0aaaaaaa 0aaaaaaa
1976 0aaaaaaa 0aaaaaaa
3457 00000bbbbbaaaaaa 110bbbbb 10aaaaaa
1977 00000bbbbbaaaaaa 110bbbbb 10aaaaaa
3458 ccccbbbbbbaaaaaa 1110cccc 10bbbbbb 10aaaaaa
1978 ccccbbbbbbaaaaaa 1110cccc 10bbbbbb 10aaaaaa
3459 00000dddccccccbbbbbbaaaaaa 11110ddd 10cccccc 10bbbbbb 10aaaaaa
1979 00000dddccccccbbbbbbaaaaaa 11110ddd 10cccccc 10bbbbbb 10aaaaaa
34601980
34611981=begin original
34621982
3463As you can see, the continuation bytes all begin with C<"10">, and the
1983As you can see, the continuation bytes all begin with C<10>, and the
3464leading bits of the start byte tell how many bytes there are in the
1984leading bits of the start byte tell how many bytes the are in the
34651985encoded character.
34661986
34671987=end original
34681988
3469見ての通り、後続バイトはすべて C<"10"> から始まっていて、開始バイトの
1989見ての通り、後続バイトはすべて C<10> から始まっていて、開始バイトの
34701990先行ビットはエンコードされた文字がどのくらいの長さであるかを示しています。
34711991
3472=begin original
3473
3474The original UTF-8 specification allowed up to 6 bytes, to allow
3475encoding of numbers up to C<0x7FFF_FFFF>. Perl continues to allow those,
3476and has extended that up to 13 bytes to encode code points up to what
3477can fit in a 64-bit word. However, Perl will warn if you output any of
3478these as being non-portable; and under strict UTF-8 input protocols,
3479they are forbidden. In addition, it is now illegal to use a code point
3480larger than what a signed integer variable on your system can hold. On
348132-bit ASCII systems, this means C<0x7FFF_FFFF> is the legal maximum
3482(much higher on 64-bit systems).
3483
3484=end original
3485
3486元の UTF-8 仕様は、C<0x7FFF_FFFF> までの数値をエンコードできるように、
34876 バイトまで許されていました。
3488Perl はこれを許し続け、さらに 64 ビットワードに適合する符号位置を
3489エンコードするために 13 バイトまで拡張しています。
3490しかし、これらを出力すると、Perl は互換性がないとして警告します;
3491そして厳密な UTF-8 入力プロトコルでは、これらは禁止されています。
3492さらに、システムの符号付き整数変数が保持できるよりも
3493大きな符号位置は不正になりました。
349432 ビット ASCII システムでは、
3495これは、C<0x7FFF_FFFF> が正当な最大であることを意味します
3496(64 ビットシステムでは遙かに大きいです)。
3497
34981992=item *
34991993
35001994UTF-EBCDIC
35011995
35021996=begin original
35031997
3504Like UTF-8, but EBCDIC-safe, in the way that UTF-8 is ASCII-safe.
1998Like UTF-8 but EBCDIC-safe, in the way that UTF-8 is ASCII-safe.
3505This means that all the basic characters (which includes all
3506those that have ASCII equivalents (like C<"A">, C<"0">, C<"%">, I<etc.>)
3507are the same in both EBCDIC and UTF-EBCDIC.)
35081999
35092000=end original
35102001
35112002UTF-8 と似ていますが、UTF-8 が ASCII-safe であるように EBCDIC-safe です。
3512つまり、全ての基本文字 ((C<"A">, C<"0">, C<"%"> などのような) ASCII の
3513等価物が EBCDIC と UTF-EBCDIC で同じものを意味します。
35142003
3515=begin original
3516
3517UTF-EBCDIC is used on EBCDIC platforms. It generally requires more
3518bytes to represent a given code point than UTF-8 does; the largest
3519Unicode code points take 5 bytes to represent (instead of 4 in UTF-8),
3520and, extended for 64-bit words, it uses 14 bytes instead of 13 bytes in
3521UTF-8.
3522
3523=end original
3524
3525UTF-EBCDIC は EBCDIC プラットフォームで使われます。
3526一般的に、ある符号位置を表現するのに UTF-8 よりも多くのバイト数を
3527必要とします; 最大の Unicode 符号位置は表現するのに (UTF-8 の 4 バイト
3528ではなく) 5 バイトを使い、64 ビットワードのために拡張されると、
3529UTF-8 の場合の 13 バイトではなく 14 バイトを使います。
3530
35312004=item *
35322005
35332006=begin original
35342007
3535UTF-16, UTF-16BE, UTF-16LE, Surrogates, and C<BOM>'s (Byte Order Marks)
2008UTF-16, UTF-16BE, UTF-16LE, Surrogates, and BOMs (Byte Order Marks)
35362009
35372010=end original
35382011
3539UTF-16, UTF-16BE, UTF-16LE, サロゲート, C<BOM> (Byte Order Marks)
2012UTF-16, UTF-16BE, UTF-16LE, サロゲート, BOM (Byte Order Marks)
35402013
35412014=begin original
35422015
35432016The followings items are mostly for reference and general Unicode
35442017knowledge, Perl doesn't use these constructs internally.
35452018
35462019=end original
35472020
35482021以下の項目はほとんど参照および一般的な Unicode 知識のためのもので、
35492022Perl はこれらの構造を内部で使っていません。
35502023
35512024=begin original
35522025
3553Like UTF-8, UTF-16 is a variable-width encoding, but where
2026UTF-16 is a 2 or 4 byte encoding. The Unicode code points
3554UTF-8 uses 8-bit code units, UTF-16 uses 16-bit code units.
2027C<U+0000..U+FFFF> are stored in a single 16-bit unit, and the code
3555All code points occupy either 2 or 4 bytes in UTF-16: code points
3556C<U+0000..U+FFFF> are stored in a single 16-bit unit, and code
35572028points C<U+10000..U+10FFFF> in two 16-bit units. The latter case is
35582029using I<surrogates>, the first 16-bit unit being the I<high
35592030surrogate>, and the second being the I<low surrogate>.
35602031
35612032=end original
35622033
3563UTF-8 と同様、UTF-16 は可変長エンコーディングですが、
2034UTF-16 は 2 バイトもしくは 4 バイトのエンコーディングです
3564UTF-8 が 8 ビットの符号ユニットを使っているところ、
3565UTF-16 は 16 ビットの符号ユニットを使います。
3566UTF-16 は全ての符号位置が 2 バイトもしくは 4 バイトです:
35672035C<U+0000..U+FFFF> の範囲の Unicode の符号位置はひとつの 16 ビット
35682036ユニットに収められ、C<U+10000..U+10FFFF> の範囲の符号位置は 2 つの
3569203716 ビットユニットに収められます。
3570後者をサロゲート(surrogates) と呼びます; 最初の 16 ビットユニットは
2038後者をサロゲート(surrogates) と呼びます
3571I<high surrogate> で、二番目は I<low surrogate> となります。
2039最初の 16 ビットユニットは I<high surrogate> で、二番目は
2040I<low surrogate> となります。
35722041
35732042=begin original
35742043
35752044Surrogates are code points set aside to encode the C<U+10000..U+10FFFF>
35762045range of Unicode code points in pairs of 16-bit units. The I<high
3577surrogates> are the range C<U+D800..U+DBFF> and the I<low surrogates>
2046surrogates> are the range C<U+D800..U+DBFF>, and the I<low surrogates>
35782047are the range C<U+DC00..U+DFFF>. The surrogate encoding is
35792048
35802049=end original
35812050
35822051サロゲートは Unicode の符号位置の C<U+10000..U+10FFFF> の範囲を
3583205216 ビットユニットのペアで表現する集合です。
35842053I<high surrogates> は C<U+D800..U+DBFF> の範囲で、I<low surrogates> は
35852054C<U+DC00..U+DFFF> の範囲です。
35862055サロゲートのエンコーディングは
35872056
3588 $hi = ($uni - 0x10000) / 0x400 + 0xD800;
2057 $hi = ($uni - 0x10000) / 0x400 + 0xD800;
3589 $lo = ($uni - 0x10000) % 0x400 + 0xDC00;
2058 $lo = ($uni - 0x10000) % 0x400 + 0xDC00;
35902059
35912060=begin original
35922061
35932062and the decoding is
35942063
35952064=end original
35962065
35972066であり、デコードは以下のようなものです
35982067
3599 $uni = 0x10000 + ($hi - 0xD800) * 0x400 + ($lo - 0xDC00);
2068 $uni = 0x10000 + ($hi - 0xD800) * 0x400 + ($lo - 0xDC00);
36002069
36012070=begin original
36022071
2072If you try to generate surrogates (for example by using chr()), you
2073will get a warning if warnings are turned on, because those code
2074points are not valid for a Unicode character.
2075
2076=end original
2077
2078(たとえば chr() を使って)サロゲートを生成しようとしたならば、
2079警告が有効であれば警告が発生するでしょう。
2080なぜなら、そういった符号位置は Unicode 文字としては正しいものではないからです。
2081
2082=begin original
2083
36032084Because of the 16-bitness, UTF-16 is byte-order dependent. UTF-16
36042085itself can be used for in-memory computations, but if storage or
36052086transfer is required either UTF-16BE (big-endian) or UTF-16LE
36062087(little-endian) encodings must be chosen.
36072088
36082089=end original
36092090
3610209116-bitness のため、UTF-16 はバイトの並び順に依存します。
36112092UTF-16 それ自身はメモリ内の計算に使うことができますが、格納や転送の際には
36122093UTF-16BE (ビッグエンディアン)か UTF-16LE (リトルエンディアン)の
36132094いずれかのエンコーディングを選択しなければなりません。
36142095
36152096=begin original
36162097
36172098This introduces another problem: what if you just know that your data
36182099is UTF-16, but you don't know which endianness? Byte Order Marks, or
3619C<BOM>'s, are a solution to this. A special character has been reserved
2100BOMs, are a solution to this. A special character has been reserved
36202101in Unicode to function as a byte order marker: the character with the
3621code point C<U+FEFF> is the C<BOM>.
2102code point C<U+FEFF> is the BOM.
36222103
36232104=end original
36242105
36252106このことは別の問題を引き起こします: あなたのデータが UTF-16 であることだけを
36262107知っていて、そのバイト並び順を知らなかったとしたら?
3627バイト順マーク (Byte Order Marks)、略して C<BOM> はこれを解決します。
2108バイト順マーク (Byte Order Marks)、略して BOM はこれを解決します。
36282109バイト並びのマーカーとしての機能のために Unicode では特殊な文字が
3629予約されています: 符号位置 C<U+FEFF> の文字が C<BOM> です。
2110予約されています: その文字は符号位置 C<U+FEFF> です。
36302111
36312112=begin original
36322113
3633The trick is that if you read a C<BOM>, you will know the byte order,
2114The trick is that if you read a BOM, you will know the byte order,
36342115since if it was written on a big-endian platform, you will read the
36352116bytes C<0xFE 0xFF>, but if it was written on a little-endian platform,
36362117you will read the bytes C<0xFF 0xFE>. (And if the originating platform
3637was writing in ASCII platform UTF-8, you will read the bytes
2118was writing in UTF-8, you will read the bytes C<0xEF 0xBB 0xBF>.)
3638C<0xEF 0xBB 0xBF>.)
36392119
36402120=end original
36412121
3642このトリックは、C<BOM> を読み込んだときにバイト順がわかるということです;
2122このトリックは、BOM を読み込んだときにバイト順がわかるということです
36432123ビッグエンディアンのプラットフォームで書かれたものならなら
36442124C<0xFE 0xFF> を読み出し、リトルエンディガンのプラットフォームで
36452125書かれたものなら C<0xFF 0xFE> を読み出します。
3646(そしてもし元のプラットフォームで ASCII プラットフォームの UTF-8 で
2126(そしてもし元のプラットフォームで UTF-8 で書かれたものならば
3647書かれたものならば、C<0xEF 0xBB 0xBF> というバイト列を
2127C<0xEF 0xBB 0xBF> というバイト列を読むことになるでしょう。)
3648読むことになるでしょう。)
36492128
36502129=begin original
36512130
36522131The way this trick works is that the character with the code point
3653C<U+FFFE> is not supposed to be in input streams, so the
2132C<U+FFFE> is guaranteed not to be a valid Unicode character, so the
3654sequence of bytes C<0xFF 0xFE> is unambiguously "C<BOM>, represented in
2133sequence of bytes C<0xFF 0xFE> is unambiguously "BOM, represented in
36552134little-endian format" and cannot be C<U+FFFE>, represented in big-endian
36562135format".
36572136
36582137=end original
36592138
3660このトリックがうまくいくのは符号位置 C<U+FFFE> の文字は
2139このトリックがうまくいくのは符号位置 C<U+FFFE> の文字は正当な
3661入力ストリームには現れないはずであるということによって、
2140Unicode 文字でないということによって、C<0xFF 0xFE> という並びは紛れなく
3662C<0xFF 0xFE> という並びは紛れなく
2141"リトルエンディアンフォーマットの BOM" であって
3663「リトルエンディアンフォーマットの C<BOM>あって
2142"ビッグエンディアンの C<U+FFFE>" とはならないのす。
3664「ビッグエンディアンの C<U+FFFE>」 とはならないのです。
36652143
3666=begin original
3667
3668Surrogates have no meaning in Unicode outside their use in pairs to
3669represent other code points. However, Perl allows them to be
3670represented individually internally, for example by saying
3671C<chr(0xD801)>, so that all code points, not just those valid for open
3672interchange, are
3673representable. Unicode does define semantics for them, such as their
3674C<L</General_Category>> is C<"Cs">. But because their use is somewhat dangerous,
3675Perl will warn (using the warning category C<"surrogate">, which is a
3676sub-category of C<"utf8">) if an attempt is made
3677to do things like take the lower case of one, or match
3678case-insensitively, or to output them. (But don't try this on Perls
3679before 5.14.)
3680
3681=end original
3682
3683サロゲートは、他の符号位置を表すためにペアで使用する以外は、
3684Unicode では意味を持ちません。
3685ただし、Perl では、例えば C<chr(0xD801)> と記述することによって、
3686内部的に個別に表すことができるため、
3687オープンな交換に妥当な符号位置だけでなく、
3688すべての符号位置を表すことができます。
3689Unicode では、C<L</General_Category>> が C<"Cs"> であるなどの、
3690このための意味論が定義されています。
3691しかし、これらの使用はやや危険であるため、Perl では、小文字を使用したり、
3692大文字と小文字を無視してマッチングしたり、出力しようとした場合には、
3693(C<"utf8"> のサブカテゴリである C<"surrogate"> 警告カテゴリを使って) 警告が
3694出されます。
3695(ただし、5.14 より前の Perl でこれを使用しないでください。)
3696
36972144=item *
36982145
36992146UTF-32, UTF-32BE, UTF-32LE
37002147
37012148=begin original
37022149
3703The UTF-32 family is pretty much like the UTF-16 family, except that
2150The UTF-32 family is pretty much like the UTF-16 family, expect that
37042151the units are 32-bit, and therefore the surrogate scheme is not
3705needed. UTF-32 is a fixed-width encoding. The C<BOM> signatures are
2152needed. The BOM signatures will be C<0x00 0x00 0xFE 0xFF> for BE and
3706C<0x00 0x00 0xFE 0xFF> for BE and C<0xFF 0xFE 0x00 0x00> for LE.
2153C<0xFF 0xFE 0x00 0x00> for LE.
37072154
37082155=end original
37092156
37102157UTF-32 ファミリーは UTF-16 ファミリーと良く似ていますが、ユニットが
3711215832 ビットで、そのためサロゲート方式の必要がないという点が異なります。
3712UTF-32 は固定長エンコーディングです。
2159BOM ネチャは BE は C<0x00 0x00 0xFE 0xFF> に、
3713C<BOM> シグネチャは BE では C<0x00 0x00 0xFE 0xFF> に、
37142160LE では C<0xFF 0xFE 0x00 0x00> になります。
37152161
37162162=item *
37172163
37182164UCS-2, UCS-4
37192165
37202166=begin original
37212167
3722Legacy, fixed-width encodings defined by the ISO 10646 standard. UCS-2 is a 16-bit
2168Encodings defined by the ISO 10646 standard. UCS-2 is a 16-bit
37232169encoding. Unlike UTF-16, UCS-2 is not extensible beyond C<U+FFFF>,
37242170because it does not use surrogates. UCS-4 is a 32-bit encoding,
3725functionally identical to UTF-32 (the difference being that
2171functionally identical to UTF-32.
3726UCS-4 forbids neither surrogates nor code points larger than C<0x10_FFFF>).
37272172
37282173=end original
37292174
3730ISO 10646 標準で定義されている古い固定長のエンコーディングです。
2175ISO 10646 標準で定義されているエンコーディングです。
37312176UCS-2 は 16 ビットエンコーディングです。
3732UTF-16 とは異なり、UCS-2 は C<U+FFFF> を超えた範囲に拡張できません;
2177UTF-16 とは異なり、UCS-2 は C<U+FFFF> を超えた範囲に拡張できません
37332178これはサロゲートを使わないためです。
3734UCS-4 は 32 ビットエンコーディングで、機能的には UTF-32 と同じです
2179UCS-4 は 32 ビットエンコーディングで、機能的には UTF-32 と同じです
3735(違いは、UCS-4 はサロゲートや C<0x10_FFFF> より大きな符号位置を
3736禁止していることです)。
37372180
37382181=item *
37392182
37402183UTF-7
37412184
37422185=begin original
37432186
37442187A seven-bit safe (non-eight-bit) encoding, which is useful if the
37452188transport or storage is not eight-bit safe. Defined by RFC 2152.
37462189
37472190=end original
37482191
374921927 ビットセーフ(非 8 ビット)エンコーディングで、8 ビットセーフでない
37502193転送や格納に便利です。
37512194RFC 2152 によって定義されています。
37522195
37532196=back
37542197
3755=head2 Noncharacter code points
2198=head2 Security Implications of Unicode
37562199
3757(非文字符号位置)
2200(Unicode のセキュリティへの影響)
37582201
3759=begin original
3760
376166 code points are set aside in Unicode as "noncharacter code points".
3762These all have the C<Unassigned> (C<Cn>) C<L</General_Category>>, and
3763no character will ever be assigned to any of them. They are the 32 code
3764points between C<U+FDD0> and C<U+FDEF> inclusive, and the 34 code
3765points:
3766
3767=end original
3768
376966 の符号位置は、Unicode では「非文字符号位置」として確保されています。
3770これらはすべて C<Unassigned> (C<Cn>) C<L</General_Category>> を 持ち、
3771これらに文字が割り当てられることはありません。
3772それは、C<U+FDD0> と C<U+FDEF> の間にある 32 の符号位置と、
3773次の 34 の符号位置です。
3774
3775 U+FFFE U+FFFF
3776 U+1FFFE U+1FFFF
3777 U+2FFFE U+2FFFF
3778 ...
3779 U+EFFFE U+EFFFF
3780 U+FFFFE U+FFFFF
3781 U+10FFFE U+10FFFF
3782
3783=begin original
3784
3785Until Unicode 7.0, the noncharacters were "B<forbidden> for use in open
3786interchange of Unicode text data", so that code that processed those
3787streams could use these code points as sentinels that could be mixed in
3788with character data, and would always be distinguishable from that data.
3789(Emphasis above and in the next paragraph are added in this document.)
3790
3791=end original
3792
3793Unicode 7.0 までは、非文字は
3794「Unicode テキストデータのオープンな交換での使用は B<禁止>」であったため、
3795これらのストリームを処理するコードは、これらの符号位置を
3796文字データと混在させられる標識として使うことができ、
3797それは常にデータと区別できました。
3798(前述および次の段落の強調は、この文書によって追加されています。)
3799
3800=begin original
3801
3802Unicode 7.0 changed the wording so that they are "B<not recommended> for
3803use in open interchange of Unicode text data". The 7.0 Standard goes on
3804to say:
3805
3806=end original
3807
3808Unicode 7.0 では、「Unicode テキストデータのオープンな交換での使用は
3809B<非推奨>」という表現に変更されました。
38107.0 標準では、次のように記述されています。
3811
38122202=over 4
38132203
3814=begin original
2204=item *
38152205
3816"If a noncharacter is received in open interchange, an application is
3817not required to interpret it in any way. It is good practice, however,
3818to recognize it as a noncharacter and to take appropriate action, such
3819as replacing it with C<U+FFFD> replacement character, to indicate the
3820problem in the text. It is not recommended to simply delete
3821noncharacter code points from such text, because of the potential
3822security issues caused by deleting uninterpreted characters. (See
3823conformance clause C7 in Section 3.2, Conformance Requirements, and
3824L<Unicode Technical Report #36, "Unicode Security
3825Considerations"|https://www.unicode.org/reports/tr36/#Substituting_for_Ill_Formed_Subsequences>)."
3826
3827=end original
3828
3829「オープンな交換で非文字が受信された場合、
3830アプリケーションはそれを解釈する必要はない。
3831しかし、それを非文字として認識し、テキスト内の問題を示すために
3832C<U+FFFD> 置換文字で置き換えるなどの適切なアクションを
3833実行することはよい習慣である。
3834解釈されない文字を削除することによってセキュリティ上の問題が発生する
3835可能性があるため、そのようなテキストから非文字符号位置を単純に
3836削除することは推奨しない。
3837(Conformance Clause C7 in Section 3.2,Conformance Requirements および
3838L<Unicode Technical Report #36, "Unicode Security
3839Considerations"|https://www.unicode.org/reports/tr36/#Substituting_for_Ill_Formed_Subsequences>
3840を参照)。」
3841
3842=back
3843
38442206=begin original
38452207
3846This change was made because it was found that various commercial tools
2208Malformed UTF-8
3847like editors, or for things like source code control, had been written
3848so that they would not handle program files that used these code points,
3849effectively precluding their use almost entirely! And that was never
3850the intent. They've always been meant to be usable within an
3851application, or cooperating set of applications, at will.
38522209
38532210=end original
38542211
3855この変更は、
2212不正な UTF-8
3856エディタやソースコード制御のような様々な市販のツールが、
3857これらの符号位置を使ったプログラムファイルを扱わず、
3858事実上これらの使用をほぼ完全に排除していることが分かったからです!
3859そしてこれは決して意図してものではありません。
3860これは常に、アプリケーション単体や、協調するアプリケーションの
3861集合の中で、任意に使えることを意味していました。
38622213
38632214=begin original
38642215
3865If you're writing code, such as an editor, that is supposed to be able
2216Unfortunately, the specification of UTF-8 leaves some room for
3866to handle any Unicode text data, then you shouldn't be using these code
2217interpretation of how many bytes of encoded output one should generate
3867points yourself, and instead allow them in the input. If you need
2218from one input Unicode character. Strictly speaking, the shortest
3868sentinels, they should instead be something that isn't legal Unicode.
2219possible sequence of UTF-8 bytes should be generated,
3869For UTF-8 data, you can use the bytes 0xC1 and 0xC2 as sentinels, as
2220because otherwise there is potential for an input buffer overflow at
3870they never appear in well-formed UTF-8. (There are equivalents for
2221the receiving end of a UTF-8 connection. Perl always generates the
3871UTF-EBCDIC). You can also store your Unicode code points in integer
2222shortest length UTF-8, and with warnings on Perl will warn about
3872variables and use negative values as sentinels.
2223non-shortest length UTF-8 along with other malformations, such as the
2224surrogates, which are not real Unicode code points.
38732225
38742226=end original
38752227
3876任意の Unicode テキストデータを扱えると想定される、エディタなどコードを
2228残念ながら、UTF-8 仕様ではひとつの Unicode 文字入力から
3877いている場合は、これらの符号位置を自分自身では使わず、
2229何バイトのエンコードされた出力として解釈するのかについてい
3878入力として使用できるようにする必要があります。
2230余地があります。
3879番兵文字が必要な場合は正当な Unicode ではないものを使う必要あります。
2231厳密にいえば可能限り最も短い UTF-8 バイト列生成されるべきです。
3880UTF-8 データ場合は、バイト 0xC1 よび 0xC2 を番兵文字とし使用できます;
2232なぜなら、そうしないと UTF-8 コネクション終わりに、入力バッファが
3881これらは整形式の UTF-8 では決して現れないからです
2233オーバーフローする可能性があるからです
3882(UTF-EBCDIC にも同等があります。)
2234Perl は常に最も短い長さの UTF-8 を生成し、本当 Unicode 符号位置でない
3883Unicode 符号位置を整数変数格納、負の値センチネルと
2235サロゲートのような不正な形式の最短でない UTF-8て警告ます。
3884使用することもできます。
38852236
2237=item *
38862238
38872239=begin original
38882240
3889If you're not writing such a tool, then whether you accept noncharacters
2241Regular expressions behave slightly differently between byte data and
3890as input is up to you (though the Standard recommends that you not). If
2242character (Unicode) data. For example, the "word character" character
3891you do strict input stream checking with Perl, these code points
2243class C<\w> will work differently depending on if data is eight-bit bytes
3892continue to be forbidden. This is to maintain backward compatibility
2244or Unicode.
3893(otherwise potential security holes could open up, as an unsuspecting
3894application that was written assuming the noncharacters would be
3895filtered out before getting to it, could now, without warning, start
3896getting them). To do strict checking, you can use the layer
3897C<:encoding('UTF-8')>.
38982245
38992246=end original
39002247
3901そのようなツルを書いているのでないのなら、
2248正規表現はバイトデタと文字(Unicode)データとまったく異
3902非文字入力とて受け付けるかどうかはあなた次第で
2249振る舞いをし
3903(しかし標準はそうしないことを勧めています)。
2250たとえば、単語文字("word character")クラス C<\w> はそのデータが
3904Perl で厳密入力ストリームチェックをするなら、
22518 ビットバイトか Unicode かに依存して異る働きしま
3905これらの符号位置は禁止され続けます。
3906これは後方互換性を維持するためです
3907(そうしないと、非文字は受け取る前にフィルタリングされることを仮定して
3908書かれた、疑わないアプリケーションが、警告なしに受け取るようになるといため、
3909潜在的なセキュリティホールが開く可能性があります)。
3910厳密なチェックをするためには、C<:encoding('UTF-8')> 層を使えます。
39112252
39122253=begin original
39132254
3914Perl continues to warn (using the warning category C<"nonchar">, which
2255In the first case, the set of C<\w> characters is either small--the
3915is a sub-category of C<"utf8">) if an attempt is made to output
2256default set of alphabetic characters, digits, and the "_"--or, if you
3916noncharacters.
2257are using a locale (see L<perllocale>), the C<\w> might contain a few
2258more letters according to your language and country.
39172259
39182260=end original
39192261
3920Perl は非文字を出力しようとすると(C<"utf8"> のサブカテゴリある
2262第一の場合、C<\w> 文字集合は相対的に小さいものす -- アルファベット、
3921C<"nonchar"> 警告カテゴリ使って)警告し続けます。
2263数字、そして "_" のデフォルト集合 -- もしくはロケール(L<perllocale> を参照)
2264使っているのであれば、C<\w> はあなたの使っている言語や国に応じていくつかの
2265文字が増えているかもしれません。
39222266
3923=head2 Beyond Unicode code points
3924
3925(Unicode 符号位置を越えたもの)
3926
39272267=begin original
39282268
3929The maximum Unicode code point is C<U+10FFFF>, and Unicode only defines
2269In the second case, the C<\w> set of characters is much, much larger.
3930operations on code points up through that. But Perl works on code
2270Most importantly, even in the set of the first 256 characters, it will
3931points up to the maximum permissible signed number available on the
2271probably match different characters: unlike most locales, which are
3932platform. However, Perl will not accept these from input streams unless
2272specific to a language and country pair, Unicode classifies all the
3933lax rules are being used, and will warn (using the warning category
2273characters that are letters I<somewhere> as C<\w>. For example, your
3934C<"non_unicode">, which is a sub-category of C<"utf8">) if any are output.
2274locale might not think that LATIN SMALL LETTER ETH is a letter (unless
2275you happen to speak Icelandic), but Unicode does.
39352276
39362277=end original
39372278
3938Unicode 符号位置最大値は C<U+10FFFF> で、
2279第二場合、C<\w> の文字集合は相対的に大きなものになります。
3939Unicode はこまで符号位置に対する操作みを定義しいます。
2280最も重要なとは、最初 256 文字集合にあっさえ異なる文字と
3940しかし、Perl は、プラトフォームで利用可能な符号付きの最大数までの
2281チする可能性があるということす: 言語と国ペアで指定される
3941符号位置で動作します。
2282大部分のロケールと異なり、Unicode のクラス分けは I<どこかにある>
3942しかし、Perl は、緩い規則が使用されいないかぎり、入力ストリームから
2283すべの文字を C<\w> に属するものとします。
3943これらを受け入れず、それらを出力しようと(C<"utf8">
2284えば、あなたの使っていロケールは LATIN SMALL LETTER ETH が
3944サブカテゴリである C<"non_unicode"> 警告カテゴリを使って)警告ます。
2285(アイスランド語を使っていない限り)ていないとみなしているでしょうが、
2286Unicode は属するものとしてみなすのです。
39452287
39462288=begin original
39472289
3948Since Unicode rules are not defined on these code points, if a
2290As discussed elsewhere, Perl has one foot (two hooves?) planted in
3949Unicode-defined operation is done on them, Perl uses what we believe are
2291each of two worlds: the old world of bytes and the new world of
3950sensible rules, while generally warning, using the C<"non_unicode">
2292characters, upgrading from bytes to characters when necessary.
3951category. For example, C<uc("\x{11_0000}")> will generate such a
2293If your legacy code does not explicitly use Unicode, no automatic
3952warning, returning the input parameter as its result, since Perl defines
2294switch-over to characters should happen. Characters shouldn't get
3953the uppercase of every non-Unicode code point to be the code point
2295downgraded to bytes, either. It is possible to accidentally mix bytes
3954itself. (All the case changing operations, not just uppercasing, work
2296and characters, however (see L<perluniintro>), in which case C<\w> in
3955this way.)
2297regular expressions might start behaving differently. Review your
2298code. Use warnings and the C<strict> pragma.
39562299
39572300=end original
39582301
3959Unicode の規則これら符号位置に対して定義さていないため、
2302すでに述べている通り、Perl二つ世界のそぞれに片方の足
3960Unicode が定義た操作がこれらに対して行われた場合
2303(二つのひづめ?) を突っ込んでいます: 古いバイトの世界と新い文字の世界で
3961Perl は私たちがふさわしいと信る規則を使いますが、一般的には
2304必要に応てバイトから文字に昇格します
3962C<"non_unicode"> カテゴリの警告ます。
2305もしあなたの古いコードが明示的に Unicode を使ってないのなら、文字への
3963ば、C<uc("\x{11_0000}")> はの警告を生成し、入力パラメータを
2306切り替が自動的になされるとはありません。
3964その結果として返します; Perl はすべての非 Unicode 符号位置の大文字をその
2307文字はバイトにダウングレードされるべきではありません。
3965符号位置自身定義していからで
2308偶発的にバイト文字が混じ可能性がありまが(L<perluniintro> を参照)、
3966(大文字化だけでなく、全て大文字小文字変更操作はこのよう
2309のような場合正規表現中の C<\w> は異なるふるまいをするかもしれません。
3967動作ます)
2310あなたのコードをレビューてください
2311warnings と C<strict> プラグマを使ってください。
39682312
3969=begin original
2313=back
39702314
3971The situation with matching Unicode properties in regular expressions,
2315=head2 Unicode in Perl on EBCDIC
3972the C<\p{}> and C<\P{}> constructs, against these code points is not as
3973clear cut, and how these are handled has changed as we've gained
3974experience.
39752316
3976=end original
2317(EBCDIC 上の Perl での Unicode)
39772318
3978正規表現中で C<\p{}> や C<\P{}> 構文による Unicode 特性を
3979このような符号位置に対してマッチングさせる状況は
3980はっきりしたものではなく、これらをどのように扱うかは
3981経験を積むにつれて変更されてきました。
3982
39832319=begin original
39842320
3985One possibility is to treat any match against these code points as
2321The way Unicode is handled on EBCDIC platforms is still
3986undefined. But since Perl doesn't have the concept of a match being
2322experimental. On such platforms, references to UTF-8 encoding in this
3987undefined, it converts this to failing or C<FALSE>. This is almost, but
2323document and elsewhere should be read as meaning the UTF-EBCDIC
3988not quite, what Perl did from v5.14 (when use of these code points
2324specified in Unicode Technical Report 16, unless ASCII vs. EBCDIC issues
3989became generally reliable) through v5.18. The difference is that Perl
2325are specifically discussed. There is no C<utfebcdic> pragma or
3990treated all C<\p{}> matches as failing, but all C<\P{}> matches as
2326":utfebcdic" layer; rather, "utf8" and ":utf8" are reused to mean
3991succeeding.
2327the platform's "natural" 8-bit encoding of Unicode. See L<perlebcdic>
2328for more discussion of the issues.
39922329
39932330=end original
39942331
3995一つ可能性は、これら符号位置に対るあらゆるマッチングを
2332EBCDIC プラットフォームで Unicode 扱い方は未だ実験的で
3996未定義として扱うこす。
2333このよなプラットフォームでは、の文書やその他
3997しかし、Perl はマッチングが未定義であるという概念を持っていない
2334UTF-8 コーディン言及は特に ASCII 対 EBCDIC 問題について
3998れは失敗または C<FALSE> に変換されます。
2335議論さている場合でない限りは、Unicode Technical Report 16 で
3999は、(完全にではありませんが) ほぼ (これら符号位置が一般的に
2336定義さている UTF-EBCDIC を意味するもとして読むべきです。
4000信頼できるようになった) v5.14 から v5.18 での動作です。
2337C<utfebcdic> プラグマや ":utfebcdic" 層はありせん;
4001違いはPerl は全ての C<\p{}> マッチングを失敗として扱うけれども
2338代わりに"utf8" ":utf8" そのプラットフォームの「自然な」
4002全てC<\P{}> ングは成功として扱ことです。
2339Unicode 8 トエコーディンを意味するよに再利用されています。
2340この問題に関する更なる議論については L<perlebcdic> を参照してください。
40032341
4004=begin original
2342=head2 Locales
40052343
4006One problem with this is that it leads to unexpected, and confusing
2344(ロケール)
4007results in some cases:
40082345
4009=end original
4010
4011これの問題の一つは、場合によっては、予想外で混乱する結果が
4012導かれることです:
4013
4014 chr(0x110000) =~ \p{ASCII_Hex_Digit=True} # Failed on <= v5.18
4015 chr(0x110000) =~ \p{ASCII_Hex_Digit=False} # Failed! on <= v5.18
4016
40172346=begin original
40182347
4019That is, it treated both matches as undefined, and converted that to
2348Usually locale settings and Unicode do not affect each other, but
4020false (raising a warning on each). The first case is the expected
2349there are a couple of exceptions:
4021result, but the second is likely counterintuitive: "How could both be
4022false when they are complements?" Another problem was that the
4023implementation optimized many Unicode property matches down to already
4024existing simpler, faster operations, which don't raise the warning. We
4025chose to not forgo those optimizations, which help the vast majority of
4026matches, just to generate a warning for the unlikely event that an
4027above-Unicode code point is being matched against.
40282350
40292351=end original
40302352
4031つまり、両方マッチングは未して扱われ
2353通常ロケール定と Unicode は互いに影響を及ぼすことはありませんが
4032偽に変換されます (それぞれ警告発生します)。
2354いくつかの例外あります:
4033最初の場合は予想される結果ですが、2 番目のものはおそらく直感に反します:
4034「補集合の両方で失敗するってどういうこと?」
4035もう一つの問題は、多くの Unicode 特性は、警告を発生させない、
4036既存のより単純で高速な演算に最適化される実装であることです。
4037私たちは、単に Unicode を超える符号位置に対してマッチングをするという
4038めったに起きないことで警告を出すということのために、
4039圧倒的多数のマッチングの助けになるこれらの最適化をしないで
4040済ませるということはしないことを選びました;
40412355
4042=begin original
4043
4044As a result of these problems, starting in v5.20, what Perl does is
4045to treat non-Unicode code points as just typical unassigned Unicode
4046characters, and matches accordingly. (Note: Unicode has atypical
4047unassigned code points. For example, it has noncharacter code points,
4048and ones that, when they do get assigned, are destined to be written
4049Right-to-left, as Arabic and Hebrew are. Perl assumes that no
4050non-Unicode code point has any atypical properties.)
4051
4052=end original
4053
4054これらの問題の結果として、v5.20 から Perl が行うことは、
4055非 Unicode 符号位置を単なる典型的な未割り当て Unicode 文字として扱い、
4056それに応じてマッチングするということです。
4057(注意: Unicode には典型的でない未割り当て符号位置があります。
4058例えば、非文字符号位置があります; 割り当てられたときにはそうだったものの
4059一つは、アラビア語やヘブライ語のように右から左に書かれることになるものです。
4060Perl は、非 Unicode 符号位置に典型的でない属性はないことを仮定しています。)
4061
4062=begin original
4063
4064Perl, in most cases, will raise a warning when matching an above-Unicode
4065code point against a Unicode property when the result is C<TRUE> for
4066C<\p{}>, and C<FALSE> for C<\P{}>. For example:
4067
4068=end original
4069
4070ほとんどの場合、Perl は、Unicode 特性を Unicode を超える符号位置に
4071マッチングして、結果が C<\p{}> なら C<TRUE>、C<\P{}> なら C<FALSE> の
4072場合、警告を発生させます。
4073例えば:
4074
4075 chr(0x110000) =~ \p{ASCII_Hex_Digit=True} # Fails, no warning
4076 chr(0x110000) =~ \p{ASCII_Hex_Digit=False} # Succeeds, with warning
4077
4078=begin original
4079
4080In both these examples, the character being matched is non-Unicode, so
4081Unicode doesn't define how it should match. It clearly isn't an ASCII
4082hex digit, so the first example clearly should fail, and so it does,
4083with no warning. But it is arguable that the second example should have
4084an undefined, hence C<FALSE>, result. So a warning is raised for it.
4085
4086=end original
4087
4088これら両方の例において、マッチングする文字は非 Unicode なので、
4089Unicode はこれがどのようにマッチングするべきかを定義していません。
4090これは明らかに ASCII 16 進文字ではないので、
4091最初の例は明らかに失敗するべきで、実際警告なしで失敗します。
4092しかし 2 番目の例は未定義の、つまり C<FALSE> の結果となるべきです。
4093従って警告が発生します。
4094
4095=begin original
4096
4097Thus the warning is raised for many fewer cases than in earlier Perls,
4098and only when what the result is could be arguable. It turns out that
4099none of the optimizations made by Perl (or are ever likely to be made)
4100cause the warning to be skipped, so it solves both problems of Perl's
4101earlier approach. The most commonly used property that is affected by
4102this change is C<\p{Unassigned}> which is a short form for
4103C<\p{General_Category=Unassigned}>. Starting in v5.20, all non-Unicode
4104code points are considered C<Unassigned>. In earlier releases the
4105matches failed because the result was considered undefined.
4106
4107=end original
4108
4109従って、警告は以前の Perl よりも遙かに少ない場合で、
4110結果に議論の余地がある場合にのみ発生します。
4111Perl によって行われた (および行われうる) どの最適化によっても
4112警告は飛ばされなくなったので、Perl の以前の手法の二つの問題両方を
4113解決しています。
4114この変更の影響を受ける、もっともよく使われている特性は、
4115C<\p{General_Category=Unassigned}> の短縮版である C<\p{Unassigned}> です。
4116v5.20 から、全ての非 Unicode 符号位置は C<Unassigned> として扱われます。
4117以前のリリースでは、結果は未定義として扱われていたのでこのマッチングは
4118失敗していました。
4119
4120=begin original
4121
4122The only place where the warning is not raised when it might ought to
4123have been is if optimizations cause the whole pattern match to not even
4124be attempted. For example, Perl may figure out that for a string to
4125match a certain regular expression pattern, the string has to contain
4126the substring C<"foobar">. Before attempting the match, Perl may look
4127for that substring, and if not found, immediately fail the match without
4128actually trying it; so no warning gets generated even if the string
4129contains an above-Unicode code point.
4130
4131=end original
4132
4133警告が発生するべきかもしれないけれでも発生しない唯一の場所は、
4134最適化によってパターンマッチング自体が試みられさえもしなかった場合です。
4135例えば、ある正規表現パターンにマッチングする文字列に対して、
4136文字列が特定の部分文字列 C<"foobar"> を含んでいなければならないことに
4137Perl が気付いたとします。
4138マッチングを試みる前に Perl はその部分文字列を探し、もし見つからなければ、
4139実際にマッチングを試みる前に直ちに失敗します;
4140従って、文字列に非 Unicode 符号位置が含まれていたとしても、
4141警告は発生しません。
4142
4143=begin original
4144
4145This behavior is more "Do what I mean" than in earlier Perls for most
4146applications. But it catches fewer issues for code that needs to be
4147strictly Unicode compliant. Therefore there is an additional mode of
4148operation available to accommodate such code. This mode is enabled if a
4149regular expression pattern is compiled within the lexical scope where
4150the C<"non_unicode"> warning class has been made fatal, say by:
4151
4152=end original
4153
4154この振る舞いは、ほとんどのアプリケーションにとって、
4155以前の Perl よりもより「空気を読む」ものです。
4156しかし、これは厳密に Unicode に準拠していることが必要なコードにとっては
4157より少ないながらも問題があります。
4158従って、そのようなコードに適応するために追加の
4159操作モードが利用可能です。
4160このモードは次のように、C<"non_unicode"> 警告クラスが致命的になっている
4161レキシカルスコープ内で正規表現がコンパイルされたときに有効になります:
4162
4163 use warnings FATAL => "non_unicode"
4164
4165=begin original
4166
4167(see L<warnings>). In this mode of operation, Perl will raise the
4168warning for all matches against a non-Unicode code point (not just the
4169arguable ones), and it skips the optimizations that might cause the
4170warning to not be output. (It currently still won't warn if the match
4171isn't even attempted, like in the C<"foobar"> example above.)
4172
4173=end original
4174
4175(L<warnings> 参照)。
4176この操作モードでは、Perl は (議論の余地のあるものだけでなく)
4177非 Unicode 符号位置に対する全てのマッチングで警告を出力し、
4178警告が出力されなくなるかもしれない最適化を飛ばします。
4179(現在のところ、前述の C<"foobar"> の例のように、マッチングが試みられさえ
4180しなかった場合は、警告は出ないままです。)
4181
4182=begin original
4183
4184In summary, Perl now normally treats non-Unicode code points as typical
4185Unicode unassigned code points for regular expression matches, raising a
4186warning only when it is arguable what the result should be. However, if
4187this warning has been made fatal, it isn't skipped.
4188
4189=end original
4190
4191まとめると、Perl は通常正規表現マッチングでは非 Unicode 符号位置を
4192典型的な Unicode 未割り当て符号位置として扱い、
4193その結果に議論の余地がある場合にのみ警告を出力するようになりました。
4194しかし、警告が致命的になっている場合は、これは飛ばされません。
4195
4196=begin original
4197
4198There is one exception to all this. C<\p{All}> looks like a Unicode
4199property, but it is a Perl extension that is defined to be true for all
4200possible code points, Unicode or not, so no warning is ever generated
4201when matching this against a non-Unicode code point. (Prior to v5.20,
4202it was an exact synonym for C<\p{Any}>, matching code points C<0>
4203through C<0x10FFFF>.)
4204
4205=end original
4206
4207これら全てに関して一つの例外があります。
4208C<\p{All}> は Unicode 特性のように見えますが、
4209これは Unicode であろうがなかろうが全ての可能な符号位置に対して
4210真と定義されている Perl 拡張なので、非 Unicode 符号位置に対してこれを
4211マッチングしても警告は発生しません。
4212(v5.20 より前では、これは C<\p{Any}> の正確な別名で、
4213C<0> から C<0x10FFFF> の符号位置にマッチングしていました。)
4214
4215=head2 Security Implications of Unicode
4216
4217(Unicode のセキュリティへの影響)
4218
4219=begin original
4220
4221First, read
4222L<Unicode Security Considerations|https://www.unicode.org/reports/tr36>.
4223
4224=end original
4225
4226まず、
4227L<Unicode Security Considerations|https://www.unicode.org/reports/tr36> を
4228読んでください。
4229
4230=begin original
4231
4232Also, note the following:
4233
4234=end original
4235
4236また、以下のことに注意してください:
4237
42382356=over 4
42392357
42402358=item *
42412359
42422360=begin original
42432361
4244Malformed UTF-8
2362You can enable automatic UTF-8-ification of your standard file
2363handles, default C<open()> layer, and C<@ARGV> by using either
2364the C<-C> command line switch or the C<PERL_UNICODE> environment
2365variable, see L<perlrun> for the documentation of the C<-C> switch.
42452366
42462367=end original
42472368
4248不正な UTF-8
2369デフォルトの C<open()> 層や C<@ARGV> の標準ファイルハンドルの
2370自動的な UTF-8 化を、C<-C> コマンドラインスイッチか
2371環境変数 C<PERL_UNICODE> によって有効にできます。
2372C<-C> スイッチについての説明は L<perlrun> を参照してください。
42492373
4250=begin original
4251
4252UTF-8 is very structured, so many combinations of bytes are invalid. In
4253the past, Perl tried to soldier on and make some sense of invalid
4254combinations, but this can lead to security holes, so now, if the Perl
4255core needs to process an invalid combination, it will either raise a
4256fatal error, or will replace those bytes by the sequence that forms the
4257Unicode REPLACEMENT CHARACTER, for which purpose Unicode created it.
4258
4259=end original
4260
4261UTF-8 is very structured, so many combinations of bytes are invalid.
4262以前は、Perl はこれと戦って、不正な組み合わせに意味を持たせようとしましたが、
4263これはセキュリティホールを引き起こすことがあったので、
4264今では、Perl コアが不正な組み合わせを処理する必要があると、
4265致命的エラーが発生するか、それらのバイト列を、Unicode がこのために作った
4266Unicode の REPLACEMENT CHARACTER を形成する並びに置き換えます。
4267
4268=begin original
4269
4270Every code point can be represented by more than one possible
4271syntactically valid UTF-8 sequence. Early on, both Unicode and Perl
4272considered any of these to be valid, but now, all sequences longer
4273than the shortest possible one are considered to be malformed.
4274
4275=end original
4276
4277全ての符号位置は、一つの可能な文法的に正当な UTF-8 並び以上の
4278方法で表現できます。
4279以前は、Unicode と Perl はこれら全ても正当であると考えていましたが、
4280今は、最短のもの以外の、より長い全ての並びは不正と考えられます。
4281
4282=begin original
4283
4284Unicode considers many code points to be illegal, or to be avoided.
4285Perl generally accepts them, once they have passed through any input
4286filters that may try to exclude them. These have been discussed above
4287(see "Surrogates" under UTF-16 in L</Unicode Encodings>,
4288L</Noncharacter code points>, and L</Beyond Unicode code points>).
4289
4290=end original
4291
4292Unicode は多くの符号位置を不正または避けるべきと考えています。
4293Perl は、一旦これらを除外しようとする入力フィルタを通過したものは、
4294一般的にこれらを受け入れます。
4295これらは先に議論しています
4296(L</Unicode Encodings> の UTF-16 の「サロゲート」("Surrogates"),
4297L</Noncharacter code points>, L</Beyond Unicode code points> を
4298参照してください)。
4299
43002374=item *
43012375
43022376=begin original
43032377
4304Regular expression pattern matching may surprise you if you're not
2378Perl tries really hard to work both with Unicode and the old
4305accustomed to Unicode. Starting in Perl 5.14, several pattern
2379byte-oriented world. Most often this is nice, but sometimes Perl's
4306modifiers are available to control this, called the character set
2380straddling of the proverbial fence causes problems.
4307modifiers. Details are given in L<perlre/Character set modifiers>.
43082381
43092382=end original
43102383
4311Unicode に慣れていないなら、正規表現パターンマッチングは
2384Perl は Unicode と古いバイト指向の世界の両方で働くため苦労しています。
4312あなたかもしれません。
2385ほとんどの場合はうまくいきますが、ときには Perl が二股をかけていことが
4313Perl 5.14 から、これ制御るためのいくつかのパターンマッチング修飾子が
2386問題引き起ここともあります。
4314利用可能になりました; これは文字集合修飾子と呼ばれます。
4315詳細は L<perlre/Character set modifiers> にあります。
43162387
43172388=back
43182389
4319=begin original
4320
4321As discussed elsewhere, Perl has one foot (two hooves?) planted in
4322each of two worlds: the old world of ASCII and single-byte locales, and
4323the new world of Unicode, upgrading when necessary.
4324If your legacy code does not explicitly use Unicode, no automatic
4325switch-over to Unicode should happen.
4326
4327=end original
4328
4329すでに述べている通り、Perl は二つの世界のそれぞれに片方の足
4330(二つのひづめ?) を突っ込んでいます: ASCII と単一バイトロケールの
4331古い世界と、必要に応じて昇格する Unicode の新しい世界です。
4332もしあなたの古いコードが明示的に Unicode を使っていないのなら、
4333Unicode への切り替えが自動的になされることはありません。
4334
4335=head2 Unicode in Perl on EBCDIC
4336
4337(EBCDIC 上の Perl での Unicode)
4338
4339=begin original
4340
4341Unicode is supported on EBCDIC platforms. See L<perlebcdic>.
4342
4343=end original
4344
4345Unicode は EBCDIC プラットフォームで対応しています。
4346L<perlebcdic> を参照してください。
4347
4348=begin original
4349
4350Unless ASCII vs. EBCDIC issues are specifically being discussed,
4351references to UTF-8 encoding in this document and elsewhere should be
4352read as meaning UTF-EBCDIC on EBCDIC platforms.
4353See L<perlebcdic/Unicode and UTF>.
4354
4355=end original
4356
4357特に ASCII 対 EBCDIC 問題について
4358議論されている場合でない限り、
4359EBCDIC プラットフォームでは、
4360この文書やその他での
4361UTF-8 エンコーディングへの言及は、
4362UTF-EBCDIC を意味するものとして読むべきです。
4363L<perlebcdic/Unicode and UTF> を参照してください。
4364
4365=begin original
4366
4367Because UTF-EBCDIC is so similar to UTF-8, the differences are mostly
4368hidden from you; S<C<use utf8>> (and NOT something like
4369S<C<use utfebcdic>>) declares the script is in the platform's
4370"native" 8-bit encoding of Unicode. (Similarly for the C<":utf8">
4371layer.)
4372
4373=end original
4374
4375UTF-EBCDIC は UTF-8 にとても似ているので、違いはほとんど隠されています;
4376S<C<use utf8>> (そして S<C<use utfebcdic>> のようなものでは「ありません」) は
4377スクリプトがそのプラットフォームの「ネイティブな」Unicode の 8 ビット
4378エンコーディングであることを宣言します。
4379(C<":utf8"> 層も同様です。)
4380
4381=head2 Locales
4382
4383(ロケール)
4384
4385=begin original
4386
4387See L<perllocale/Unicode and UTF-8>
4388
4389=end original
4390
4391L<perllocale/Unicode and UTF-8> を参照してください。
4392
43932390=head2 When Unicode Does Not Happen
43942391
43952392(Unicode ではない場合)
43962393
43972394=begin original
43982395
4399There are still many places where Unicode (in some encoding or
2396While Perl does have extensive ways to input and output in Unicode,
4400another) could be given as arguments or received as results, or both in
2397and few other 'entry points' like the @ARGV which can be interpreted
4401Perl, but it is not, in spite of Perl having extensive ways to input and
2398as Unicode (UTF-8), there still are many places where Unicode (in some
4402output in Unicode, and a few other "entry points" like the C<@ARGV>
2399encoding or another) could be given as arguments or received as
4403array (which can sometimes be interpreted as UTF-8).
2400results, or both, but it is not.
44042401
44052402=end original
44062403
4407Perl には入出力を Unicode で行うための幅広い方法があり、
2404Perl には入出力を Unicode で行うための多数の方法があり、
4408C<@ARGV> 配列のように (時々 UTF-8 として解釈できるような)その他の
2405@ARGV のように Unicode (UTF-8) として解釈できるようなその他の
4409「エントリポイント」くつかあるにも関わらず
2406「エントリポイント」はほとんどな一方(何らかのエンコーディングで)
4410(何かのエンコーディングで)
2407Unicode が引数として与えれたり結果として返されるべきにも関わらず、
4411Unicode が引数とし与えられたり結果として返されたり、ある
2408そうなっていない場所も未だ多くあります。
4412両方であるべきにも関わらず、そうなっていない場所も未だ多くあります。
44132409
44142410=begin original
44152411
4416The following are such interfaces. Also, see L</The "Unicode Bug">.
2412The following are such interfaces. For all of these interfaces Perl
4417For all of these interfaces Perl
2413currently (as of 5.8.3) simply assumes byte strings both as arguments
4418currently (as of v5.16.0) simply assumes byte strings both as arguments
2414and results, or UTF-8 strings if the C<encoding> pragma has been used.
4419and results, or UTF-8 strings if the (deprecated) C<encoding> pragma has been used.
44202415
44212416=end original
44222417
44232418以下に挙げるのはそのようなインターフェースです。
4424また、L</The "Unicode Bug"> を参照してください。
2419これらすべてが現在の Perl(5.8.3) では単純に引数と戻り値の両方が
4425らすべが現在の Perl(v5.16.0)は単純に引数と戻り値の両方が
2420バイト文字列か、C<encoding> プラグマが使われていれば UTF-8 文字列
4426バイト文字列か、(廃止予の) C<encoding> プラグマが使われていれば
2421あると仮ています。
4427UTF-8 文字列であると仮定しています。
44282422
44292423=begin original
44302424
4431One reason that Perl does not attempt to resolve the role of Unicode in
2425One reason why Perl does not attempt to resolve the role of Unicode in
4432these situations is that the answers are highly dependent on the operating
2426this cases is that the answers are highly dependent on the operating
44332427system and the file system(s). For example, whether filenames can be
4434in Unicode and in exactly what kind of encoding, is not exactly a
2428in Unicode, and in exactly what kind of encoding, is not exactly a
4435portable concept. Similarly for C<qx> and C<system>: how well will the
2429portable concept. Similarly for the qx and system: how well will the
4436"command-line interface" (and which of them?) handle Unicode?
2430'command line interface' (and which of them?) handle Unicode?
44372431
44382432=end original
44392433
4440このような状況において、Perl が Unicode による解決をしないのかの
2434このようなケースにおいて、Perl がなぜ Unicode による解決を
4441理由の一つは、答えがオペレーティングシステムや
2435しないのかの理由の一つは、答えがオペレーティングシステムや
44422436ファイルシステムに強く依存しているからです。
44432437たとえば、ファイル名が Unicode で記述できてエンコーディングが
44442438合っていたとしてもそれは移植性のあるコンセプトではないのです。
4445同様なことが C<qx>C<system> にも言えます:
2439同様なことが qx や system にも言えます:
44462440「コマンドラインインターフェース」は Unicode をどのように
44472441扱うのでしょうか?
44482442
44492443=over 4
44502444
44512445=item *
44522446
4453C<chdir>, C<chmod>, C<chown>, C<chroot>, C<exec>, C<link>, C<lstat>, C<mkdir>,
2447chdir, chmod, chown, chroot, exec, link, lstat, mkdir,
4454C<rename>, C<rmdir>, C<stat>, C<symlink>, C<truncate>, C<unlink>, C<utime>, C<-X>
2448rename, rmdir, stat, symlink, truncate, unlink, utime, -X
44552449
44562450=item *
44572451
4458C<%ENV>
2452%ENV
44592453
44602454=item *
44612455
44622456=begin original
44632457
4464C<glob> (aka the C<E<lt>*E<gt>>)
2458glob (aka the <*>)
44652459
44662460=end original
44672461
4468C<glob> (または C<E<lt>*E<gt>>)
2462glob (または <*>)
44692463
44702464=item *
44712465
4472C<open>, C<opendir>, C<sysopen>
2466open, opendir, sysopen
44732467
44742468=item *
44752469
44762470=begin original
44772471
4478C<qx> (aka the backtick operator), C<system>
2472qx (aka the backtick operator), system
44792473
44802474=end original
44812475
4482C<qx> (または逆クォート演算子), C<system>
2476qx (または逆クォート演算子), system
44832477
44842478=item *
44852479
4486C<readdir>, C<readlink>
2480readdir, readlink
44872481
44882482=back
44892483
4490=head2 The "Unicode Bug"
2484=head2 Forcing Unicode in Perl (Or Unforcing Unicode in Perl)
44912485
4492(Unicode バグ」)
2486(Unicode を Perl に強制する (あるいは Unicode でないことを Perl に強制する))
44932487
44942488=begin original
44952489
4496The term, "Unicode bug" has been applied to an inconsistency with the
2490Sometimes (see L</"When Unicode Does Not Happen">) there are
4497code points in the C<Latin-1 Supplement> block, that is, between
2491situations where you simply need to force Perl to believe that a byte
4498128 and 255. Without a locale specified, unlike all other characters or
2492string is UTF-8, or vice versa. The low-level calls
4499code points, these characters can have very different semantics
2493utf8::upgrade($bytestring) and utf8::downgrade($utf8string) are
4500depending on the rules in effect. (Characters whose code points are
2494the answers.
4501above 255 force Unicode rules; whereas the rules for ASCII characters
4502are the same under both ASCII and Unicode rules.)
45032495
45042496=end original
45052497
4506Unicode バグ」("Unicode bug")という用語は
2498ときとして(L</When Unicode Does Not Happen> を参照)、Perl にバイト列を
4507C<Latin-1 Supplement> ブロック、つまり 128 から 255 にある符号位置
2499UTF-8 あるように強制したりそ逆を行う場合があるかもしれません。
4508非一貫性に対て使われます。
2500低レベルの呼び出 utf8::upgrade($bytestring) と
4509その他の文字や符号位置とは異なり、これらの文字は
2501utf8::downgrade($utf8string) がその回答です。
4510有効な規則によってとても異なったセマンティクスです。
4511(255 を超える符号位置の文字は Unicode の規則が強制されます;
4512一方 ASCII 文字のための規則は、ASCII と Unicode の規則で同じです。)
45132502
45142503=begin original
45152504
4516Under Unicode rules, these upper-Latin1 characters are interpreted as
2505Do not use them without careful thought, though: Perl may easily get
4517Unicode code points, which means they have the same semantics as Latin-1
2506very confused, angry, or even crash, if you suddenly change the 'nature'
4518(ISO-8859-1) and C1 controls.
2507of scalar like that. Especially careful you have to be if you use the
2508utf8::upgrade(): any random byte string is not valid UTF-8.
45192509
45202510=end original
45212511
4522Unicode の規則の下では、これらの上位の Latin1 文字は Unicode 符号位置とし
2512しかし、これらを使うきには十分注意なければなりません: あなたが突然
4523解釈され、Latin-1 (ISO-8859-1) および C1 制御文字と
2513スカラのような'性質'(nature)を突然変えたりしたら、Perl は簡単に混乱し、
4524同じセマンティスを持ちます。
2514怒り、ラッシュしてしまいます。
2515utf8::upgrade() を使うときには特に注意が必要です: 任意のランダムな
2516バイト列は正当な UTF-8 ではありません。
45252517
4526=begin original
2518=head2 Using Unicode in XS
45272519
4528As explained in L</ASCII Rules versus Unicode Rules>, under ASCII rules,
2520(XS Unicode を使う)
4529they are considered to be unassigned characters.
45302521
4531=end original
4532
4533L</ASCII Rules versus Unicode Rules> で説明されているように、
4534ASCII の規則では、これらは未割り当て文字と見なされます。
4535
45362522=begin original
45372523
4538This can lead to unexpected results. For example, a string's
2524If you want to handle Perl Unicode in XS extensions, you may find the
4539semantics can suddenly change if a code point above 255 is appended to
2525following C APIs useful. See also L<perlguts/"Unicode Support"> for an
4540it, which changes the rules from ASCII to Unicode. As an
2526explanation about Unicode at the XS level, and L<perlapi> for the API
4541example, consider the following program and its output:
2527details.
45422528
45432529=end original
45442530
4545これによ、予期しな結果が生じ可能性があります。
2531Perl の Unicode を XS 拡張で取たいと思うのなら、以下に挙げ
4546たとえば、255 を超えるコードポイント文字列に追加さた場合、
2532API 便利かも知ません。
4547文字列のセマンティクスが突然変更され、規則が ASCII から Unicode に
2533XS レベルでの Unicode に関しての説明は L<perlguts/"Unicode Support"> を、
4548変更れる可能性があります
2534API の詳細については L<perlapi> を参照してくだ
4549例として、次のプログラムとその出力を考えてみます:
45502535
4551 $ perl -le'
2536=over 4
4552 no feature "unicode_strings";
4553 $s1 = "\xC2";
4554 $s2 = "\x{2660}";
4555 for ($s1, $s2, $s1.$s2) {
4556 print /\w/ || 0;
4557 }
4558 '
4559 0
4560 0
4561 1
45622537
4563=begin original
2538=item *
45642539
4565If there's no C<\w> in C<s1> nor in C<s2>, why does their concatenation
4566have one?
4567
4568=end original
4569
4570C<s1> や C<s2> に C<\w> がなければ、なぜこれらの結合は一つになるのでしょう?
4571
45722540=begin original
45732541
4574This anomaly stems from Perl's attempt to not disturb older programs that
2542C<DO_UTF8(sv)> returns true if the C<UTF8> flag is on and the bytes
4575didn't use Unicode, along with Perl's desire to add Unicode support
2543pragma is not in effect. C<SvUTF8(sv)> returns true is the C<UTF8>
4576seamlessly. But the result turned out to not be seamless. (By the way,
2544flag is on; the bytes pragma is ignored. The C<UTF8> flag being on
4577you can choose to be warned when things like this happen. See
2545does B<not> mean that there are any characters of code points greater
4578C<L<encoding::warnings>>.)
2546than 255 (or 127) in the scalar or that there are even any characters
2547in the scalar. What the C<UTF8> flag means is that the sequence of
2548octets in the representation of the scalar is the sequence of UTF-8
2549encoded code points of the characters of a string. The C<UTF8> flag
2550being off means that each octet in this representation encodes a
2551single character with code point 0..255 within the string. Perl's
2552Unicode model is not to use UTF-8 until it is absolutely necessary.
45792553
45802554=end original
45812555
4582この異常Unicode使用していない、
2556C<DO_UTF8(sv)> C<UTF8> フラグがオンでバイトプラグマが効果
4583プログラムを妨害しないようにしようという Perl の試みと、
2557もっていないとき真を返ます。
4584Unicode 対応をシームレスに追加しようとする Perl
2558C<SvUTF8(sv)> C<UTF8> がオンとき、バイトプラグマの状態には
4585願望によるものです。
2559関係なく真を返します。
4586しかしその結果シームレになりませんでした。
2560C<UTF8> フラグはスカラの中 255(もくは127)を超える符号位置の文字が
4587(ころで、このよことが起きたときに警告されるようにでき
2561あるうことを I<意味しせん>
4588C<L<encoding::warnings>> を参照してください。)
2562C<UTF8> フラグの意味するところは、スカラ中のそのオクテットの並びが
2563文字列としてUTF-8でエンコードされた符号位置の並びだということです。
2564C<UTF8> フラグがオフであるということは文字列の中のエンコードされた
2565文字が 0..255 の範囲でエンコードされたオクテットであることを意味します。
2566Perl の Unicode モデルは本当に必要となるまで UTF-8 を使用しません。
45892567
2568=item *
2569
45902570=begin original
45912571
4592L<S<C<use feature 'unicode_strings'>>|feature/The 'unicode_strings' feature>
2572C<uvuni_to_utf8(buf, chr)> writes a Unicode character code point into
4593was added, starting in Perl v5.12, to address this problem. It affects
2573a buffer encoding the code point as UTF-8, and returns a pointer
4594these things:
2574pointing after the UTF-8 bytes.
45952575
45962576=end original
45972577
4598Perl v5.12 から、こ問題に対応に対応するために
2578C<uvuni_to_utf8(buf, chr)> Unicode 文字符号位置を UTF-8 で
4599L<S<C<use feature 'unicode_strings'>>|feature/The 'unicode_strings' feature>
2579エンコードされたの符号位置としてバッファに書き込みます。
4600が追加されま
2580て、その UTF-8 バイトの後を指し示すポインタを返します
4601これは以下のような影響があります:
46022581
4603=over 4
4604
46052582=item *
46062583
46072584=begin original
46082585
4609Changing the case of a scalar, that is, using C<uc()>, C<ucfirst()>, C<lc()>,
2586C<utf8_to_uvuni(buf, lenp)> reads UTF-8 encoded bytes from a buffer and
4610and C<lcfirst()>, or C<\L>, C<\U>, C<\u> and C<\l> in double-quotish
2587returns the Unicode character code point and, optionally, the length of
4611contexts, such as regular expression substitutions.
2588the UTF-8 byte sequence.
46122589
46132590=end original
46142591
4615スカラの大文字小文字を変える; つまり、C<uc()>, C<ucfirst()>, C<lc()>,
2592C<utf8_to_uvuni(buf, lenp)> はバッファから UTF-8 エンコードされたバイトを
4616C<lcfirst()> を使ったり、正規表現ようなダブルクォート風
2593読み出し、Unicode の文字符号位と、オプションでそ
4617テキ中で C<\L>, C<\U>, C<\u>, C<\l> 使う
2594UTF-8 バイトシーケンスの長さ返します
46182595
2596=item *
2597
46192598=begin original
46202599
4621Under C<unicode_strings> starting in Perl 5.12.0, Unicode rules are
2600C<utf8_length(start, end)> returns the length of the UTF-8 encoded buffer
4622generally used. See L<perlfunc/lc> for details on how this works
2601in characters. C<sv_len_utf8(sv)> returns the length of the UTF-8 encoded
4623in combination with various other pragmas.
2602scalar.
46242603
46252604=end original
46262605
4627Perl 5.12.0 からの C<unicode_strings> 、一般的に
2606C<utf8_length(start, end)> は UTF-8 エンコードされたバッファの長さを
4628Unicode の規則が使われます。
2607文字で返します。
4629さまざまなプラグマと組み合わせて動作る方法の
2608C<sv_len_utf8(sv)> は UTF-8 エンコードさたスカラの長を返します
4630詳細については、L<perlfunc/lc> を参照してください。
46312609
46322610=item *
46332611
46342612=begin original
46352613
4636Using caseless (C</i>) regular expression matching.
2614C<sv_utf8_upgrade(sv)> converts the string of the scalar to its UTF-8
2615encoded form. C<sv_utf8_downgrade(sv)> does the opposite, if
2616possible. C<sv_utf8_encode(sv)> is like sv_utf8_upgrade except that
2617it does not set the C<UTF8> flag. C<sv_utf8_decode()> does the
2618opposite of C<sv_utf8_encode()>. Note that none of these are to be
2619used as general-purpose encoding or decoding interfaces: C<use Encode>
2620for that. C<sv_utf8_upgrade()> is affected by the encoding pragma
2621but C<sv_utf8_downgrade()> is not (since the encoding pragma is
2622designed to be a one-way street).
46372623
46382624=end original
46392625
4640文字小文字無視した (C</i>) 正規表現マッチグを使う。
2626C<sv_utf8_upgrade(sv)> はスカラの文字その UTF-8 コードされた
2627形式に変換します。
2628C<sv_utf8_downgrade(sv)> は(可能であれば)その反対の動作をします。
2629C<sv_utf8_encode(sv)> は C<sv_utf8_upgrade> に似ていますが、
2630C<UTF8> フラグをセットしない点が異なります。
2631これらの欠如が一般的な目的のエンコーディングやデコーディングの
2632インターフェースとして使われていることに注意してください:
2633C<use Encode> がそのためにあります。
2634C<sv_utf8_upgrade()> はエンコーディングプラグマに影響を受けますが、
2635C<sv_utf8_downgrade()> はそうではありません(なぜならエンコーディング
2636プラグマは一方通行にデザインされているからです)。
46412637
2638=item *
2639
46422640=begin original
46432641
4644Starting in Perl 5.14.0, regular expressions compiled within
2642C<is_utf8_char(s)> returns true if the pointer points to a valid UTF-8
4645the scope of C<unicode_strings> use Unicode rules
2643character.
4646even when executed or compiled into larger
4647regular expressions outside the scope.
46482644
46492645=end original
46502646
4651Perl 5.14.0 から、C<unicode_strings> のスコープ内でコンパルされた
2647C<is_utf8_char(s)> はポンタが正しい UTF-8 文字を指し示しているときに
4652正規表現は、スコープの外で実行されたり、
2648真を返します。
4653より大きな正規表現の中にコンパイルされたりした場合でも、
4654Unicode の規則を使います。
46552649
46562650=item *
46572651
46582652=begin original
46592653
4660Matching any of several properties in regular expressions.
2654C<is_utf8_string(buf, len)> returns true if C<len> bytes of the buffer
2655are valid UTF-8.
46612656
46622657=end original
46632658
4664規表現中にくつかの特性を使う。
2659C<is_utf8_string(buf, len)> はバッファの C<len> バイトが
2660UTF-8 文字であるときに真を返します。
46652661
2662=item *
2663
46662664=begin original
46672665
4668These properties are C<\b> (without braces), C<\B> (without braces),
2666C<UTF8SKIP(buf)> will return the number of bytes in the UTF-8 encoded
4669C<\s>, C<\S>, C<\w>, C<\W>, and all the Posix character classes
2667character in the buffer. C<UNISKIP(chr)> will return the number of bytes
4670I<except> C<[[:ascii:]]>.
2668required to UTF-8-encode the Unicode character code point. C<UTF8SKIP()>
2669is useful for example for iterating over the characters of a UTF-8
2670encoded buffer; C<UNISKIP()> is useful, for example, in computing
2671the size required for a UTF-8 encoded buffer.
46712672
46722673=end original
46732674
4674その特性は、(大かっこなしの) C<\b>, (大かっこなし) C<\B>,
2675C<UTF8SKIP(buf)> はバッファ中にある UTF-8 エンコードされた文字の
4675C<\s>, C<\S>, C<\w>, C<\W> および、
2676バイト数を返します。
4676C<[[:ascii:]]> I<以外の> Posix 文字クラスで
2677C<UNISKIP(chr)> UTF-8 エンコードする Unicode 文字の符号位置が要求
2678バイト数を返します。
2679C<UTF8SKIP()> は UTF-8 エンコードされたバッファの文字に対して繰り返しを
2680行うような例に便利です。
2681C<UNISKIP()> はたとえば、UTF-8 エンコードされたバッファの要求する大きさを
2682計算するのに便利です。
46772683
2684=item *
2685
46782686=begin original
46792687
4680Starting in Perl 5.14.0, regular expressions compiled within
2688C<utf8_distance(a, b)> will tell the distance in characters between the
4681the scope of C<unicode_strings> use Unicode rules
2689two pointers pointing to the same UTF-8 encoded buffer.
4682even when executed or compiled into larger
4683regular expressions outside the scope.
46842690
46852691=end original
46862692
4687Perl 5.14.0 から、C<unicode_strings> のスコープ内でコンパイルされた
2693C<utf8_distance(a, b)> は同じ UTF-8 エンコーされたバッファをさす
4688正規表現は、スコープ外で実行されたり、
2694二つポインタの間の文字単位の距離を返します。
4689より大きな正規表現の中にコンパイルされたりした場合でも、
4690Unicode の規則を使います。
46912695
46922696=item *
46932697
46942698=begin original
46952699
4696In C<quotemeta> or its inline equivalent C<\Q>.
2700C<utf8_hop(s, off)> will return a pointer to an UTF-8 encoded buffer
2701that is C<off> (positive or negative) Unicode characters displaced
2702from the UTF-8 buffer C<s>. Be careful not to overstep the buffer:
2703C<utf8_hop()> will merrily run off the end or the beginning of the
2704buffer if told to do so.
46972705
46982706=end original
46992707
4700C<quotemeta> インラインの等価物ある C<\Q> の中。
2708C<utf8_hop(s, off)> UTF-8 バッファ C<s> から Unicode で C<off> 文字分
2709(正数でも負数でも) 移動した UTF-8 エンコーディングバッファへの
2710ポインタを返します。
2711バッファを超えないように注意してください: C<utf8_hop()> は、そう
2712指示されれば何も気にせずにバッファの先頭や末尾を踏み越えます。
47012713
2714=item *
2715
47022716=begin original
47032717
4704Starting in Perl 5.16.0, consistent quoting rules are used within the
2718C<pv_uni_display(dsv, spv, len, pvlim, flags)> and
4705scope of C<unicode_strings>, as described in L<perlfunc/quotemeta>.
2719C<sv_uni_display(dsv, ssv, pvlim, flags)> are useful for debugging the
4706Prior to that, or outside its scope, no code points above 127 are quoted
2720output of Unicode strings and scalars. By default they are useful
4707in UTF-8 encoded strings, but in byte encoded strings, code points
2721only for debugging--they display B<all> characters as hexadecimal code
4708between 128-255 are always quoted.
2722points--but with the flags C<UNI_DISPLAY_ISPRINT>,
2723C<UNI_DISPLAY_BACKSLASH>, and C<UNI_DISPLAY_QQ> you can make the
2724output more readable.
47092725
47102726=end original
47112727
4712Perl 5.16.0 から、L<perlfunc/quotemeta> で記述されているように、
2728C<pv_uni_display(dsv, spv, len, pvlim, flags)>
4713C<unicode_strings> のスコープ中では、
2729C<sv_uni_display(dsv, ssv, pvlim, flags)> は Unicode 文字列やカラ
4714一貫したクォート規則が使われます。
2730出力をデバッグするのに便利です。
4715それ以前あったり、スコープ外場合、
2731デフォルトはデバッグみに便利です -- B<すべての> 文字を
4716UTF-8 エンコードされた文字列では 128 を超える符号位置の文字は
273216 進の符号位置として表示します -- しかし C<UNI_DISPLAY_ISPRINT>,
4717クォートされなが、
2733C<UNI_DISPLAY_BACKSLASH>, C<UNI_DISPLAY_QQ> とうフラグを
4718バイトエンコードされた文字列では、128-255 の符号位置は常にクォートされる。
2734与えことによって、出力を読みやすくできます
47192735
47202736=item *
47212737
47222738=begin original
47232739
4724In the C<..> or L<range|perlop/Range Operators> operator.
2740C<ibcmp_utf8(s1, pe1, u1, l1, u1, s2, pe2, l2, u2)> can be used to
2741compare two strings case-insensitively in Unicode. For case-sensitive
2742comparisons you can just use C<memEQ()> and C<memNE()> as usual.
47252743
47262744=end original
47272745
4728C<..> という L<範囲|perlop/Range Operators> 演算子の中。
2746C<ibcmp_utf8(s1, pe1, u1, l1, u1, s2, pe2, l2, u2)> は Unicode に
2747おいて大小文字を無視した文字列比較に使うことができます。
2748大小文字を意識した比較には通常どおり C<memEQ()> や C<memNE()> を
2749使うことができます。
47292750
2751=back
2752
47302753=begin original
47312754
4732Starting in Perl 5.26.0, the range operator on strings treats their lengths
2755For more information, see L<perlapi>, and F<utf8.c> and F<utf8.h>
4733consistently within the scope of C<unicode_strings>. Prior to that, or
2756in the Perl source code distribution.
4734outside its scope, it could produce strings whose length in characters
4735exceeded that of the right-hand side, where the right-hand side took up more
4736bytes than the correct range endpoint.
47372757
47382758=end original
47392759
4740Perl 5.26.0 から文字列へ範囲演算子は、
2760もっと詳しい情報は、L<perlapi> Perl ソースコード配布の
4741C<unicode_strings> のスコープ内で、その長さ一貫性を持っます
2761F<utf8.c> と F<utf8.h> を参照しください。
4742それより前、あるいはスコープの外では、
4743右側が正しい範囲の端点より多くのバイト数を必要とする場所では、
4744右側の長さを超えた長さの文字を生成することがあります。
47452762
4746=item *
2763=head1 BUGS
47472764
4748=begin original
2765=head2 Interaction with Locales
47492766
4750In L<< C<split>'s special-case whitespace splitting|perlfunc/split >>.
2767(ロケールとの相互作用)
47512768
4752=end original
4753
4754L<< C<split> の空白分割の特殊処理|perlfunc/split >> の中。
4755
47562769=begin original
47572770
4758Starting in Perl 5.28.0, the C<split> function with a pattern specified as
2771Use of locales with Unicode data may lead to odd results. Currently,
4759a string containing a single space handles whitespace characters consistently
2772Perl attempts to attach 8-bit locale info to characters in the range
4760within the scope of C<unicode_strings>. Prior to that, or outside its scope,
27730..255, but this technique is demonstrably incorrect for locales that
4761characters that are whitespace according to Unicode rules but not according to
2774use characters above that range when mapped into Unicode. Perl's
4762ASCII rules were treated as field contents rather than field separators when
2775Unicode support will also tend to run slower. Use of locales with
4763they appear in byte-encoded strings.
2776Unicode is discouraged.
47642777
47652778=end original
47662779
4767Perl 5.28.0 から、単一の空白からなる文字列をパターとし
2780Unicode デーと共にロケルを使うこはおかな結果を
4768指定され C<split> 関数は、C<unicode_strings> のスコープ内
2781らすことになりやすいす。
4769空白文字を一貫性を持って扱います。
2782現在のところ、Perl は文字に 0..255 の範囲の 8 ビットロケール
4770それよ前、あるはスコープ外で
2783当てようとしてますが、こテクニック Unicode に
4771Unicode 規則では空白だけれども ASCII 規則ではそうではない文字は、
2784マップしようとしたときに先範囲の文字を使用するロケールに対して
4772バイトエンコードされた文字列現れた場合、
2785明らか正しくありません。
4773フィルド区切りでなくフィールドの内容として扱われていた。
2786Perl の Unicode サポはまた、遅くなりがちです
2787Unicode といっしょにロケールを使うことはお勧めできません。
47742788
4775=back
2789=head2 Interaction with Extensions
47762790
2791(エクステンションとの相互作用)
2792
47772793=begin original
47782794
4779You can see from the above that the effect of C<unicode_strings>
2795When Perl exchanges data with an extension, the extension should be
4780increased over several Perl releases. (And Perl's support for Unicode
2796able to understand the UTF8 flag and act accordingly. If the
4781continues to improve; it's best to use the latest available release in
2797extension doesn't know about the flag, it's likely that the extension
4782order to get the most complete and accurate results possible.) Note that
2798will return incorrectly-flagged data.
4783C<unicode_strings> is automatically chosen if you S<C<use v5.12>> or
4784higher.
47852799
47862800=end original
47872801
4788前述のところから、C<unicode_strings> の効果は Perl のリリースが進むにつれて
2802Perl がエクステンションとデタをやり取りするとき、そのエクテンションは
4789拡大ていることが分かります。
2803UTF8 フラグを理解た、それに従った振る舞いをすべきです。
4790(そして Perl Unicode 対応は改良し続けられています;
2804エクステンションがこフラグについて何も知なけば、そのエクステンションは
4791最大限に完全で結果を得るめには、利用可能な最新のリリ
2805しくいフラグがつい返す可能性があります。
4792使うのが最良です。)
4793S<C<use v5.12>> 以上を使うと、C<unicode_strings> は自動的に選択されることに
4794注意してください。
47952806
47962807=begin original
47972808
4798For Perls earlier than those described above, or when a string is passed
2809So if you're working with Unicode data, consult the documentation of
4799to a function outside the scope of C<unicode_strings>, see the next section.
2810every module you're using if there are any issues with Unicode data
2811exchange. If the documentation does not talk about Unicode at all,
2812suspect the worst and probably look at the source to learn how the
2813module is implemented. Modules written completely in Perl shouldn't
2814cause problems. Modules that directly or indirectly access code written
2815in other programming languages are at risk.
48002816
48012817=end original
48022818
4803前述したものより古い Perl場合や文字列が C<unicode_strings>
2819そのめ、 Unicode データを扱おうというであればUnicode データ
4804スコープ外のから渡された場合、次参照してください。
2820交換にして何らの記述があるのな使うモジュールすべてドキュメント
2821調べてください。
2822ドキュメントが Unicode に関して何の言及もしていないのなら、最悪のケースを
2823考慮し、そしてそのモジュールがどのように実装されているかを知るために
2824ソースを見ることになるかもしれません。
2825完全に Perl で書かれたモジュールは問題を引き起こしません。
2826他のプログラミング言語で書かれている直接または間接にアクセスするコードに
2827リスクがあるのです。
48052828
4806=head2 Forcing Unicode in Perl (Or Unforcing Unicode in Perl)
4807
4808(Unicode を Perl に強制する (あるいは Unicode でないことを Perl に強制する))
4809
48102829=begin original
48112830
4812Sometimes (see L</"When Unicode Does Not Happen"> or L</The "Unicode Bug">)
2831For affected functions, the simple strategy to avoid data corruption is
4813there are situations where you simply need to force a byte
2832to always make the encoding of the exchanged data explicit. Choose an
4814string into UTF-8, or vice versa. The standard module L<Encode> can be
2833encoding that you know the extension can handle. Convert arguments passed
4815used for this, or the low-level calls
2834to the extensions to that encoding and convert results back from that
4816L<C<utf8::upgrade($bytestring)>|utf8/Utility functions> and
2835encoding. Write wrapper functions that do the conversions for you, so
4817L<C<utf8::downgrade($utf8string[, FAIL_OK])>|utf8/Utility functions>.
2836you can later change the functions when the extension catches up.
48182837
48192838=end original
48202839
4821ときとして(L</When Unicode Does Not Happen> を参照)、バイト列
2840影響を受けた関数のための、データの劣化(data corruption)を防ぐ単純な
4822UTF-8 であように強制したりそ行う場合があかもしれません
2841戦略とは、交換すデータエンコーディング常に明確にすということです
4823標準モジュル L<Encode> や、
2842エクステンションが取り扱うことができると知っているエンコディングを
4824低レベルの呼び出
2843選択てください。
4825L<C<utf8::upgrade($bytestring)>|utf8/Utility functions> と
2844エクステンションに渡す引数を選択したエンコーディングに変換し、
4826L<C<utf8::downgrade($utf8string[, FAIL_OK])>|utf8/Utility functions> が
2845エクステンションから返ってきた結果をそのエンコーディングから
4827このため使えます。
2846逆方向変換します。
2847変換を行ってくれるラッパ関数を書いておいて、
2848エクステンションが追いついた時に関数を変更できるようにしておきます。
48282849
48292850=begin original
48302851
4831Note that C<utf8::downgrade()> can fail if the string contains characters
2852To provide an example, let's say the popular Foo::Bar::escape_html
4832that don't fit into a byte.
2853function doesn't deal with Unicode data yet. The wrapper function
2854would convert the argument to raw UTF-8 and convert the result back to
2855Perl's internal representation like so:
48332856
48342857=end original
48352858
4836C<utf8::downgrade()> は、バイト収まらない文字を含む文字列の場合は
2859例として、まだ Unicode データを取り扱うようはできていない
4837失敗することがあること注意してください。
2860有名な Foo::Bar::escape_html て述べましょう
2861ラッパ関数は引数を生の UTF-8 に変換し、結果を Perl の内部表現に
2862逆変換します:
48382863
2864 sub my_escape_html ($) {
2865 my($what) = shift;
2866 return unless defined $what;
2867 Encode::decode_utf8(Foo::Bar::escape_html(Encode::encode_utf8($what)));
2868 }
2869
48392870=begin original
48402871
4841Calling either function on a string that already is in the desired state is a
2872Sometimes, when the extension does not convert data but just stores
4842no-op.
2873and retrieves them, you will be in a position to use the otherwise
2874dangerous Encode::_utf8_on() function. Let's say the popular
2875C<Foo::Bar> extension, written in C, provides a C<param> method that
2876lets you store and retrieve data according to these prototypes:
48432877
48442878=end original
48452879
4846既に望み通りの状態にってる文字列に対してこらの関数を呼び出しても
2880エクステンションがデータを変換しないども格納したり取り出したりするときに
4847起こりません。
2881ときとして危険な Encode::_utf8_on() 関数以外ののを
2882使うことがあるかもしれません。
2883C で書かれていて、データを以下のプロトタイプに従って格納したり
2884取り出したりする C<param> メソッドを持っている
2885有名な C<Foo::Bar> エクステンションについて述べてみましょう:
48482886
2887 $self->param($name, $value); # set a scalar
2888 $value = $self->param($name); # retrieve a scalar
2889
48492890=begin original
48502891
4851L</ASCII Rules versus Unicode Rules> gives all the ways that a string is
2892If it does not yet provide support for any encoding, one could write a
4852made to use Unicode rules.
2893derived class with such a C<param> method:
48532894
48542895=end original
48552896
4856L</ASCII Rules versus Unicode Rules> は、Unicode 規則を使う文字列が
2897エンコーディングもまだサポートしていないのなら、
4857作られる全て方法提供します。
2898以下ような C<param> メソッド持った派生クラスを
2899記述することができるでしょう:
48582900
4859=head2 Using Unicode in XS
2901 sub param {
2902 my($self,$name,$value) = @_;
2903 utf8::upgrade($name); # make sure it is UTF-8 encoded
2904 if (defined $value) {
2905 utf8::upgrade($value); # make sure it is UTF-8 encoded
2906 return $self->SUPER::param($name,$value);
2907 } else {
2908 my $ret = $self->SUPER::param($name);
2909 Encode::_utf8_on($ret); # we know, it is UTF-8 encoded
2910 return $ret;
2911 }
2912 }
48602913
4861(XS で Unicode を使う)
4862
48632914=begin original
48642915
4865See L<perlguts/"Unicode Support"> for an introduction to Unicode at
2916Some extensions provide filters on data entry/exit points, such as
4866the XS level, and L<perlapi/Unicode Support> for the API details.
2917DB_File::filter_store_key and family. Look out for such filters in
2918the documentation of your extensions, they can make the transition to
2919Unicode data much easier.
48672920
48682921=end original
48692922
4870XS レベル Unicode の紹介について L<perlguts/"Unicode Support">
2923一部エクステンションデータのエントリ/脱出ポイントでフィルター
4871API の詳細については L<perlapi/Unicode Support> を参照してください。
2924提供しています
2925たとえば DB_File::filter_store_keyとその仲間です。
2926あなた使うエクステンションのドキュメントにあるそのようなフィルターに
2927注意してください。
2928それらは Unicode データの変化をより容易にします。
48722929
4873=head2 Hacking Perl to work on earlier Unicode versions (for very serious hackers only)
2930=head2 Speed
48742931
4875(以前の Unicode のバージョンで動作させるように Perl をハックする (とても真剣なハッカー専用))
2932(速度)
48762933
48772934=begin original
48782935
4879Perl by default comes with the latest supported Unicode version built-in, but
2936Some functions are slower when working on UTF-8 encoded strings than
4880the goal is to allow you to change to use any earlier one. In Perls
2937on byte encoded strings. All functions that need to hop over
4881v5.20 and v5.22, however, the earliest usable version is Unicode 5.1.
2938characters such as length(), substr() or index(), or matching regular
4882Perl v5.18 and v5.24 are able to handle all earlier versions.
2939expressions can work B<much> faster when the underlying data are
2940byte-encoded.
48832941
48842942=end original
48852943
4886Perl はデフォルトでは最新の Unicode バージョが組み込まれていますが、
2944一部関数は UTF-8 でエコードさた文字列に対し適用したときにバイト
4887目標は、より古いもの変更できるようにするす。
2945エンコードされた文字列するときよりも遅くなります。
4888かし、Perl v5.20 と v5.22 は利用可能もっ早いバージョンは
2946文字に対て働く必要のある length()、substr()index()のよう関数のすべて
4889Unicode 5.1 です。
2947正規表現マッチングは、データが
4890Perl v5.18 v5.24は、それ以前の全てのバージョンが利用可能です。
2948バイトエンコードされているきには B<かなり> 早く動作きます。
48912949
48922950=begin original
48932951
4894Download the files in the desired version of Unicode from the Unicode web
2952In Perl 5.8.0 the slowness was often quite spectacular; in Perl 5.8.1
4895site L<https://www.unicode.org>). These should replace the existing files in
2953a caching scheme was introduced which will hopefully make the slowness
4896F<lib/unicore> in the Perl source tree. Follow the instructions in
2954somewhat less spectacular, at least for some operations. In general,
4897F<README.perl> in that directory to change some of their names, and then build
2955operations with UTF-8 encoded strings are still slower. As an example,
4898perl (see L<INSTALL>).
2956the Unicode properties (character classes) like C<\p{Nd}> are known to
2957be quite a bit slower (5-20 times) than their simpler counterparts
2958like C<\d> (then again, there 268 Unicode characters matching C<Nd>
2959compared with the 10 ASCII characters matching C<d>).
48992960
49002961=end original
49012962
4902Unicode の Web サイト L<https://www.unicode.org> から、 Unicode
2963Perl 5.8.0 ではこの遅さはしばしば立つもでした。
4903バージョンファイルダウンロードしま
2964Perl 5.8.1 では少なくとも一部操作については、遅さ改善ることを
4904これらのファイルは、Perl ソーツリの F<lib/unicore> の既存のファイルを
2965期待するキャッシングム(caching scheme)が導入されました。
4905置き換え必要があります。
2966一般的には、UTF-8 エンコードされた文字列に対す操作はだ遅いものです。
4906一部の名前を変るにはそのディレクトリにある F<README.perl> の指示に従って、
2967たとC<\p{Nd}> のような Unicode の特性(文字クラス)は対応する
4907perl をビルドしくださ (L<INSTALL> 参照)
2968C<\d> のような単純なものよりも目立っい(5 倍から10 倍)ことが
2969知られています(繰り返しますが、C<d> は 10 の ASCII 文字に対して
2970マッチするのに対して C<Nd> は 268 の Unicode 文字にマッチします)。
49082971
49092972=head2 Porting code from perl-5.6.X
49102973
49112974(perl 5.6.X からコードを移植する)
49122975
49132976=begin original
49142977
4915Perls starting in 5.8 have a different Unicode model from 5.6. In 5.6 the
2978Perl 5.8 has a different Unicode model from 5.6. In 5.6 the programmer
4916programmer was required to use the C<utf8> pragma to declare that a
2979was required to use the C<utf8> pragma to declare that a given scope
4917given scope expected to deal with Unicode data and had to make sure that
2980expected to deal with Unicode data and had to make sure that only
4918only Unicode data were reaching that scope. If you have code that is
2981Unicode data were reaching that scope. If you have code that is
49192982working with 5.6, you will need some of the following adjustments to
4920your code. The examples are written such that the code will continue to
2983your code. The examples are written such that the code will continue
4921work under 5.6, so you should be safe to try them out.
2984to work under 5.6, so you should be safe to try them out.
49222985
49232986=end original
49242987
4925Perl 5.8 からは 5.6 とは異なる Unicode モデルを持っています。
2988Perl 5.8 は 5.6 とは異なる Unicode モデルを持っています。
492629895.6 ではプログラマは、ある与えられたスコープが Unicode データを
49272990取り扱うのと Unicode データだけがそのスコープにあることを宣言するのに
49282991C<utf8> プラグマの使用を要求されていました。
492929925.6 で動いていたプログラムを持っているのなら、以下に挙げる微調整を施す
49302993必要があるでしょう。
49312994例は 5.6 でも動くように書かれているので、安心して試すことができます。
49322995
4933=over 3
2996=over 4
49342997
49352998=item *
49362999
49373000=begin original
49383001
49393002A filehandle that should read or write UTF-8
49403003
49413004=end original
49423005
49433006UTF-8 で読み書きすべきファイルハンドル
49443007
4945 if ($] > 5.008) {
3008 if ($] > 5.007) {
4946 binmode $fh, ":encoding(UTF-8)";
3009 binmode $fh, ":encoding(utf8)";
49473010 }
49483011
49493012=item *
49503013
49513014=begin original
49523015
49533016A scalar that is going to be passed to some extension
49543017
49553018=end original
49563019
49573020何らかのエクステンションに渡そうとするスカラ
49583021
49593022=begin original
49603023
4961Be it C<Compress::Zlib>, C<Apache::Request> or any extension that has no
3024Be it Compress::Zlib, Apache::Request or any extension that has no
49623025mention of Unicode in the manpage, you need to make sure that the
49633026UTF8 flag is stripped off. Note that at the time of this writing
4964(January 2012) the mentioned modules are not UTF-8-aware. Please
3027(October 2002) the mentioned modules are not UTF-8-aware. Please
49653028check the documentation to verify if this is still true.
49663029
49673030=end original
49683031
4969C<Compress::Zlib>, C<Apache::Request> などの、マニュアルページに Unicode に
3032Compress::ZlibApache::Request などの、マニュアルページに Unicode に
49703033関する記載がない何らかのエクステンションで、確実に UTF8 フラグが
49713034オフにする必要があります。
4972これを書いている時点(2012 年 1 月)では、上記のモジュールは
3035これを書いている時点(2002 年 10 月)では、上記のモジュールは
49733036UTF-8 対応でないことに注意してください。
49743037これがまだ真であるのなら、ドキュメントをチェックして確かめてください。
49753038
4976 if ($] > 5.008) {
3039 if ($] > 5.007) {
49773040 require Encode;
4978 $val = Encode::encode("UTF-8", $val); # make octets
3041 $val = Encode::encode_utf8($val); # make octets
49793042 }
49803043
49813044=item *
49823045
49833046=begin original
49843047
49853048A scalar we got back from an extension
49863049
49873050=end original
49883051
49893052エクステンションから返ってきたスカラ
49903053
49913054=begin original
49923055
49933056If you believe the scalar comes back as UTF-8, you will most likely
49943057want the UTF8 flag restored:
49953058
49963059=end original
49973060
49983061そのスカラが UTF-8 として返ってきたものだと信じているのなら、
49993062UTF-8 フラグをリストアしたいと考えるでしょう:
50003063
5001 if ($] > 5.008) {
3064 if ($] > 5.007) {
50023065 require Encode;
5003 $val = Encode::decode("UTF-8", $val);
3066 $val = Encode::decode_utf8($val);
50043067 }
50053068
50063069=item *
50073070
50083071=begin original
50093072
50103073Same thing, if you are really sure it is UTF-8
50113074
50123075=end original
50133076
50143077同様に、UTF-8 だと確信しているのなら
50153078
5016 if ($] > 5.008) {
3079 if ($] > 5.007) {
50173080 require Encode;
50183081 Encode::_utf8_on($val);
50193082 }
50203083
50213084=item *
50223085
50233086=begin original
50243087
5025A wrapper for L<DBI> C<fetchrow_array> and C<fetchrow_hashref>
3088A wrapper for fetchrow_array and fetchrow_hashref
50263089
50273090=end original
50283091
5029L<DBI> の C<fetchrow_array>C<fetchrow_hashref> へのラッパ
3092fetchrow_array と fetchrow_hashref へのラッパ
50303093
50313094=begin original
50323095
50333096When the database contains only UTF-8, a wrapper function or method is
5034a convenient way to replace all your C<fetchrow_array> and
3097a convenient way to replace all your fetchrow_array and
5035C<fetchrow_hashref> calls. A wrapper function will also make it easier to
3098fetchrow_hashref calls. A wrapper function will also make it easier to
50363099adapt to future enhancements in your database driver. Note that at the
5037time of this writing (January 2012), the DBI has no standardized way
3100time of this writing (October 2002), the DBI has no standardized way
5038to deal with UTF-8 data. Please check the L<DBI documentation|DBI> to verify if
3101to deal with UTF-8 data. Please check the documentation to verify if
50393102that is still true.
50403103
50413104=end original
50423105
50433106データベースが UTF-8 のみから構成されているとき、ラッパ関数や
5044ラッパメソッドはあなたの C<fetchrow_array>C<fetchrow_hashref>
3107ラッパメソッドはあなたの fetchrow_array や fetchrow_hashref の呼び出しを
5045呼び出しを置き換えるのに便利な方法でしょう。
3108置き換えるのに便利な方法でしょう。
50463109ラッパ関数はまた、あなたの使っているデータベースドライバが
50473110将来拡張されたときに適用しやすくするでしょう。
5048このドキュメントを書いている時点(2012 年 1 月)では、DBI は UTF-8 のデータを
3111このドキュメントを書いている時点(2002 年 10 月)では、DBI は UTF-8 のデータを
50493112扱う標準的な方法を持っていません。
5050これがまだ真なら L<DBI の文書|DBI> をチェックして確かめてください。
3113これがまだ真ならドキュメントをチェックして確かめてください。
50513114
50523115 sub fetchrow {
5053 # $what is one of fetchrow_{array,hashref}
3116 my($self, $sth, $what) = @_; # $what is one of fetchrow_{array,hashref}
5054 my($self, $sth, $what) = @_;
3117 if ($] < 5.007) {
5055 if ($] < 5.008) {
50563118 return $sth->$what;
50573119 } else {
50583120 require Encode;
50593121 if (wantarray) {
50603122 my @arr = $sth->$what;
50613123 for (@arr) {
50623124 defined && /[^\000-\177]/ && Encode::_utf8_on($_);
50633125 }
50643126 return @arr;
50653127 } else {
50663128 my $ret = $sth->$what;
50673129 if (ref $ret) {
50683130 for my $k (keys %$ret) {
5069 defined
3131 defined && /[^\000-\177]/ && Encode::_utf8_on($_) for $ret->{$k};
5070 && /[^\000-\177]/
5071 && Encode::_utf8_on($_) for $ret->{$k};
50723132 }
50733133 return $ret;
50743134 } else {
50753135 defined && /[^\000-\177]/ && Encode::_utf8_on($_) for $ret;
50763136 return $ret;
50773137 }
50783138 }
50793139 }
50803140 }
50813141
50823142=item *
50833143
50843144=begin original
50853145
50863146A large scalar that you know can only contain ASCII
50873147
50883148=end original
50893149
50903150ASCII だけが含まれていると分かっている大きなスカラ
50913151
50923152=begin original
50933153
50943154Scalars that contain only ASCII and are marked as UTF-8 are sometimes
50953155a drag to your program. If you recognize such a situation, just remove
50963156the UTF8 flag:
50973157
50983158=end original
50993159
51003160ASCII だけから構成されているのに UTF8 として印付けされているスカラが
51013161あなたのプログラムへ引きずりこまれることがあります。
51023162そのような場合を認識したならば、単に UTF-8 フラグを取り除いてください:
51033163
5104 utf8::downgrade($val) if $] > 5.008;
3164 utf8::downgrade($val) if $] > 5.007;
51053165
51063166=back
51073167
5108=head1 BUGS
5109
5110=begin original
5111
5112See also L</The "Unicode Bug"> above.
5113
5114=end original
5115
5116前述の L</The "Unicode Bug"> も参照してください。
5117
5118=head2 Interaction with Extensions
5119
5120(エクステンションとの相互作用)
5121
5122=begin original
5123
5124When Perl exchanges data with an extension, the extension should be
5125able to understand the UTF8 flag and act accordingly. If the
5126extension doesn't recognize that flag, it's likely that the extension
5127will return incorrectly-flagged data.
5128
5129=end original
5130
5131Perl がエクステンションとデータをやり取りするとき、そのエクステンションは
5132UTF8 フラグを理解し、また、それに従った振る舞いをすべきです。
5133エクステンションがこのフラグを認識しない場合、そのエクステンションは
5134正しくないフラグがついたデータを返す可能性があります。
5135
5136=begin original
5137
5138So if you're working with Unicode data, consult the documentation of
5139every module you're using if there are any issues with Unicode data
5140exchange. If the documentation does not talk about Unicode at all,
5141suspect the worst and probably look at the source to learn how the
5142module is implemented. Modules written completely in Perl shouldn't
5143cause problems. Modules that directly or indirectly access code written
5144in other programming languages are at risk.
5145
5146=end original
5147
5148そのため、もし Unicode データを扱おうというのであれば、 Unicode データの
5149交換に関して何らかの記述があるのなら使うモジュールすべてのドキュメントを
5150調べてください。
5151ドキュメントが Unicode に関して何の言及もしていないのなら、最悪のケースを
5152考慮し、そしてそのモジュールがどのように実装されているかを知るために
5153ソースを見ることになるかもしれません。
5154完全に Perl で書かれたモジュールは問題を引き起こしません。
5155他のプログラミング言語で書かれている直接または間接にアクセスするコードに
5156リスクがあるのです。
5157
5158=begin original
5159
5160For affected functions, the simple strategy to avoid data corruption is
5161to always make the encoding of the exchanged data explicit. Choose an
5162encoding that you know the extension can handle. Convert arguments passed
5163to the extensions to that encoding and convert results back from that
5164encoding. Write wrapper functions that do the conversions for you, so
5165you can later change the functions when the extension catches up.
5166
5167=end original
5168
5169影響を受けた関数のための、データの劣化(data corruption)を防ぐ単純な
5170戦略とは、交換するデータのエンコーディングを常に明確にするということです。
5171エクステンションが取り扱うことができると知っているエンコーディングを
5172選択してください。
5173エクステンションに渡す引数を選択したエンコーディングに変換し、
5174エクステンションから返ってきた結果をそのエンコーディングから
5175逆方向に変換します。
5176変換を行ってくれるラッパ関数を書いておいて、
5177エクステンションが追いついた時に関数を変更できるようにしておきます。
5178
5179=begin original
5180
5181To provide an example, let's say the popular C<Foo::Bar::escape_html>
5182function doesn't deal with Unicode data yet. The wrapper function
5183would convert the argument to raw UTF-8 and convert the result back to
5184Perl's internal representation like so:
5185
5186=end original
5187
5188例として、まだ Unicode データを取り扱うようにはできていない、
5189有名な C<Foo::Bar::escape_html> について述べましょう。
5190ラッパ関数は引数を生の UTF-8 に変換し、結果を Perl の内部表現に
5191逆変換します:
5192
5193 sub my_escape_html ($) {
5194 my($what) = shift;
5195 return unless defined $what;
5196 Encode::decode("UTF-8", Foo::Bar::escape_html(
5197 Encode::encode("UTF-8", $what)));
5198 }
5199
5200=begin original
5201
5202Sometimes, when the extension does not convert data but just stores
5203and retrieves it, you will be able to use the otherwise
5204dangerous L<C<Encode::_utf8_on()>|Encode/_utf8_on> function. Let's say
5205the popular C<Foo::Bar> extension, written in C, provides a C<param>
5206method that lets you store and retrieve data according to these prototypes:
5207
5208=end original
5209
5210エクステンションがデータを変換しないけれども格納したり取り出したりするときに、
5211ときとして危険な L<C<Encode::_utf8_on()>|Encode/_utf8_on> 関数以外のものを
5212使うことができるかもしれません。
5213C で書かれていて、データを以下のプロトタイプに従って格納したり
5214取り出したりする C<param> メソッドを持っている
5215有名な C<Foo::Bar> エクステンションについて述べてみましょう:
5216
5217 $self->param($name, $value); # set a scalar
5218 $value = $self->param($name); # retrieve a scalar
5219
5220=begin original
5221
5222If it does not yet provide support for any encoding, one could write a
5223derived class with such a C<param> method:
5224
5225=end original
5226
5227どのエンコーディングもまだサポートしていないのなら、
5228以下のような C<param> メソッドを持った派生クラスを
5229記述することができるでしょう:
5230
5231 sub param {
5232 my($self,$name,$value) = @_;
5233 utf8::upgrade($name); # make sure it is UTF-8 encoded
5234 if (defined $value) {
5235 utf8::upgrade($value); # make sure it is UTF-8 encoded
5236 return $self->SUPER::param($name,$value);
5237 } else {
5238 my $ret = $self->SUPER::param($name);
5239 Encode::_utf8_on($ret); # we know, it is UTF-8 encoded
5240 return $ret;
5241 }
5242 }
5243
5244=begin original
5245
5246Some extensions provide filters on data entry/exit points, such as
5247C<DB_File::filter_store_key> and family. Look out for such filters in
5248the documentation of your extensions; they can make the transition to
5249Unicode data much easier.
5250
5251=end original
5252
5253一部のエクステンションはデータのエントリ/脱出ポイントでフィルターを
5254提供しています; たとえば C<DB_File::filter_store_key> とその仲間です。
5255あなた使うエクステンションのドキュメントにあるそのようなフィルターに
5256注意してください; それらは Unicode データの変化をより容易にします。
5257
5258=head2 Speed
5259
5260(速度)
5261
5262=begin original
5263
5264Some functions are slower when working on UTF-8 encoded strings than
5265on byte encoded strings. All functions that need to hop over
5266characters such as C<length()>, C<substr()> or C<index()>, or matching
5267regular expressions can work B<much> faster when the underlying data are
5268byte-encoded.
5269
5270=end original
5271
5272一部の関数は UTF-8 でエンコードされた文字列に対して適用したときにバイト
5273エンコードされた文字列に対するときよりも遅くなります。
5274文字に対して働く必要のある C<length()>, C<substr()>, C<index()>
5275のような関数のすべてと正規表現マッチングは、データが
5276バイトエンコードされているときには B<かなり> 早く動作できます。
5277
5278=begin original
5279
5280In Perl 5.8.0 the slowness was often quite spectacular; in Perl 5.8.1
5281a caching scheme was introduced which improved the situation. In general,
5282operations with UTF-8 encoded strings are still slower. As an example,
5283the Unicode properties (character classes) like C<\p{Nd}> are known to
5284be quite a bit slower (5-20 times) than their simpler counterparts
5285like C<[0-9]> (then again, there are hundreds of Unicode characters matching
5286C<Nd> compared with the 10 ASCII characters matching C<[0-9]>).
5287
5288=end original
5289
5290Perl 5.8.0 ではこの遅さはしばしば目立つものでした; Perl 5.8.1 では
5291状況を改善するキャッシュ機構が導入されました。
5292一般的には、UTF-8 エンコードされた文字列に対する操作はまだ遅いものです。
5293たとえば、C<\p{Nd}> のような Unicode の特性(文字クラス)は対応する
5294C<[0-9]> のような単純なものよりも目立って遅い(5 倍から10 倍)ことが
5295知られています(繰り返しますが、C<[0-9]> は 10 の ASCII 文字に対して
5296マッチするのに対して C<Nd> は数百の Unicode 文字にマッチします)。
5297
52983168=head1 SEE ALSO
52993169
5300L<perlunitut>, L<perluniintro>, L<perluniprops>, L<Encode>, L<open>, L<utf8>, L<bytes>,
3170L<perlunitut>, L<perluniintro>, L<Encode>, L<open>, L<utf8>, L<bytes>,
5301L<perlretut>, L<perlvar/"${^UNICODE}">,
3171L<perlretut>, L<perlvar/"${^UNICODE}">
5302L<https://www.unicode.org/reports/tr44>).
53033172
5304=cut
5305
53063173=begin meta
53073174
53083175Translate: KIMURA Koichi (-5.8.5)
5309Update: SHIRAKATA Kentaro <argrath@ub32.org> (5.10.0-)
3176Update: Kentaro Shirakata <argrath@ub32.org> (5.10.0-)
5310Status: completed
53113177
53123178=end meta
3179
3180=cut