Welcome, guest | Sign In | My Account | Store | Cart

Translates ascii characters to wide characters.

Python, 11 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from string import printable, whitespace

def ascii2wide(ascii):
    wide = []
    for letter in ascii:
        if letter in whitespace or letter not in printable:
            wide.append(letter)
        else:
            wide.append(chr(ord(letter) + 0xFEE0))

    return ''.join(wide)

Each character in the returned string is the same as the character in the argument string, when that character is in string.whitespace or not in string.printable, or its wide character equivalent.

Note: some string.whitespace character is in string.printable.