Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
172 lines (162 sloc) 3.15 KB
`JorgeChB 2012-06-03 Mac to UTF8
`$1 TEXT El texto que hay que convertir de MacRoman a UTF8
`$0 TEXT el texto convertido
`OJO Esto es muy lento: siempre que se pueda es mejor/más rápido usar DocumentConvert
`OJO Si $1 es muy larga, puede que quede cortada:
`un texto en UTF8 pueder ser más largo que el mismo texto en MacRoman
`Si se anda cerca de los 32000 caracteres, habrá problemas casi seguro
ARRAY LONGINT($c;256)
C_LONGINT($i;$code;$uno;$dos;$tres)
C_TEXT($0;$1;$str;$char)
`Ver:http://en.wikipedia.org/wiki/Macroman#Codepage_layout
$c{128}:=0x00C4
$c{129}:=0x00C5
$c{130}:=0x00C7
$c{131}:=0x00C9
$c{132}:=0x00D1
$c{133}:=0x00D6
$c{134}:=0x00DC
$c{135}:=0x00E1
$c{136}:=0x00E0
$c{137}:=0x00E2
$c{138}:=0x00E4
$c{139}:=0x00E3
$c{140}:=0x00E5
$c{141}:=0x00E7
$c{142}:=0x00E9
$c{143}:=0x00E8
$c{144}:=0x00EA
$c{145}:=0x00EB
$c{146}:=0x00ED
$c{147}:=0x00EC
$c{148}:=0x00EE
$c{149}:=0x00EF
$c{150}:=0x00F1
$c{151}:=0x00F3
$c{152}:=0x00F2
$c{153}:=0x00F4
$c{154}:=0x00F6
$c{155}:=0x00F5
$c{156}:=0x00FA
$c{157}:=0x00F9
$c{158}:=0x00FB
$c{159}:=0x00FC
$c{160}:=0x2020
$c{161}:=0x00B0
$c{162}:=0x00A2
$c{163}:=0x00A3
$c{164}:=0x00A7
$c{165}:=0x2022
$c{166}:=0x00B6
$c{167}:=0x00DF
$c{168}:=0x00AE
$c{169}:=0x00A9
$c{170}:=0x2122
$c{171}:=0x00B4
$c{172}:=0x00A8
$c{173}:=0x2260
$c{174}:=0x00C6
$c{175}:=0x00D8
$c{176}:=0x221E
$c{177}:=0x00B1
$c{178}:=0x2264
$c{179}:=0x2265
$c{180}:=0x00A5
$c{181}:=0x00B5
$c{182}:=0x2202
$c{183}:=0x2211
$c{184}:=0x220F
$c{185}:=0x03C0
$c{186}:=0x222B
$c{187}:=0x00AA
$c{188}:=0x00BA
$c{189}:=0x03A9
$c{190}:=0x00E6
$c{191}:=0x00F8
$c{192}:=0x00BF
$c{193}:=0x00A1
$c{194}:=0x00AC
$c{195}:=0x221A
$c{196}:=0x0192
$c{197}:=0x2248
$c{198}:=0x2206
$c{199}:=0x00AB
$c{200}:=0x00BB
$c{201}:=0x2026
$c{202}:=0x00A0
$c{203}:=0x00C0
$c{204}:=0x00C3
$c{205}:=0x00D5
$c{206}:=0x0152
$c{207}:=0x0153
$c{208}:=0x2013
$c{209}:=0x2014
$c{210}:=0x201C
$c{211}:=0x201D
$c{212}:=0x2018
$c{213}:=0x2019
$c{214}:=0x00F7
$c{215}:=0x25CA
$c{216}:=0x00FF
$c{217}:=0x0178
$c{218}:=0x2044
$c{219}:=0x20AC
$c{220}:=0x2039
$c{221}:=0x203A
$c{222}:=0xFB01
$c{223}:=0xFB02
$c{224}:=0x2021
$c{225}:=0x00B7
$c{226}:=0x201A
$c{227}:=0x201E
$c{228}:=0x2030
$c{229}:=0x00C2
$c{230}:=0x00CA
$c{231}:=0x00C1
$c{232}:=0x00CB
$c{233}:=0x00C8
$c{234}:=0x00CD
$c{235}:=0x00CE
$c{236}:=0x00CF
$c{237}:=0x00CC
$c{238}:=0x00D3
$c{239}:=0x00D4
$c{240}:=0xF8FF
$c{241}:=0x00D2
$c{242}:=0x00DA
$c{243}:=0x00DB
$c{244}:=0x00D9
$c{245}:=0x0131
$c{246}:=0x02C6
$c{247}:=0x02DC
$c{248}:=0x00AF
$c{249}:=0x02D8
$c{250}:=0x02D9
$c{251}:=0x02DA
$c{252}:=0x00B8
$c{253}:=0x02DD
$c{254}:=0x02DB
$c{255}:=0x02C7
`Ver:http://en.wikipedia.org/wiki/UTF8#Description
$str:=""
For ($i;1;Length($1))
`$char:=$1{$i}
$char:=Substring($1;$i;1)
$code:=Ascii($char)
If ($code<128)
$str:=$str+$char
Else
$code:=$c{$code}
If (($code>=0) & ($code<2048))
$uno:=(($code & 0x07C0) >> 6) | 0x00C0
$dos:=($code & 0x003F) | 0x0080
$str:=$str+Char($uno)+Char($dos)
Else
$uno:=(($code & 0xF000) >> 12) | 0x00E0
$dos:=(($code & 0x0FC0) >> 6) | 0x0080
$tres:=($code & 0x003F) | 0x0080
$str:=$str+Char($uno)+Char($dos)+Char($tres)
End if
End if
End for
$0:=$str