Created
April 22, 2012 06:30
-
-
Save haggaie/2462016 to your computer and use it in GitHub Desktop.
Convert \uDDDD sequences to unicode
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
#/usr/bin/env python | |
import sys, re | |
text = sys.stdin.read() | |
result = unicode() | |
unicode_char_re = re.compile(r'\\u[0-9a-fA-F]{4}') | |
prev_pos = 0 | |
for m in unicode_char_re.finditer(text): | |
span = m.span() | |
result += text[prev_pos:span[0]] | |
char = text[span[0]:span[1]] | |
char = unichr(int(char[2:],16)) | |
result += char | |
prev_pos = span[1] | |
result += text[prev_pos:] | |
print result.encode('utf-8') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment