Unicode-String-2.09 > Unicode::String
Unicode-String-2.09

名前

Unicode::String - String of Unicode characters (UTF-16BE)

Unicode::String - Unicode 文字の文字列 (UTF16-BE)

概要

 use Unicode::String qw(utf8 latin1 utf16be);

 $u = utf8("string");
 $u = latin1("string");
 $u = utf16be("\0s\0t\0r\0i\0n\0g");

 print $u->utf32be;   # 4 byte characters
 print $u->utf16le;   # 2 byte characters + surrogates
 print $u->utf8;      # 1-4 byte characters

説明

A Unicode::String object represents a sequence of Unicode characters. Methods are provided to convert between various external formats (encodings) and Unicode::String objects, and methods are provided for common string manipulations.

Unicode::String オブジェクトは Unicode 文字の並びを表現します。 様々な外部フォーマット(エンコーディング) と Unicode::String オブジェクトの変換を行うメソッドが提供され、また 基本的な文字列操作のためのメソッドも提供されます。

The functions utf32be(), utf32le(), utf16be(), utf16le(), utf8(), utf7(), latin1(), uhex(), uchr() can be imported from the Unicode::String module and will work as constructors initializing strings of the corresponding encoding.

utf32be(), utf32le(), utf16be(), utf16le(), utf8(), utf7(), latin1(), uhex(), uchr() といった関数は、Unicode::String モジュールから インポートでき、対応するエンコーディングの文字列を初期化するための コンストラクタとしても動作します。

The Unicode::String objects overload various operators, which means that they in most cases can be treated like plain strings.

Unicode::String オブジェクトは様々な演算子をオーバーロードしているので、 ほとんどの場合で通常の文字列と同じように扱うことができます。

Internally a Unicode::String object is represented by a string of 2 byte numbers in network byte order (big-endian). This representation is not visible by the API provided, but it might be useful to know in order to predict the efficiency of the provided methods.

内部的には Unicode::String オブジェクトはネットワークバイト順序 (ビッグエンディアン)で並んだ 2 バイトの文字列です。 この表現は提供されている API からは見えませんが、提供されているメソッドの 効率を予測するためには知っておくと有用でしょう。

メソッド

クラスメソッド

The following class methods are available:

以下のクラスメソッドが利用可能です:

Unicode::String->stringify_as
Unicode::String->stringify_as( $enc )

This method is used to specify which encoding will be used when Unicode::String objects are implicitly converted to and from plain strings.

このメソッドは、 通常の文字列と Unicode::String との間で暗黙的な変換が 行われるときに使用されるエンコーディングを指定するものです。

If an argument is provided it sets the current encoding. The argument should have one of the following: "ucs4", "utf32", "utf32be", "utf32le", "ucs2", "utf16", "utf16be", "utf16le", "utf8", "utf7", "latin1" or "hex". The default is "utf8".

If an argument is provided it sets the current encoding. The argument should have one of the following: "ucs4", "utf32", "utf32be", "utf32le", "ucs2", "utf16", "utf16be", "utf16le", "utf8", "utf7", "latin1" or "hex". The default is "utf8". (TBT)

The stringify_as() method returns a reference to the current encoding function.

The stringify_as() method returns a reference to the current encoding function. (TBT)

$us = Unicode::String->new
$us = Unicode::String->new( $initial_value )

This is the object constructor. Without argument, it creates an empty Unicode::String object. If an $initial_value argument is given, it is decoded according to the specified stringify_as() encoding, UTF-8 by default.

これはオブジェクトコンストラクタです。 引数が与えられなかった場合、このメソッドは空の Unicode::String オブジェクトを返します。 $initial_value 引数が与えられた場合には、 stringify_as() エンコーディングの指定に従ってデコードが行われます; デフォルトは UTF-8 です。

In general it is recommended to import and use one of the encoding specific constructor functions instead of invoking this method.

In general it is recommended to import and use one of the encoding specific constructor functions instead of invoking this method. (TBT)

Encoding methods

These methods get or set the value of the Unicode::String object by passing strings in the corresponding encoding. If a new value is passed as argument it will set the value of the Unicode::String, and the previous value is returned. If no argument is passed then the current value is returned.

These methods get or set the value of the Unicode::String object by passing strings in the corresponding encoding. If a new value is passed as argument it will set the value of the Unicode::String, and the previous value is returned. If no argument is passed then the current value is returned. (TBT)

To illustrate the encodings we show how the 2 character sample string of "µm" (micro meter) is encoded for each one.

To illustrate the encodings we show how the 2 character sample string of "µm" (micro meter) is encoded for each one. (TBT)

$us->utf32be
$us->utf32be( $newval )

The string passed should be in the UTF-32 encoding with bytes in big endian order. The sample "µm" is "\0\0\0\xB5\0\0\0m" in this encoding.

The string passed should be in the UTF-32 encoding with bytes in big endian order. The sample "µm" is "\0\0\0\xB5\0\0\0m" in this encoding. (TBT)

Alternative names for this method are utf32() and ucs4().

Alternative names for this method are utf32() and ucs4(). (TBT)

$us->utf32le
$us->utf32le( $newval )

The string passed should be in the UTF-32 encoding with bytes in little endian order. The sample "µm" is is "\xB5\0\0\0m\0\0\0" in this encoding.

The string passed should be in the UTF-32 encoding with bytes in little endian order. The sample "µm" is is "\xB5\0\0\0m\0\0\0" in this encoding. (TBT)

$us->utf16be
$us->utf16be( $newval )

The string passed should be in the UTF-16 encoding with bytes in big endian order. The sample "µm" is "\0\xB5\0m" in this encoding.

The string passed should be in the UTF-16 encoding with bytes in big endian order. The sample "µm" is "\0\xB5\0m" in this encoding. (TBT)

Alternative names for this method are utf16() and ucs2().

Alternative names for this method are utf16() and ucs2(). (TBT)

If the string passed to utf16be() starts with the Unicode byte order mark in little endian order, the result is as if utf16le() was called instead.

If the string passed to utf16be() starts with the Unicode byte order mark in little endian order, the result is as if utf16le() was called instead. (TBT)

$us->utf16le
$us->utf16le( $newval )

The string passed should be in the UTF-16 encoding with bytes in little endian order. The sample "µm" is is "\xB5\0m\0" in this encoding. This is the encoding used by the Microsoft Windows API.

The string passed should be in the UTF-16 encoding with bytes in little endian order. The sample "µm" is is "\xB5\0m\0" in this encoding. This is the encoding used by the Microsoft Windows API. (TBT)

If the string passed to utf16le() starts with the Unicode byte order mark in big endian order, the result is as if utf16le() was called instead.

If the string passed to utf16le() starts with the Unicode byte order mark in big endian order, the result is as if utf16le() was called instead. (TBT)

$us->utf8
$us->utf8( $newval )

The string passed should be in the UTF-8 encoding. The sample "µm" is "\xC2\xB5m" in this encoding.

渡される文字列は UTF-7 エンコーディングです。 例として、"µm" はこのエンコーディングでは "\xC2\xB5m" となります。

$us->utf7
$us->utf7( $newval )

The string passed should be in the UTF-7 encoding. The sample "µm" is "+ALU-m" in this encoding.

渡される文字列は UTF-7 エンコーディングです。 例として、"µm" はこのエンコーディングでは "+ALU-m" となります。

The UTF-7 encoding only use plain US-ASCII characters for the encoding. This makes it safe for transport through 8-bit stripping protocols. Characters outside the US-ASCII range are base64-encoded and '+' is used as an escape character. The UTF-7 encoding is described in RFC 1642.

UTF-7エンコーディングは、プレーンな US-ASCII 文字だけを用いる エンコーディングです。 これは 8 ビット目を落としてしまうような転送に対しても安全なものにします。 US-ASCII の範囲にない文字は base64 エンコードされ、 エスケープ文字として '+' が使われます。 UTF-7 エンコーディングは RFC 1642 に記述されています。

If the (global) variable $Unicode::String::UTF7_OPTIONAL_DIRECT_CHARS is TRUE, then a wider range of characters are encoded as themselves. It is even TRUE by default. The characters affected by this are:

(グローバル)変数 $Unicode::String::UTF7_OPTIONAL_DIRECT_CHARS が 真である場合には、文字エンコードの対象となる範囲が広がります。 デフォルトでは真にセットされています。 影響を受ける文字は以下の通りです:

   ! " # $ % & * ; < = > @ [ ] ^ _ ` { | }
$us->latin1
$us->latin1( $newval )

The string passed should be in the ISO-8859-1 encoding. The sample "µm" is "\xB5m" in this encoding.

渡される文字列は ISO-8859-1 エンコーディングです。 例として、"µm" はこのエンコーディングでは "\xB5m" となります。

Characters outside the "\x00" .. "\xFF" range are simply removed from the return value of the latin1() method. If you want more control over the mapping from Unicode to ISO-8859-1, use the Unicode::Map8 class. This is also the way to deal with other 8-bit character sets.

latin1() メソッドの返り値から、"\x00" から "\xFF" の範囲にない文字は 単に削除されます。 Unicode から ISO-8859-1 のマッピングをもっと自分で制御したいというのであれば、 Unicode::Map8 クラスを使用してください。 このクラスは他の 8 ビット文字クラスを扱うときも同様です。

$us->hex
$us->hex( $newval )

The string passed should be plain ASCII where each Unicode character is represented by the "U+XXXX" string and separated by a single space character. The "U+" prefix is optional when setting the value. The sample "µm" is "U+00b5 U+006d" in this encoding.

渡される文字列は、それぞれの文字が "U+XXXX" で表現され、 一つの空白で区切られる、プレーンな ASCII です。 値を設定する場合は "U+" 接頭辞は省略可能です。 例として、"µm" はこのエンコーディングでは "U+00b5 U+006d" となります。

String Operations

The following methods are available:

以下のメソッドが使用可能です:

$us->as_string

Converts a Unicode::String to a plain string according to the setting of stringify_as(). The default stringify_as() encoding is "utf8".

Unicode::String を stringify_as() の設定にしたがってプレーンな文字列に 変換します。 デフォルトの stringify_as() エンコーディングは "utf8" です。

$us->as_num

Converts a Unicode::String to a number. Currently only the digits in the range 0x30 .. 0x39 are recognized. The plan is to eventually support all Unicode digit characters.

Unicode::String を数値に変換します。 現時点では、0x30 から 0x39 までのみが数字として認識されます。 計画では、全ての Unicode の数字文字をサポートする予定です。

$us->as_bool

Converts a Unicode::String to a boolean value. Only the empty string is FALSE. A string consisting of only the character U+0030 is considered TRUE, even if Perl consider "0" to be FALSE.

Unicode::String を真偽値に変換します。 空文字列のみが FALSE となります。 Perl が "0" を FALSE とみなすにも関わらず、U+0030 という文字のみの 文字列は TRUE と判定されます。

$us->repeat( $count )

Returns a new Unicode::String where the content of $us is repeated $count times. This operation is also overloaded as:

$us の内容を $count 回繰り返した新しい Unicode::String を返します。 この操作はまた、以下のようにオーバーロードされています:

  $us x $count
$us->concat( $other_string )

Concatenates the string $us and the string $other_string. If $other_string is not an Unicode::String object, then it is first passed to the Unicode::String->new constructor function. This operation is also overloaded as:

文字列 $us と文字列 $other_string を連結します。 $other_string が Unicode::String オブジェクトでない場合には、 まず最初に Unicode::string->new コンストラクタに渡されます。 この操作はまた、以下のようにオーバーロードされています:

  $us . $other_string
$us->append( $other_string )

Appends the string $other_string to the value of $us. If $other_string is not an Unicode::String object, then it is first passed to the Unicode::String->new constructor function. This operation is also overloaded as:

文字列 $other_string を $us に追加します。 $other_string が Unicode::String オブジェクトでなかった場合には、 追加に先立って Unicode::String->new コンストラクタに $other_string が渡されます。 この操作はまた、以下のようにオーバーロードされています:

  $us .= $other_string
$us->copy

Returns a copy of the current Unicode::String object. This operation is overloaded as the assignment operator.

Unicode::String のカレントオブジェクトのコピーを返します。 この操作は代入演算子としてオーバーロードされています。

$us->length

Returns the length of the Unicode::String. Surrogate pairs are still counted as 2.

Unicode::String の長さを返します。 サロゲートペアの長さは 2 として数えられます。

$us->byteswap

This method will swap the bytes in the internal representation of the Unicode::String object.

This method will swap the bytes in the internal representation of the Unicode::String object. (TBT)

Unicode reserve the character U+FEFF character as a byte order mark. This works because the swapped character, U+FFFE, is reserved to not be valid. For strings that have the byte order mark as the first character, we can guaranty to get the byte order right with the following code:

Unicode reserve the character U+FEFF character as a byte order mark. This works because the swapped character, U+FFFE, is reserved to not be valid. For strings that have the byte order mark as the first character, we can guaranty to get the byte order right with the following code: (TBT)

   $ustr->byteswap if $ustr->ord == 0xFFFE;
$us->unpack

Returns a list of integers each representing an UCS-2 character code.

それぞれが UCS-2 文字コードを表している整数値のリストを返します。

$us->pack( @uchr )

Sets the value of $us as a sequence of UCS-2 characters with the characters codes given as parameter.

$us の値として、引数で渡された UCS-2 文字の並びをセットします。

$us->ord

Returns the character code of the first character in $us. The ord() method deals with surrogate pairs, which gives us a result-range of 0x0 .. 0x10FFFF. If the $us string is empty, undef is returned.

$us の最初の文字の文字コードを返します。 ord()メソッドはサロゲートペアにも対応していて、0x0 から 0x10FFFF の範囲で 結果を返します。 $us が空文字列であった場合には undef が返されます。

$us->chr( $code )

Sets the value of $us to be a string containing the character assigned code $code. The argument $code must be an integer in the range 0x0 .. 0x10FFFF. If the code is greater than 0xFFFF then a surrogate pair created.

$us に $code で指示された文字から構成される文字列をセットします。 引数 $code は 0x0 から 0x10FFFF の間の整数でなければなりません。 コードが 0xFFFF よりも大きい場合にはサロゲートペアが生成されます。

$us->name

In scalar context returns the official Unicode name of the first character in $us. In array context returns the name of all characters in $us. Also see Unicode::CharName.

スカラコンテキストでは $us の最初の文字の公式 Unicode 名を返します。 配列コンテキストでは $us の全ての文字の名前を返します。 Unicode::CharName も参照してください。

$us->substr( $offset )
$us->substr( $offset, $length )
$us->substr( $offset, $length, $subst )

Returns a sub-string of $us. Works similar to the builtin substr() function.

$us の部分文字列を返します。 組み込みの substr() 関数と同様です。

$us->index( $other )
$us->index( $other, $pos )

Locates the position of $other within $us, possibly starting the search at position $pos.

$us 中での $other の位置です; $pos を起点として検索することも可能です。

$us->chop

Chops off the last character of $us and returns it (as a Unicode::String object).

$us の最後の文字を切り取って、それを (Unicode::String オブジェクトとして)返します。

関数

The following functions are provided. None of these are exported by default.

以下の関数が提供されます。 デフォルトでエクスポートされる関数はありません。

byteswap2( $str, ... )

This function will swap 2 and 2 bytes in the strings passed as arguments. If this function is called in void context, then it will modify its arguments in-place. Otherwise, the swapped strings are returned.

This function will swap 2 and 2 bytes in the strings passed as arguments. If this function is called in void context, then it will modify its arguments in-place. Otherwise, the swapped strings are returned. (TBT)

byteswap4( $str, ... )

The byteswap4 function works similar to byteswap2, but will reverse the order of 4 and 4 bytes.

The byteswap4 function works similar to byteswap2, but will reverse the order of 4 and 4 bytes. (TBT)

latin1( $str )
utf7( $str )
utf8( $str )
utf16le( $str )
utf16be( $str )
utf32le( $str )
utf32be( $str )

Constructor functions for the various Unicode encodings. These return new Unicode::String objects. The provided argument should be encoded correspondingly.

Constructor functions for the various Unicode encodings. These return new Unicode::String objects. The provided argument should be encoded correspondingly. (TBT)

uhex( $str )

Constructs a new Unicode::String object from a string of hex values. See hex() method above for description of the format.

Constructs a new Unicode::String object from a string of hex values. See hex() method above for description of the format. (TBT)

uchar( $num )

Constructs a new one character Unicode::String object from a Unicode character code. This works similar to perl's builtin chr() function.

Constructs a new one character Unicode::String object from a Unicode character code. This works similar to perl's builtin chr() function. (TBT)

SEE ALSO

Unicode::CharName, Unicode::Map8

http://www.unicode.org/

perlunicode

コピーライト

Copyright 1997-2000,2005 Gisle Aas.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.