Listing 2 CSV2db::Mac
package CSV2db::Mac;
use strict;
use vars qw($VERSION @ISA @EXPORT_OK);
use Carp;
require Exporter;
$VERSION = substr q$Revision: 1.0 $, 10;
@ISA = qw(Exporter);
@EXPORT_OK = qw(macroman2iso);
# Translate a string from MacRoman to an approximation of ISO-8859-1.
# This is a pragmatic, not perfect, translation, since some characters
# in MacRoman simply don't exist in ISO-8859-1.
sub macroman2iso {
# modified from http://bumppo.net/lists/macperl/2000/02/msg00033.html
# (by Axel Rose <rose@sj.com>)
my %chars = (
128, "\304", # Ä
129, "\305", # Å
130, "\307", # Ç
131, "\311", # É
132, "\321", # Ñ
133, "\326", # Ö
134, "\334", # Ü
135, "\341", # á
136, "\340", # à
137, "\342", # â
138, "\344", # ä
139, "\343", # ã
140, "\345", # å
141, "\347", # ç
142, "\351", # é
143, "\350", # è
144, "\352", # ê
145, "\353", # ë
146, "\355", # í
147, "\354", # ì
148, "\356", # î
149, "\357", # ï
150, "\361", # ñ
151, "\363", # ó
152, "\362", # ò
153, "\364", # ô
154, "\366", # ö
155, "\365", # õ
156, "\372", # ú
157, "\371", # ù
158, "\373", # û
159, "\374", # ü
160, "*", # dagger
161, "\260", # °
162, "\242", # ¢
163, "\243", # £
164, "\247", # §
165, "\267", # bullet
166, "\266", # ¶
167, "\337", # ß
168, "\256", # ®
169, "\251", # ©
170, "(TM)", # trademark
171, "\264", # ´
172, "\250", # ¨
173, "<>", # not_eq
174, "\306", # Æ
175, "\330", # Ø
176, "infinity", # infinity
177, "\261", # ±
178, "<=", # less/eq
179, ">=", # great/eq
180, "\245", # ¥
181, "\265", # µ
182, "delta", # delta
183, "Sigma", # Sigma
184, "Pi", # Pi
185, "pi", # pi
186, "integral", # integral
187, "\252", # ª
188, "\272", # º
189, "Omega", # Omega
190, "\346", # æ
191, "\370", # ø
192, "\277", # ¿
193, "\241", # ¡
194, "\254", # ¬
195, "sqrt", # radical
196, "f", # florin
197, "~=", # apeq
198, "Delta", # Delta
199, "\253", # &laqot;
200, "\273", # &raqot;
201, "...", # ellipsis
202, "\240", #
203, "\300", # À
204, "\303", # Ã
205, "\325", # Õ
206, "OE", # OE
207, "oe", # oe
208, "-", # endash
209, "--", # emdash
210, '"', # open_qt
211, '"', # clos_qt
212, "'", # open_qt
213, "'", # clos_qt
214, "\367", # ÷
215, "*", # diamond
216, "\377", # ÿ
217, "Y", # Y.umlaut
218, "/", # fraction
219, "ECU", # circ.x euro
220, '<', # open_qt <
221, '>', # clos qt >
222, "fi", # fi.lig
223, "fl", # fl.lig
224, "++", # dbldagger
225, "\267", # ·
226, "'", # under_qt
227, '"', # under_dqt
228, "o/oo", # per_mil
229, "\302", # Â
230, "\312", # Ê
231, "\301", # Á
232, "\313", # Ë
233, "\310", # È
234, "\315", # Í
235, "\316", # Î
236, "\317", # Ï
237, "\314", # Ì
238, "\323", # Ó
239, "\324", # Ô
240, "*", # apple
241, "\322", # Ò
242, "\332", # Ú
243, "\333", # Û
244, "\331", # Ù
245, "i", # dotless_i
246, "^", # circumflex ^
247, "~", # tilde
248, "\257", # ¯
249, "\257", # breve
250, "\267", # dot
251, "\260", # ring_above
252, "\270", # cedilla
253, "\250", # hung_umlaut
254, "?", # ogonek
255, "?", # caron
);
my $out = join("",
map {exists $chars{ord $_} ? $chars{ord $_} : $_}
split(//, shift @_)
);
$out;
}
1;
|