Created
July 14, 2012 20:32
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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