Skip to content

Commit

Permalink
Merge pull request #18 from moritz/fallback-docs
Browse files Browse the repository at this point in the history
[doc] clarify that CHECK coderefs return octets
  • Loading branch information
dankogai committed Feb 2, 2014
2 parents e0d51da + 83145ae commit ccaa6bf
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions Encode.pm
Original file line number Diff line number Diff line change
Expand Up @@ -801,13 +801,24 @@ If you're not interested in this, then bitwise-OR it with the bitmask.
=head2 coderef for CHECK
As of C<Encode> 2.12, C<CHECK> can also be a code reference which takes the
ordinal value of the unmapped character as an argument and returns a string
that represents the fallback character. For instance:
ordinal value of the unmapped character as an argument and returns
octets that represent the fallback character. For instance:
$ascii = encode("ascii", $utf8, sub{ sprintf "<U+%04X>", shift });
Acts like C<FB_PERLQQ> but U+I<XXXX> is used instead of C<\x{I<XXXX>}>.
Even the fallback for C<decode> must return octets, which are
then decoded with the character encoding that C<decode> accepts. So for
example if you wish to decode octests as UTF-8, and use ISO-8859-15 as
a fallback for bytes that are not valid UTF-8, you could write
$str = decode 'UTF-8', $octets, sub {
my $tmp = chr shift;
from_to $tmp, 'ISO-8859-15', 'UTF-8';
return $tmp;
};
=head1 Defining Encodings
To define a new encoding, use:
Expand Down

0 comments on commit ccaa6bf

Please sign in to comment.