Created
April 10, 2017 08:26
-
-
Save ethe/d16bf59c811dd5311f31492271c7387e to your computer and use it in GitHub Desktop.
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
| def is_surrogate(string): | |
| for index, char in enumerate(string): | |
| if 0xD800 <= ord(char) <= 0xDBFF: | |
| try: | |
| next_char = string[index + 1] | |
| except IndexError: | |
| pass | |
| if 0xDC00 <= ord(next_char) <= 0xDFFF: | |
| return True | |
| else: | |
| raise ValueError(u"Illegal UTF-16 sequence: {}".format(string)) | |
| return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment