NAME
PApp::Recode - convert bytes from one charset to another
SYNOPSIS
use PApp::Recode;
# not auto-imported into .papp-files
$converter = to_utf8 PApp::Recode "iso-8859-1";
$converter->("string");
DESCRIPTION
This module creates conversion functions that enable you to convert text data from one character set (and/or encoding) to another.
Functions
- charset_valid $charset
-
Returns a boolean indicating wether the named charset is valid on this system (where "valid" is defined as "can be converted from/to UTF-8 using this module").
The PApp::Recode Class
This class can be used to convert textual data between various encodings.
- $converter = new PApp::Recode "destination-charset", "source-charset" [, \&fallback]
-
Returns a new conversion function (a code reference) that converts its argument from the source character set into the destination character set each time it is called (it does remember state, though. A call without arguments resets the state).
Perl's internal UTF-8-flag is ignored on input and not set on output.
Example: create a converter that converts UTF-8 into ascii, html-escaping any non-ascii characters:
new PApp::Recode "ascii", "utf-8", sub { sprintf "&#x%x;", $_[0] };
- $converter = to_utf8 PApp::Recode "source-character-set" [, \&fallback]
-
Similar to a call to
new
with the first argument equal to "utf-8". The returned conversion function will, however, forcefully set perl's UTF-8 flag on the returned scalar. - $converter = utf8_to PApp::Recode "destination-character-set" [, \&fallback]
-
Similar to a call to
new
with the second argument equal to "utf-8". The returned conversion function will, however, upgrade its argument to UTF-8.
The PApp::Recode::Pconv Class
This is the class that actually implements character conversion. It should not be used directly.
- new PApp::Recode::Pconv tocode, fromcode [, fallback]
-
Create a new encoding convert that encodes from
fromcode
totocode
, optionally invoking thefallback
code reference for every character that is not representable in the target encoding. - PApp::Recode::Pconv::open tocode, fromcode [, fallback]
-
Convenience function that calls
new
and returns the converter. - $pconv->convert($string [, reset])
-
Convert the given string. If
reset
is true, the internal multibyte state is reset before conversion. - $pconv->reset
-
Reset the multibyte state.
- $pconv->convert_fresh ($string)
-
Same as
convert
withreset
set to true.
SEE ALSO
PApp.
AUTHOR
Marc Lehmann <schmorp@schmorp.de>
http://home.schmorp.de/