Babble::Encode - Encoding wrapper for Babble


Babble documentation Contained in the Babble distribution.

Index


Code Index:

NAME

Top

Babble::Encode - Encoding wrapper for Babble

SYNOPSIS

Top

 use Babble::Encode;
 ...
 $encoded = to_utf8 ($string);
 ...

DESCRIPTION

Top

This module provides a wrapper around either Encode or Text::Iconv, whichever is installed on ones computer, to convert an arbitrary string to UTF-8.

METHODS

Top

to_utf8

Converts its only argument to UTF-8.

AUTHOR

Top

Gergely Nagy, algernon@bonehunter.rulez.org

Bugs should be reported at http://bugs.bonehunter.rulez.org/babble.

SEE ALSO

Top

Encode, Text::Iconv


Babble documentation Contained in the Babble distribution.
## Babble/Encode.pm
## Copyright (C) 2004 Gergely Nagy <algernon@bonehunter.rulez.org>
##
## This file is part of Babble.
##
## Babble is free software; you can redistribute it and/or modify it
## under the terms of the GNU General Public License as published by
## the Free Software Foundation; version 2 dated June, 1991.
##
## Babble is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
## for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

package Babble::Encode;

use strict;
require Exporter;
use base qw/Exporter/;
our @EXPORT = qw(to_utf8);

sub to_utf8 ($) {
	my ($text) = @_;
	eval q{
				use Encode;
		};
	if ($@) {
		use Text::Iconv;
		my $c = Text::Iconv ('iso-8859-2', 'utf-8');
		return $c->convert ($text) || $text;
	} else {
		return Encode::encode ('utf-8', $text);
	}
}

1;

# arch-tag: 6393c26f-c780-4533-900b-6133ed0dec1f