Skip to content

Instantly share code, notes, and snippets.

@jrus
Created July 14, 2012 20:32
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrus/3113240 to your computer and use it in GitHub Desktop.
Save jrus/3113240 to your computer and use it in GitHub Desktop.
decode a Mac OS Roman string to a regular Javascript string (code written in coffeescript)
decode_macroman = do ->
high_chars_unicode = '''
ÄÅÇÉÑÖÜáàâäãåçéèêëíìîïñóòôöõúùûü
†°¢£§•¶ß®©™´¨≠ÆØ∞±≤≥¥µ∂∑∏π∫ªºΩæø
¿¡¬√ƒ≈∆«»… ÀÃÕŒœ–—“”‘’÷◊ÿŸ⁄€‹›fifl
‡·‚„‰ÂÊÁËÈÍÎÏÌÓÔÒÚÛÙıˆ˜¯˘˙˚¸˝˛ˇ
'''.replace /\n/g, ''
(mac_roman_bytestring) ->
char_array = for idx in [0...mac_roman_bytestring.length]
byte = mac_roman_bytestring.charCodeAt idx
if byte < 0x80 then String.fromCharCode byte
else high_chars_unicode.charAt byte - 0x80
char_array.join ''
# the cute version, with unicode in the code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment