Skip to content

Instantly share code, notes, and snippets.

@tremby
Created May 4, 2020 15:37
Show Gist options
  • Save tremby/43d6fbd5ebd364c07139537a05216def to your computer and use it in GitHub Desktop.
Save tremby/43d6fbd5ebd364c07139537a05216def to your computer and use it in GitHub Desktop.
Convert text from RISC OS encoding to UTF-8
#!/usr/bin/env python3
"""
Convert stdin (text in the standard RISC OS character set) to UTF-8
See https://en.wikipedia.org/wiki/RISC_OS_character_set#Code_page_layout_(standard)
"""
import sys
chars = [
#0 1 2 3 4 5 6 7 8 9 a b c d e f
'€','Ŵ','ŵ','◰','🯀','Ŷ','ŷ','⅞','⇦','⇨','⇩','⇧','…','™','‰','•', # 0x8_
'‘','’','‹','›','“','”','„','–','—','−','Œ','œ','†','‡','fi','fl', # 0x9_
]
while True:
b = sys.stdin.buffer.read(1)
if len(b) == 0:
break
val = ord(b)
if val >= 0x80 and val <= 0x9f:
diff = val - 0x80
sys.stdout.buffer.write(chars[diff].encode('utf-8'))
else:
sys.stdout.buffer.write(b.decode('latin1').encode('utf-8'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment