123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336 |
- package door
- import "strings"
- // I used iconv in door++, but it was horrible. It doesn't translate
- // control codes to Unicode.
- // This converts CP437 to Unicode for rendering in Unicode terminals
- // like the linux telnet client.
- // This does everything but: \x07, \x08, \x0a and \x0d.
- // 0x07, 0x08, 0x09, 0x0a, 0x0c, 0x0d, 0x1b (ANSI spec)
- func CP437_to_Unicode(cp437 string) string {
- // var result string
- var result strings.Builder
- // make initial guess on capacity
- result.Grow(len(cp437))
- for _, char := range []byte(cp437) {
- // for _, char := range []rune(cp437) {
- switch int(char) {
- case 0x01:
- result.WriteRune('\u263A')
- case 0x02:
- result.WriteRune('\u263B')
- case 0x03:
- result.WriteRune('\u2665')
- case 0x04:
- result.WriteRune('\u2666')
- case 0x05:
- result.WriteRune('\u2663')
- case 0x06:
- result.WriteRune('\u2660')
- case 0x09:
- result.WriteRune('\u25CB')
- case 0x0b:
- result.WriteRune('\u2642')
- case 0x0c:
- result.WriteRune('\u2640')
- case 0x0e:
- result.WriteRune('\u266B')
- case 0x0f:
- result.WriteRune('\u263C')
- case 0x10:
- result.WriteRune('\u25BA')
- case 0x11:
- result.WriteRune('\u25C4')
- case 0x12:
- result.WriteRune('\u2195')
- case 0x13:
- result.WriteRune('\u203C')
- case 0x14:
- result.Write([]byte{0xc2, 0xb6})
- case 0x15:
- result.Write([]byte{0xc2, 0xa7})
- case 0x16:
- result.WriteRune('\u25AC')
- case 0x17:
- result.WriteRune('\u21A8')
- case 0x18:
- result.WriteRune('\u2191')
- case 0x19:
- result.WriteRune('\u2193')
- case 0x1a:
- result.WriteRune('\u2192')
- case 0x1c:
- result.WriteRune('\u221F')
- case 0x1d:
- result.WriteRune('\u2194')
- case 0x1e:
- result.WriteRune('\u25B2')
- case 0x1f:
- result.WriteRune('\u25BC')
- case 0x7f:
- result.WriteRune('\u2302')
- case 0x80:
- result.Write([]byte{0xc3, 0x87})
- case 0x81:
- result.Write([]byte{0xc3, 0xbc})
- case 0x82:
- result.Write([]byte{0xc3, 0xa9})
- case 0x83:
- result.Write([]byte{0xc3, 0xa2})
- case 0x84:
- result.Write([]byte{0xc3, 0xa4})
- case 0x85:
- result.Write([]byte{0xc3, 0xa0})
- case 0x86:
- result.Write([]byte{0xc3, 0xa5})
- case 0x87:
- result.Write([]byte{0xc3, 0xa7})
- case 0x88:
- result.Write([]byte{0xc3, 0xaa})
- case 0x89:
- result.Write([]byte{0xc3, 0xab})
- case 0x8a:
- result.Write([]byte{0xc3, 0xa8})
- case 0x8b:
- result.Write([]byte{0xc3, 0xaf})
- case 0x8c:
- result.Write([]byte{0xc3, 0xae})
- case 0x8d:
- result.Write([]byte{0xc3, 0xac})
- case 0x8e:
- result.Write([]byte{0xc3, 0x84})
- case 0x8f:
- result.Write([]byte{0xc3, 0x85})
- case 0x90:
- result.Write([]byte{0xc3, 0x89})
- case 0x91:
- result.Write([]byte{0xc3, 0xa6})
- case 0x92:
- result.Write([]byte{0xc3, 0x86})
- case 0x93:
- result.Write([]byte{0xc3, 0xb4})
- case 0x94:
- result.Write([]byte{0xc3, 0xb6})
- case 0x95:
- result.Write([]byte{0xc3, 0xb2})
- case 0x96:
- result.Write([]byte{0xc3, 0xbb})
- case 0x97:
- result.Write([]byte{0xc3, 0xb9})
- case 0x98:
- result.Write([]byte{0xc3, 0xbf})
- case 0x99:
- result.Write([]byte{0xc3, 0x96})
- case 0x9a:
- result.Write([]byte{0xc3, 0x9c})
- case 0x9b:
- result.Write([]byte{0xc2, 0xa2})
- case 0x9c:
- result.Write([]byte{0xc2, 0xa3})
- case 0x9d:
- result.Write([]byte{0xc2, 0xa5})
- case 0x9e:
- result.WriteRune('\u20A7')
- case 0x9f:
- result.WriteRune('\u0192')
- case 0xa0:
- result.Write([]byte{0xc3, 0xa1})
- case 0xa1:
- result.Write([]byte{0xc3, 0xad})
- case 0xa2:
- result.Write([]byte{0xc3, 0xb3})
- case 0xa3:
- result.Write([]byte{0xc3, 0xba})
- case 0xa4:
- result.Write([]byte{0xc3, 0xb1})
- case 0xa5:
- result.Write([]byte{0xc3, 0x91})
- case 0xa6:
- result.Write([]byte{0xc2, 0xaa})
- case 0xa7:
- result.Write([]byte{0xc2, 0xba})
- case 0xa8:
- result.Write([]byte{0xc2, 0xbf})
- case 0xa9:
- result.WriteRune('\u2310')
- case 0xaa:
- result.Write([]byte{0xc2, 0xac})
- case 0xab:
- result.Write([]byte{0xc2, 0xbd})
- case 0xac:
- result.Write([]byte{0xc2, 0xbc})
- case 0xad:
- result.Write([]byte{0xc2, 0xa1})
- case 0xae:
- result.Write([]byte{0xc2, 0xab})
- case 0xaf:
- result.Write([]byte{0xc2, 0xbb})
- case 0xb0:
- result.WriteRune('\u2591')
- case 0xb1:
- result.WriteRune('\u2592')
- case 0xb2:
- result.WriteRune('\u2593')
- case 0xb3:
- result.WriteRune('\u2502')
- case 0xb4:
- result.WriteRune('\u2524')
- case 0xb5:
- result.WriteRune('\u2561')
- case 0xb6:
- result.WriteRune('\u2562')
- case 0xb7:
- result.WriteRune('\u2556')
- case 0xb8:
- result.WriteRune('\u2555')
- case 0xb9:
- result.WriteRune('\u2563')
- case 0xba:
- result.WriteRune('\u2551')
- case 0xbb:
- result.WriteRune('\u2557')
- case 0xbc:
- result.WriteRune('\u255D')
- case 0xbd:
- result.WriteRune('\u255C')
- case 0xbe:
- result.WriteRune('\u255B')
- case 0xbf:
- result.WriteRune('\u2510')
- case 0xc0:
- result.WriteRune('\u2514')
- case 0xc1:
- result.WriteRune('\u2534')
- case 0xc2:
- result.WriteRune('\u252C')
- case 0xc3:
- result.WriteRune('\u251C')
- case 0xc4:
- result.WriteRune('\u2500')
- case 0xc5:
- result.WriteRune('\u253C')
- case 0xc6:
- result.WriteRune('\u255E')
- case 0xc7:
- result.WriteRune('\u255F')
- case 0xc8:
- result.WriteRune('\u255A')
- case 0xc9:
- result.WriteRune('\u2554')
- case 0xca:
- result.WriteRune('\u2569')
- case 0xcb:
- result.WriteRune('\u2566')
- case 0xcc:
- result.WriteRune('\u2560')
- case 0xcd:
- result.WriteRune('\u2550')
- case 0xce:
- result.WriteRune('\u256C')
- case 0xcf:
- result.WriteRune('\u2567')
- case 0xd0:
- result.WriteRune('\u2568')
- case 0xd1:
- result.WriteRune('\u2564')
- case 0xd2:
- result.WriteRune('\u2565')
- case 0xd3:
- result.WriteRune('\u2559')
- case 0xd4:
- result.WriteRune('\u2558')
- case 0xd5:
- result.WriteRune('\u2552')
- case 0xd6:
- result.WriteRune('\u2553')
- case 0xd7:
- result.WriteRune('\u256B')
- case 0xd8:
- result.WriteRune('\u256A')
- case 0xd9:
- result.WriteRune('\u2518')
- case 0xda:
- result.WriteRune('\u250C')
- case 0xdb:
- result.WriteRune('\u2588')
- case 0xdc:
- result.WriteRune('\u2584')
- case 0xdd:
- result.WriteRune('\u258C')
- case 0xde:
- result.WriteRune('\u2590')
- case 0xdf:
- result.WriteRune('\u2580')
- case 0xe0:
- result.WriteRune('\u03B1')
- case 0xe1:
- result.Write([]byte{0xc3, 0x9f})
- case 0xe2:
- result.WriteRune('\u0393')
- case 0xe3:
- result.WriteRune('\u03C0')
- case 0xe4:
- result.WriteRune('\u03A3')
- case 0xe5:
- result.WriteRune('\u03C3')
- case 0xe6:
- result.Write([]byte{0xc2, 0xb5})
- case 0xe7:
- result.WriteRune('\u03C4')
- case 0xe8:
- result.WriteRune('\u03A6')
- case 0xe9:
- result.WriteRune('\u0398')
- case 0xea:
- result.WriteRune('\u03A9')
- case 0xeb:
- result.WriteRune('\u03B4')
- case 0xec:
- result.WriteRune('\u221E')
- case 0xed:
- result.WriteRune('\u03C6')
- case 0xee:
- result.WriteRune('\u03B5')
- case 0xef:
- result.WriteRune('\u2229')
- case 0xf0:
- result.WriteRune('\u2261')
- case 0xf1:
- result.Write([]byte{0xc2, 0xb1})
- case 0xf2:
- result.WriteRune('\u2265')
- case 0xf3:
- result.WriteRune('\u2264')
- case 0xf4:
- result.WriteRune('\u2320')
- case 0xf5:
- result.WriteRune('\u2321')
- case 0xf6:
- result.Write([]byte{0xc3, 0xb7})
- case 0xf7:
- result.WriteRune('\u2248')
- case 0xf8:
- result.Write([]byte{0xc2, 0xb0})
- case 0xf9:
- result.WriteRune('\u2219')
- case 0xfa:
- result.Write([]byte{0xc2, 0xb7})
- case 0xfb:
- result.WriteRune('\u221A')
- case 0xfc:
- result.WriteRune('\u207F')
- case 0xfd:
- result.Write([]byte{0xc2, 0xb2})
- case 0xfe:
- result.WriteRune('\u25A0')
- case 0xff:
- result.Write([]byte{0xc2, 0xa0})
- default:
- result.WriteByte(byte(char))
- }
- }
- return result.String()
- }
|