Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] clarify that CHECK coderefs return octets #18

Merged
merged 1 commit into from
Feb 2, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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