NAME
Encode::First - Encode strings in a first possible encoding
SYNOPSIS
use Encode::First;
my($enc, $bytes) = encode_first("ascii,latin-1,iso-2022-jp,utf-8", $string);
DESCRIPTION
Encode::First provides a function to encode strings in the first possible encoding out of multiple encodings supplied as a list.
It'd be useful to figure out what's the minimal encoding to encode the email content, for instance, to be friendly with utf-8 incapable email clients.
FUNCTIONS
- encode_first
-
($enc, $bytes) = encode_first($encodings, $string);
returns $enc (encoding used) and $bytes, the encoded characters. $enc is the first encoding that $string is encodable into. $encodings can be either comma or colon separated scalar, or an array reference.
If none of $encodings can encode the $string safely, the function would throw an exception. To avoid that, you should always add utf-8 in $encodings.
$enc = encode_first($encodings, $string);
In a scalar context it just returns the name of encoding.
This function is exported by default.
BUGS
As of this writing, if you include iso-2022-jp in the list of encodings, this module will return iso-2022-jp as the best encoding for most of the Unicode strings, because of Encode::JP::JIS7 bug. The bug is reported and awaits for the patch to be applied.
AUTHOR
Tatsuhiko Miyagawa <miyagawa@bulknews.net>
Juerd Waalboer
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
SEE ALSO
Encode::InCharset, http://use.perl.org/~miyagawa/journal/32781