| 1 | ##---------------------------------------------------------------------------## | ||
| 2 | ## File: | ||
| 3 | ## $Id: UTF8.pm,v 1.6 2003/03/05 22:17:15 ehood Exp $ | ||
| 4 | ## Author: | ||
| 5 | ## Earl Hood earl@earlhood.com | ||
| 6 | ## Description: | ||
| 7 | ## POD after __END__. | ||
| 8 | ##---------------------------------------------------------------------------## | ||
| 9 | ## Copyright (C) 2002 Earl Hood, earl@earlhood.com | ||
| 10 | ## | ||
| 11 | ## This program is free software; you can redistribute it and/or modify | ||
| 12 | ## it under the terms of the GNU General Public License as published by | ||
| 13 | ## the Free Software Foundation; either version 2 of the License, or | ||
| 14 | ## (at your option) any later version. | ||
| 15 | ## | ||
| 16 | ## This program is distributed in the hope that it will be useful, | ||
| 17 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | ## GNU General Public License for more details. | ||
| 20 | ## | ||
| 21 | ## You should have received a copy of the GNU General Public License | ||
| 22 | ## along with this program; if not, write to the Free Software | ||
| 23 | ## Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | ||
| 24 | ## 02111-1307, USA | ||
| 25 | ##---------------------------------------------------------------------------## | ||
| 26 | |||
| 27 | package MHonArc::UTF8; | ||
| 28 | |||
| 29 | use strict; | ||
| 30 | use MHonArc::CharMaps; | ||
| 31 | |||
| 32 | our $VERSION = '2.6.24'; | ||
| 33 | |||
| 34 | BEGIN { | ||
| 35 | eval { require MHonArc::UTF8::Encode; }; | ||
| 36 | if (!$@) { | ||
| 37 | # Encode module available | ||
| 38 | *entify = \&_entify; | ||
| 39 | *clip = \&MHonArc::UTF8::Encode::clip; | ||
| 40 | *to_utf8 = \&MHonArc::UTF8::Encode::to_utf8; | ||
| 41 | *str2sgml = \&MHonArc::UTF8::Encode::str2sgml; | ||
| 42 | } else { | ||
| 43 | eval { require MHonArc::UTF8::MapUTF8; }; | ||
| 44 | if (!$@) { | ||
| 45 | # Unicode::MapUTF8 module available | ||
| 46 | *entify = \&_entify; | ||
| 47 | *clip = \&MHonArc::UTF8::MapUTF8::clip; | ||
| 48 | *to_utf8 = \&MHonArc::UTF8::MapUTF8::to_utf8; | ||
| 49 | *str2sgml = \&MHonArc::UTF8::MapUTF8::str2sgml; | ||
| 50 | } else { | ||
| 51 | # Fallback to homegrown implementation | ||
| 52 | require MHonArc::UTF8::MhaEncode; | ||
| 53 | *entify = \&_entify; | ||
| 54 | *clip = \&MHonArc::UTF8::MhaEncode::clip; | ||
| 55 | *to_utf8 = \&MHonArc::UTF8::MhaEncode::to_utf8; | ||
| 56 | *str2sgml = \&MHonArc::UTF8::MhaEncode::str2sgml; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | |||
| 61 | ##---------------------------------------------------------------------------## | ||
| 62 | |||
| 63 | sub _entify { | ||
| 64 | my $text = shift; | ||
| 65 | my $text_r = ref($text) ? $text : \$text; | ||
| 66 | $$text_r =~ s/([$HTMLSpecials])/$HTMLSpecials{$1}/go; | ||
| 67 | $$text_r; | ||
| 68 | } | ||
| 69 | |||
| 70 | ##---------------------------------------------------------------------------## | ||
| 71 | 1; | ||
| 72 | __END__ |