⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encode.3

📁 视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.
💻 3
📖 第 1 页 / 共 2 页
字号:
.Ve.PPWhen \*(L"::\*(R" is not in the name, \*(L"Encode::\*(R" is assumed..PP.Vb 1\&  @ebcdic = Encode\->encodings("EBCDIC");.Ve.PPTo find out in detail which encodings are supported by this package,see Encode::Supported..Sh "Defining Aliases".IX Subsection "Defining Aliases"To add a new alias to a given encoding, use:.PP.Vb 3\&  use Encode;\&  use Encode::Alias;\&  define_alias(newName => ENCODING);.Ve.PPAfter that, newName can be used as an alias for \s-1ENCODING\s0.\&\s-1ENCODING\s0 may be either the name of an encoding or an\&\fIencoding object\fR.PPBut before you do so, make sure the alias is nonexistent with\&\f(CW\*(C`resolve_alias()\*(C'\fR, which returns the canonical name thereof.i.e..PP.Vb 3\&  Encode::resolve_alias("latin1") eq "iso\-8859\-1" # true\&  Encode::resolve_alias("iso\-8859\-12")   # false; nonexistent\&  Encode::resolve_alias($name) eq $name  # true if $name is canonical.Ve.PP\&\fIresolve_alias()\fR does not need \f(CW\*(C`use Encode::Alias\*(C'\fR; it can beexported via \f(CW\*(C`use Encode qw(resolve_alias)\*(C'\fR..PPSee Encode::Alias for details..Sh "Finding \s-1IANA\s0 Character Set Registry names".IX Subsection "Finding IANA Character Set Registry names"The canonical name of a given encoding does not necessarily agree with\&\s-1IANA\s0 \s-1IANA\s0 Character Set Registry, commonly seen as \f(CW\*(C`Content\-Type:text/plain; charset=\f(CIwhatever\f(CW\*(C'\fR.  For most cases canonical nameswork but sometimes it does not (notably 'utf\-8\-strict')..PPTherefore as of Encode version 2.21, a new method \f(CW\*(C`mime_name()\*(C'\fR is added..PP.Vb 4\&  use Encode;\&  my $enc = find_encoding(\*(AqUTF\-8\*(Aq);\&  warn $enc\->name;      # utf\-8\-strict\&  warn $enc\->mime_name; # UTF\-8.Ve.PPSee also:  Encode::Encoding.SH "Encoding via PerlIO".IX Header "Encoding via PerlIO"If your perl supports \fIPerlIO\fR (which is the default), you can use aPerlIO layer to decode and encode directly via a filehandle.  Thefollowing two examples are totally identical in their functionality..PP.Vb 4\&  # via PerlIO\&  open my $in,  "<:encoding(shiftjis)", $infile  or die;\&  open my $out, ">:encoding(euc\-jp)",   $outfile or die;\&  while(<$in>){ print $out $_; }\&\&  # via from_to\&  open my $in,  "<", $infile  or die;\&  open my $out, ">", $outfile or die;\&  while(<$in>){\&    from_to($_, "shiftjis", "euc\-jp", 1);\&    print $out $_;\&  }.Ve.PPUnfortunately, it may be that encodings are PerlIO-savvy.  You can checkif your encoding is supported by PerlIO by calling the \f(CW\*(C`perlio_ok\*(C'\fRmethod..PP.Vb 2\&  Encode::perlio_ok("hz");             # False\&  find_encoding("euc\-cn")\->perlio_ok;  # True where PerlIO is available\&\&  use Encode qw(perlio_ok);            # exported upon request\&  perlio_ok("euc\-jp").Ve.PPFortunately, all encodings that come with Encode core are PerlIO-savvyexcept for hz and ISO\-2022\-kr.  For gory details, seeEncode::Encoding and Encode::PerlIO..SH "Handling Malformed Data".IX Header "Handling Malformed Data"The optional \fI\s-1CHECK\s0\fR argument tells Encode what to do when itencounters malformed data.  Without \s-1CHECK\s0, Encode::FB_DEFAULT ( == 0 )is assumed..PPAs of version 2.12 Encode supports coderef values for \s-1CHECK\s0.  See below..IP "\fB\s-1NOTE:\s0\fR Not all encoding support this feature" 2.IX Item "NOTE: Not all encoding support this feature"Some encodings ignore \fI\s-1CHECK\s0\fR argument.  For example,Encode::Unicode ignores \fI\s-1CHECK\s0\fR and it always croaks on error..PPNow here is the list of \fI\s-1CHECK\s0\fR values available.IP "\fI\s-1CHECK\s0\fR = Encode::FB_DEFAULT ( == 0)" 2.IX Item "CHECK = Encode::FB_DEFAULT ( == 0)"If \fI\s-1CHECK\s0\fR is 0, (en|de)code will put a \fIsubstitution character\fR inplace of a malformed character.  When you encode, <subchar>will be used.  When you decode the code point \f(CW0xFFFD\fR is used.  Ifthe data is supposed to be \s-1UTF\-8\s0, an optional lexical warning(category utf8) is given..IP "\fI\s-1CHECK\s0\fR = Encode::FB_CROAK ( == 1)" 2.IX Item "CHECK = Encode::FB_CROAK ( == 1)"If \fI\s-1CHECK\s0\fR is 1, methods will die on error immediately with an errormessage.  Therefore, when \fI\s-1CHECK\s0\fR is set to 1,  you should trap theerror with eval{} unless you really want to let it die..IP "\fI\s-1CHECK\s0\fR = Encode::FB_QUIET" 2.IX Item "CHECK = Encode::FB_QUIET"If \fI\s-1CHECK\s0\fR is set to Encode::FB_QUIET, (en|de)code will immediatelyreturn the portion of the data that has been processed so far when anerror occurs. The data argument will be overwritten with everythingafter that point (that is, the unprocessed part of data).  This ishandy when you have to call decode repeatedly in the case where yoursource data may contain partial multi-byte character sequences,(i.e. you are reading with a fixed-width buffer). Here is a samplecode that does exactly this:.Sp.Vb 5\&  my $buffer = \*(Aq\*(Aq; my $string = \*(Aq\*(Aq;\&  while(read $fh, $buffer, 256, length($buffer)){\&    $string .= decode($encoding, $buffer, Encode::FB_QUIET);\&    # $buffer now contains the unprocessed partial character\&  }.Ve.IP "\fI\s-1CHECK\s0\fR = Encode::FB_WARN" 2.IX Item "CHECK = Encode::FB_WARN"This is the same as above, except that it warns on error.  Handy whenyou are debugging the mode above..IP "perlqq mode (\fI\s-1CHECK\s0\fR = Encode::FB_PERLQQ)" 2.IX Item "perlqq mode (CHECK = Encode::FB_PERLQQ)".PD 0.IP "\s-1HTML\s0 charref mode (\fI\s-1CHECK\s0\fR = Encode::FB_HTMLCREF)" 2.IX Item "HTML charref mode (CHECK = Encode::FB_HTMLCREF)".IP "\s-1XML\s0 charref mode (\fI\s-1CHECK\s0\fR = Encode::FB_XMLCREF)" 2.IX Item "XML charref mode (CHECK = Encode::FB_XMLCREF)".PDFor encodings that are implemented by Encode::XS, \s-1CHECK\s0 ==Encode::FB_PERLQQ turns (en|de)code into \f(CW\*(C`perlqq\*(C'\fR fallback mode..SpWhen you decode, \f(CW\*(C`\ex\f(CIHH\f(CW\*(C'\fR will be inserted for a malformed character,where \fI\s-1HH\s0\fR is the hex representation of the octet  that could not bedecoded to utf8.  And when you encode, \f(CW\*(C`\ex{\f(CIHHHH\f(CW}\*(C'\fR will be inserted,where \fI\s-1HHHH\s0\fR is the Unicode \s-1ID\s0 of the character that cannot be foundin the character repertoire of the encoding..Sp\&\s-1HTML/XML\s0 character reference modes are about the same, in place of\&\f(CW\*(C`\ex{\f(CIHHHH\f(CW}\*(C'\fR, \s-1HTML\s0 uses \f(CW\*(C`&#\f(CINNN\f(CW;\*(C'\fR where \fI\s-1NNN\s0\fR is a decimal number and\&\s-1XML\s0 uses \f(CW\*(C`&#x\f(CIHHHH\f(CW;\*(C'\fR where \fI\s-1HHHH\s0\fR is the hexadecimal number..SpIn Encode 2.10 or later, \f(CW\*(C`LEAVE_SRC\*(C'\fR is also implied..IP "The bitmask" 2.IX Item "The bitmask"These modes are actually set via a bitmask.  Here is how the \s-1FB_XX\s0constants are laid out.  You can import the \s-1FB_XX\s0 constants via\&\f(CW\*(C`use Encode qw(:fallbacks)\*(C'\fR; you can import the generic bitmaskconstants via \f(CW\*(C`use Encode qw(:fallback_all)\*(C'\fR..Sp.Vb 8\&                     FB_DEFAULT FB_CROAK FB_QUIET FB_WARN  FB_PERLQQ\& DIE_ON_ERR    0x0001             X\& WARN_ON_ERR   0x0002                               X\& RETURN_ON_ERR 0x0004                      X        X\& LEAVE_SRC     0x0008                                        X\& PERLQQ        0x0100                                        X\& HTMLCREF      0x0200\& XMLCREF       0x0400.Ve.IP "Encode::LEAVE_SRC" 2.IX Item "Encode::LEAVE_SRC"If the \f(CW\*(C`Encode::LEAVE_SRC\*(C'\fR bit is not set, but \fI\s-1CHECK\s0\fR is, then the secondargument to \f(CW\*(C`encode()\*(C'\fR or \f(CW\*(C`decode()\*(C'\fR may be assigned to by the functions. Ifyou're not interested in this, then bitwise-or the bitmask with it..PPAs of Encode 2.12 \s-1CHECK\s0 can also be a code reference which takes theord value of unmapped caharacter as an argument and returns a stringthat represents the fallback character.  For instance,.PP.Vb 1\&  $ascii = encode("ascii", $utf8, sub{ sprintf "<U+%04X>", shift });.Ve.PPActs like \s-1FB_PERLQQ\s0 but <U+\fI\s-1XXXX\s0\fR> is used instead of\&\ex{\fI\s-1XXXX\s0\fR}..SH "Defining Encodings".IX Header "Defining Encodings"To define a new encoding, use:.PP.Vb 2\&    use Encode qw(define_encoding);\&    define_encoding($object, \*(AqcanonicalName\*(Aq [, alias...]);.Ve.PP\&\fIcanonicalName\fR will be associated with \fI\f(CI$object\fI\fR.  The objectshould provide the interface described in Encode::Encoding.If more than two arguments are provided then additionalarguments are taken as aliases for \fI\f(CI$object\fI\fR..PPSee Encode::Encoding for more details..SH "The UTF8 flag".IX Header "The UTF8 flag"Before the introduction of Unicode support in perl, The \f(CW\*(C`eq\*(C'\fR operatorjust compared the strings represented by two scalars. Beginning withperl 5.8, \f(CW\*(C`eq\*(C'\fR compares two strings with simultaneous consideration of\&\fIthe \s-1UTF8\s0 flag\fR. To explain why we made it so, I will quote page 402 of\&\f(CW\*(C`Programming Perl, 3rd ed.\*(C'\fR.IP "Goal #1:" 2.IX Item "Goal #1:"Old byte-oriented programs should not spontaneously break on the oldbyte-oriented data they used to work on..IP "Goal #2:" 2.IX Item "Goal #2:"Old byte-oriented programs should magically start working on the newcharacter-oriented data when appropriate..IP "Goal #3:" 2.IX Item "Goal #3:"Programs should run just as fast in the new character-oriented modeas in the old byte-oriented mode..IP "Goal #4:" 2.IX Item "Goal #4:"Perl should remain one language, rather than forking into abyte-oriented Perl and a character-oriented Perl..PPBack when \f(CW\*(C`Programming Perl, 3rd ed.\*(C'\fR was written, not even Perl 5.6.0was born and many features documented in the book remainedunimplemented for a long time.  Perl 5.8 corrected this and the introductionof the \s-1UTF8\s0 flag is one of them.  You can think of this perl notion as of abyte-oriented mode (\s-1UTF8\s0 flag off) and a character-oriented mode (\s-1UTF8\s0flag on)..PPHere is how Encode takes care of the \s-1UTF8\s0 flag..IP "\(bu" 2When you encode, the resulting \s-1UTF8\s0 flag is always off..IP "\(bu" 2When you decode, the resulting \s-1UTF8\s0 flag is on unless you canunambiguously represent data.  Here is the definition ofdis-ambiguity..SpAfter \f(CW\*(C`$utf8 = decode(\*(Aqfoo\*(Aq, $octet);\*(C'\fR,.Sp.Vb 6\&  When $octet is...   The UTF8 flag in $utf8 is\&  \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\&  In ASCII only (or EBCDIC only)            OFF\&  In ISO\-8859\-1                              ON\&  In any other Encoding                      ON\&  \-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-\-.Ve.SpAs you see, there is one exception, In \s-1ASCII\s0.  That way you can assumeGoal #1.  And with Encode Goal #2 is assumed but you still have to becareful in such cases mentioned in \fB\s-1CAVEAT\s0\fR paragraphs..SpThis \s-1UTF8\s0 flag is not visible in perl scripts, exactly for the samereason you cannot (or you \fIdon't have to\fR) see if a scalar contains astring, integer, or floating point number.   But you can still peekand poke these if you will.  See the section below..Sh "Messing with Perl's Internals".IX Subsection "Messing with Perl's Internals"The following \s-1API\s0 uses parts of Perl's internals in the currentimplementation.  As such, they are efficient but may change..IP "is_utf8(\s-1STRING\s0 [, \s-1CHECK\s0])" 2.IX Item "is_utf8(STRING [, CHECK])"[\s-1INTERNAL\s0] Tests whether the \s-1UTF8\s0 flag is turned on in the \s-1STRING\s0.If \s-1CHECK\s0 is true, also checks the data in \s-1STRING\s0 for being well-formed\&\s-1UTF\-8\s0.  Returns true if successful, false otherwise..SpAs of perl 5.8.1, utf8 also has \fIutf8::is_utf8()\fR..IP "_utf8_on(\s-1STRING\s0)" 2.IX Item "_utf8_on(STRING)"[\s-1INTERNAL\s0] Turns on the \s-1UTF8\s0 flag in \s-1STRING\s0.  The data in \s-1STRING\s0 is\&\fBnot\fR checked for being well-formed \s-1UTF\-8\s0.  Do not use unless you\&\fBknow\fR that the \s-1STRING\s0 is well-formed \s-1UTF\-8\s0.  Returns the previousstate of the \s-1UTF8\s0 flag (so please don't treat the return value asindicating success or failure), or \f(CW\*(C`undef\*(C'\fR if \s-1STRING\s0 is not a string..IP "_utf8_off(\s-1STRING\s0)" 2.IX Item "_utf8_off(STRING)"[\s-1INTERNAL\s0] Turns off the \s-1UTF8\s0 flag in \s-1STRING\s0.  Do not use frivolously.Returns the previous state of the \s-1UTF8\s0 flag (so please don't treat thereturn value as indicating success or failure), or \f(CW\*(C`undef\*(C'\fR if \s-1STRING\s0 isnot a string..SH "UTF\-8 vs. utf8 vs. UTF8".IX Header "UTF-8 vs. utf8 vs. UTF8".Vb 3\&  ....We now view strings not as sequences of bytes, but as sequences\&  of numbers in the range 0 .. 2**32\-1 (or in the case of 64\-bit\&  computers, 0 .. 2**64\-1) \-\- Programming Perl, 3rd ed..Ve.PPThat has been the perl's notion of \s-1UTF\-8\s0 but official \s-1UTF\-8\s0 is morestrict; Its ranges is much narrower (0 .. 10FFFF), some sequences arenot allowed (i.e. Those used in the surrogate pair, 0xFFFE, et al)..PPNow that is overruled by Larry Wall himself..PP.Vb 5\&  From: Larry Wall <larry@wall.org>\&  Date: December 04, 2004 11:51:58 JST\&  To: perl\-unicode@perl.org\&  Subject: Re: Make Encode.pm support the real UTF\-8\&  Message\-Id: <20041204025158.GA28754@wall.org>\&  \&  On Fri, Dec 03, 2004 at 10:12:12PM +0000, Tim Bunce wrote:\&  : I\*(Aqve no problem with \*(Aqutf8\*(Aq being perl\*(Aqs unrestricted uft8 encoding,\&  : but "UTF\-8" is the name of the standard and should give the\&  : corresponding behaviour.\&  \&  For what it\*(Aqs worth, that\*(Aqs how I\*(Aqve always kept them straight in my\&  head.\&  \&  Also for what it\*(Aqs worth, Perl 6 will mostly default to strict but\&  make it easy to switch back to lax.\&  \&  Larry.Ve.PPDo you copy?  As of Perl 5.8.7, \fB\s-1UTF\-8\s0\fR means strict, official \s-1UTF\-8\s0while \fButf8\fR means liberal, lax, version thereof.  And Encode version2.10 or later thus groks the difference between \f(CW\*(C`UTF\-8\*(C'\fR and C\*(L"utf8\*(R"..PP.Vb 2\&  encode("utf8",  "\ex{FFFF_FFFF}", 1); # okay\&  encode("UTF\-8", "\ex{FFFF_FFFF}", 1); # croaks.Ve.PP\&\f(CW\*(C`UTF\-8\*(C'\fR in Encode is actually a canonical name for \f(CW\*(C`utf\-8\-strict\*(C'\fR.Yes, the hyphen between \*(L"\s-1UTF\s0\*(R" and \*(L"8\*(R" is important.  Without it Encodegoes \*(L"liberal\*(R".PP.Vb 4\&  find_encoding("UTF\-8")\->name # is \*(Aqutf\-8\-strict\*(Aq\&  find_encoding("utf\-8")\->name # ditto. names are case insensitive\&  find_encoding("utf_8")\->name  # ditto. "_" are treated as "\-"\&  find_encoding("UTF8")\->name  # is \*(Aqutf8\*(Aq..Ve.PPThe \s-1UTF8\s0 flag is internally called \s-1UTF8\s0, without a hyphen. It indicateswhether a string is internally encoded as utf8, also without a hypen..SH "SEE ALSO".IX Header "SEE ALSO"Encode::Encoding,Encode::Supported,Encode::PerlIO,encoding,perlebcdic,\&\*(L"open\*(R" in perlfunc,perlunicode, perluniintro, perlunifaq, perlunitututf8,the Perl Unicode Mailing List <perl\-unicode@perl.org>.SH "MAINTAINER".IX Header "MAINTAINER"This project was originated by Nick Ing-Simmons and later maintainedby Dan Kogai <dankogai@dan.co.jp>.  See \s-1AUTHORS\s0 for a fulllist of people involved.  For any questions, use<perl\-unicode@perl.org> so we can all share..PPWhile Dan Kogai retains the copyright as a maintainer, the creditshould go to all those involoved.  See \s-1AUTHORS\s0 for those submittedcodes..SH "COPYRIGHT".IX Header "COPYRIGHT"Copyright 2002\-2006 Dan Kogai <dankogai@dan.co.jp>.PPThis library is free software; you can redistribute it and/or modifyit under the same terms as Perl itself..SH "POD ERRORS".IX Header "POD ERRORS"Hey! \fBThe above document had some coding errors, which are explained below:\fR.IP "Around line 737:" 4.IX Item "Around line 737:"Unknown directive: =Head2

⌨️ 快捷键说明

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