Created
April 18, 2016 12:27
-
-
Save greenqy/3f153f04de1840500b30e14219a6b4c3 to your computer and use it in GitHub Desktop.
This file contains 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
#! /usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
HALF2FULL = dict((i, i + 0xFEE0) for i in range(0x21, 0x7F)) | |
HALF2FULL[0x20] = 0x3000 | |
FULL2HALF = dict((i + 0xFEE0, i) for i in range(0x21, 0x7F)) | |
FULL2HALF[0x3000] = 0x20 | |
def fullen(s): | |
''' | |
Convert all ASCII characters to the full-width counterpart. | |
''' | |
return str(s).translate(HALF2FULL) | |
def halfen(s): | |
''' | |
Convert full-width characters to ASCII counterpart | |
''' | |
return str(s).translate(FULL2HALF) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment