Skip to content

Instantly share code, notes, and snippets.

@yuliji
Created March 23, 2018 06:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuliji/27a4856c8993a6b5676fb4de2642744d to your computer and use it in GitHub Desktop.
Save yuliji/27a4856c8993a6b5676fb4de2642744d to your computer and use it in GitHub Desktop.
[unicode_range] unicode block check, need python3
# coding: utf-8
UNICODE_RANGES = \
[[u'\x00', u'\x1f', u'Control character'],
[u' ', u'\x7f', u'Basic Latin'],
[u'\x80', u'\xff', u'Latin-1 Supplement'],
[u'\u0100', u'\u017f', u'Latin Extended-A'],
[u'\u0180', u'\u024f', u'Latin Extended-B'],
[u'\u0250', u'\u02af', u'IPA Extensions'],
[u'\u02b0', u'\u02ff', u'Spacing Modifier Letters'],
[u'\u0300', u'\u036f', u'Combining Diacritical Marks'],
[u'\u0370', u'\u03ff', u'Greek and Coptic'],
[u'\u0400', u'\u04ff', u'Cyrillic'],
[u'\u0500', u'\u052f', u'Cyrillic Supplement'],
[u'\u0530', u'\u058f', u'Armenian'],
[u'\u0590', u'\u05ff', u'Hebrew'],
[u'\u0600', u'\u06ff', u'Arabic'],
[u'\u0700', u'\u074f', u'Syriac'],
[u'\u0750', u'\u077f', u'Arabic Supplement'],
[u'\u0780', u'\u07bf', u'Thaana'],
[u'\u07c0', u'\u07ff', u'NKo'],
[u'\u0800', u'\u083f', u'Samaritan'],
[u'\u0840', u'\u085f', u'Mandaic'],
[u'\u0860', u'\u086f', u'Syriac Supplement'],
[u'\u08a0', u'\u08ff', u'Arabic Extended-A'],
[u'\u0900', u'\u097f', u'Devanagari'],
[u'\u0980', u'\u09ff', u'Bengali'],
[u'\u0a00', u'\u0a7f', u'Gurmukhi'],
[u'\u0a80', u'\u0aff', u'Gujarati'],
[u'\u0b00', u'\u0b7f', u'Oriya'],
[u'\u0b80', u'\u0bff', u'Tamil'],
[u'\u0c00', u'\u0c7f', u'Telugu'],
[u'\u0c80', u'\u0cff', u'Kannada'],
[u'\u0d00', u'\u0d7f', u'Malayalam'],
[u'\u0d80', u'\u0dff', u'Sinhala'],
[u'\u0e00', u'\u0e7f', u'Thai'],
[u'\u0e80', u'\u0eff', u'Lao'],
[u'\u0f00', u'\u0fff', u'Tibetan'],
[u'\u1000', u'\u109f', u'Myanmar'],
[u'\u10a0', u'\u10ff', u'Georgian'],
[u'\u1100', u'\u11ff', u'Hangul Jamo'],
[u'\u1200', u'\u137f', u'Ethiopic'],
[u'\u1380', u'\u139f', u'Ethiopic Supplement'],
[u'\u13a0', u'\u13ff', u'Cherokee'],
[u'\u1400', u'\u167f', u'Unified Canadian Aboriginal Syllabics'],
[u'\u1680', u'\u169f', u'Ogham'],
[u'\u16a0', u'\u16ff', u'Runic'],
[u'\u1700', u'\u171f', u'Tagalog'],
[u'\u1720', u'\u173f', u'Hanunoo'],
[u'\u1740', u'\u175f', u'Buhid'],
[u'\u1760', u'\u177f', u'Tagbanwa'],
[u'\u1780', u'\u17ff', u'Khmer'],
[u'\u1800', u'\u18af', u'Mongolian'],
[u'\u18b0', u'\u18ff', u'Unified Canadian Aboriginal Syllabics Extended'],
[u'\u1900', u'\u194f', u'Limbu'],
[u'\u1950', u'\u197f', u'Tai Le'],
[u'\u1980', u'\u19df', u'New Tai Lue'],
[u'\u19e0', u'\u19ff', u'Khmer Symbols'],
[u'\u1a00', u'\u1a1f', u'Buginese'],
[u'\u1a20', u'\u1aaf', u'Tai Tham'],
[u'\u1ab0', u'\u1aff', u'Combining Diacritical Marks Extended'],
[u'\u1b00', u'\u1b7f', u'Balinese'],
[u'\u1b80', u'\u1bbf', u'Sundanese'],
[u'\u1bc0', u'\u1bff', u'Batak'],
[u'\u1c00', u'\u1c4f', u'Lepcha'],
[u'\u1c50', u'\u1c7f', u'Ol Chiki'],
[u'\u1c80', u'\u1c8f', u'Cyrillic Extended C'],
[u'\u1cc0', u'\u1ccf', u'Sundanese Supplement'],
[u'\u1cd0', u'\u1cff', u'Vedic Extensions'],
[u'\u1d00', u'\u1d7f', u'Phonetic Extensions'],
[u'\u1d80', u'\u1dbf', u'Phonetic Extensions Supplement'],
[u'\u1dc0', u'\u1dff', u'Combining Diacritical Marks Supplement'],
[u'\u1e00', u'\u1eff', u'Latin Extended Additional'],
[u'\u1f00', u'\u1fff', u'Greek Extended'],
[u'\u2000', u'\u206f', u'General Punctuation'],
[u'\u2070', u'\u209f', u'Superscripts and Subscripts'],
[u'\u20a0', u'\u20cf', u'Currency Symbols'],
[u'\u20d0', u'\u20ff', u'Combining Diacritical Marks for Symbols'],
[u'\u2100', u'\u214f', u'Letterlike Symbols'],
[u'\u2150', u'\u218f', u'Number Forms'],
[u'\u2190', u'\u21ff', u'Arrows'],
[u'\u2200', u'\u22ff', u'Mathematical Operators'],
[u'\u2300', u'\u23ff', u'Miscellaneous Technical'],
[u'\u2400', u'\u243f', u'Control Pictures'],
[u'\u2440', u'\u245f', u'Optical Character Recognition'],
[u'\u2460', u'\u24ff', u'Enclosed Alphanumerics'],
[u'\u2500', u'\u257f', u'Box Drawing'],
[u'\u2580', u'\u259f', u'Block Elements'],
[u'\u25a0', u'\u25ff', u'Geometric Shapes'],
[u'\u2600', u'\u26ff', u'Miscellaneous Symbols'],
[u'\u2700', u'\u27bf', u'Dingbats'],
[u'\u27c0', u'\u27ef', u'Miscellaneous Mathematical Symbols-A'],
[u'\u27f0', u'\u27ff', u'Supplemental Arrows-A'],
[u'\u2800', u'\u28ff', u'Braille Patterns'],
[u'\u2900', u'\u297f', u'Supplemental Arrows-B'],
[u'\u2980', u'\u29ff', u'Miscellaneous Mathematical Symbols-B'],
[u'\u2a00', u'\u2aff', u'Supplemental Mathematical Operators'],
[u'\u2b00', u'\u2bff', u'Miscellaneous Symbols and Arrows'],
[u'\u2c00', u'\u2c5f', u'Glagolitic'],
[u'\u2c60', u'\u2c7f', u'Latin Extended-C'],
[u'\u2c80', u'\u2cff', u'Coptic'],
[u'\u2d00', u'\u2d2f', u'Georgian Supplement'],
[u'\u2d30', u'\u2d7f', u'Tifinagh'],
[u'\u2d80', u'\u2ddf', u'Ethiopic Extended'],
[u'\u2de0', u'\u2dff', u'Cyrillic Extended-A'],
[u'\u2e00', u'\u2e7f', u'Supplemental Punctuation'],
[u'\u2e80', u'\u2eff', u'CJK Radicals Supplement'],
[u'\u2f00', u'\u2fdf', u'Kangxi Radicals'],
[u'\u2ff0', u'\u2fff', u'Ideographic Description Characters'],
[u'\u3000', u'\u303f', u'CJK Symbols and Punctuation'],
[u'\u3040', u'\u309f', u'Hiragana'],
[u'\u30a0', u'\u30ff', u'Katakana'],
[u'\u3100', u'\u312f', u'Bopomofo'],
[u'\u3130', u'\u318f', u'Hangul Compatibility Jamo'],
[u'\u3190', u'\u319f', u'Kanbun'],
[u'\u31a0', u'\u31bf', u'Bopomofo Extended'],
[u'\u31c0', u'\u31ef', u'CJK Strokes'],
[u'\u31f0', u'\u31ff', u'Katakana Phonetic Extensions'],
[u'\u3200', u'\u32ff', u'Enclosed CJK Letters and Months'],
[u'\u3300', u'\u33ff', u'CJK Compatibility'],
[u'\u3400', u'\u4dbf', u'CJK Unified Ideographs Extension A'],
[u'\u4dc0', u'\u4dff', u'Yijing Hexagram Symbols'],
[u'\u4e00', u'\u9fff', u'CJK Unified Ideographs'],
[u'\ua000', u'\ua48f', u'Yi Syllables'],
[u'\ua490', u'\ua4cf', u'Yi Radicals'],
[u'\ua4d0', u'\ua4ff', u'Lisu'],
[u'\ua500', u'\ua63f', u'Vai'],
[u'\ua640', u'\ua69f', u'Cyrillic Extended-B'],
[u'\ua6a0', u'\ua6ff', u'Bamum'],
[u'\ua700', u'\ua71f', u'Modifier Tone Letters'],
[u'\ua720', u'\ua7ff', u'Latin Extended-D'],
[u'\ua800', u'\ua82f', u'Syloti Nagri'],
[u'\ua830', u'\ua83f', u'Common Indic Number Forms'],
[u'\ua840', u'\ua87f', u'Phags-pa'],
[u'\ua880', u'\ua8df', u'Saurashtra'],
[u'\ua8e0', u'\ua8ff', u'Devanagari Extended'],
[u'\ua900', u'\ua92f', u'Kayah Li'],
[u'\ua930', u'\ua95f', u'Rejang'],
[u'\ua960', u'\ua97f', u'Hangul Jamo Extended-A'],
[u'\ua980', u'\ua9df', u'Javanese'],
[u'\ua9e0', u'\ua9ff', u'Myanmar Extended-B'],
[u'\uaa00', u'\uaa5f', u'Cham'],
[u'\uaa60', u'\uaa7f', u'Myanmar Extended-A'],
[u'\uaa80', u'\uaadf', u'Tai Viet'],
[u'\uaae0', u'\uaaff', u'Meetei Mayek Extensions'],
[u'\uab00', u'\uab2f', u'Ethiopic Extended-A'],
[u'\uab30', u'\uab6f', u'Latin Extended-E'],
[u'\uab70', u'\uabbf', u'Cherokee Supplement'],
[u'\uabc0', u'\uabff', u'Meetei Mayek'],
[u'\uac00', u'\ud7af', u'Hangul Syllables'],
[u'\ud7b0', u'\ud7ff', u'Hangul Jamo Extended-B'],
[u'\ud800', u'\udb7f', u'High Surrogates'],
[u'\udb80', u'\udbff', u'High Private Use Surrogates'],
[u'\udc00', u'\udfff', u'Low Surrogates'],
[u'\ue000', u'\uf8ff', u'Private Use Area'],
[u'\uf900', u'\ufaff', u'CJK Compatibility Ideographs'],
[u'\ufb00', u'\ufb4f', u'Alphabetic Presentation Forms'],
[u'\ufb50', u'\ufdff', u'Arabic Presentation Forms-A'],
[u'\ufe00', u'\ufe0f', u'Variation Selectors'],
[u'\ufe10', u'\ufe1f', u'Vertical Forms'],
[u'\ufe20', u'\ufe2f', u'Combining Half Marks'],
[u'\ufe30', u'\ufe4f', u'CJK Compatibility Forms'],
[u'\ufe50', u'\ufe6f', u'Small Form Variants'],
[u'\ufe70', u'\ufeff', u'Arabic Presentation Forms-B'],
[u'\uff00', u'\uffef', u'Halfwidth and Fullwidth Forms'],
[u'\ufff0', u'\uffff', u'Specials'],
[u'\U00010000', u'\U0001007f', u'Linear B Syllabary'],
[u'\U00010080', u'\U000100ff', u'Linear B Ideograms'],
[u'\U00010100', u'\U0001013f', u'Aegean Numbers'],
[u'\U00010140', u'\U0001018f', u'Ancient Greek Numbers'],
[u'\U00010190', u'\U000101cf', u'Ancient Symbols'],
[u'\U000101d0', u'\U000101ff', u'Phaistos Disc'],
[u'\U00010280', u'\U0001029f', u'Lycian'],
[u'\U000102a0', u'\U000102df', u'Carian'],
[u'\U000102e0', u'\U000102ff', u'Coptic Epact Numbers'],
[u'\U00010300', u'\U0001032f', u'Old Italic'],
[u'\U00010330', u'\U0001034f', u'Gothic'],
[u'\U00010350', u'\U0001037f', u'Old Permic'],
[u'\U00010380', u'\U0001039f', u'Ugaritic'],
[u'\U000103a0', u'\U000103df', u'Old Persian'],
[u'\U00010400', u'\U0001044f', u'Deseret'],
[u'\U00010450', u'\U0001047f', u'Shavian'],
[u'\U00010480', u'\U000104af', u'Osmanya'],
[u'\U000104b0', u'\U000104ff', u'Osage'],
[u'\U00010500', u'\U0001052f', u'Elbasan'],
[u'\U00010530', u'\U0001056f', u'Caucasian Albanian'],
[u'\U00010600', u'\U0001077f', u'Linear A'],
[u'\U00010800', u'\U0001083f', u'Cypriot Syllabary'],
[u'\U00010840', u'\U0001085f', u'Imperial Aramaic'],
[u'\U00010860', u'\U0001087f', u'Palmyrene'],
[u'\U00010880', u'\U000108af', u'Nabataean'],
[u'\U000108e0', u'\U000108ff', u'Hatran'],
[u'\U00010900', u'\U0001091f', u'Phoenician'],
[u'\U00010920', u'\U0001093f', u'Lydian'],
[u'\U00010980', u'\U0001099f', u'Meroitic Hieroglyphs'],
[u'\U000109a0', u'\U000109ff', u'Meroitic Cursive'],
[u'\U00010a00', u'\U00010a5f', u'Kharoshthi'],
[u'\U00010a60', u'\U00010a7f', u'Old South Arabian'],
[u'\U00010a80', u'\U00010a9f', u'Old North Arabian'],
[u'\U00010ac0', u'\U00010aff', u'Manichaean'],
[u'\U00010b00', u'\U00010b3f', u'Avestan'],
[u'\U00010b40', u'\U00010b5f', u'Inscriptional Parthian'],
[u'\U00010b60', u'\U00010b7f', u'Inscriptional Pahlavi'],
[u'\U00010b80', u'\U00010baf', u'Psalter Pahlavi'],
[u'\U00010c00', u'\U00010c4f', u'Old Turkic'],
[u'\U00010c80', u'\U00010cff', u'Old Hungarian'],
[u'\U00010e60', u'\U00010e7f', u'Rumi Numeral Symbols'],
[u'\U00011000', u'\U0001107f', u'Brahmi'],
[u'\U00011080', u'\U000110cf', u'Kaithi'],
[u'\U000110d0', u'\U000110ff', u'Sora Sompeng'],
[u'\U00011100', u'\U0001114f', u'Chakma'],
[u'\U00011150', u'\U0001117f', u'Mahajani'],
[u'\U00011180', u'\U000111df', u'Sharada'],
[u'\U000111e0', u'\U000111ff', u'Sinhala Archaic Numbers'],
[u'\U00011200', u'\U0001124f', u'Khojki'],
[u'\U00011280', u'\U000112af', u'Multani'],
[u'\U000112b0', u'\U000112ff', u'Khudawadi'],
[u'\U00011300', u'\U0001137f', u'Grantha'],
[u'\U00011400', u'\U0001147f', u'Newa'],
[u'\U00011480', u'\U000114df', u'Tirhuta'],
[u'\U00011580', u'\U000115ff', u'Siddham'],
[u'\U00011600', u'\U0001165f', u'Modi'],
[u'\U00011660', u'\U0001167f', u'Mongolian Supplement'],
[u'\U00011680', u'\U000116cf', u'Takri'],
[u'\U00011700', u'\U0001173f', u'Ahom'],
[u'\U000118a0', u'\U000118ff', u'Warang Citi'],
[u'\U00011a00', u'\U00011a4f', u'Zanabazar Square'],
[u'\U00011a50', u'\U00011aaf', u'Soyombo'],
[u'\U00011ac0', u'\U00011aff', u'Pau Cin Hau'],
[u'\U00011c00', u'\U00011c6f', u'Bhaiksuki'],
[u'\U00011c70', u'\U00011cbf', u'Marchen'],
[u'\U00011d00', u'\U00011d5f', u'Masaram Gondi'],
[u'\U00012000', u'\U000123ff', u'Cuneiform'],
[u'\U00012400', u'\U0001247f', u'Cuneiform Numbers and Punctuation'],
[u'\U00012480', u'\U0001254f', u'Early Dynastic Cuneiform'],
[u'\U00013000', u'\U0001342f', u'Egyptian Hieroglyphs'],
[u'\U00014400', u'\U0001467f', u'Anatolian Hieroglyphs'],
[u'\U00016800', u'\U00016a3f', u'Bamum Supplement'],
[u'\U00016a40', u'\U00016a6f', u'Mro'],
[u'\U00016ad0', u'\U00016aff', u'Bassa Vah'],
[u'\U00016b00', u'\U00016b8f', u'Pahawh Hmong'],
[u'\U00016f00', u'\U00016f9f', u'Miao'],
[u'\U00016fe0', u'\U00016fff', u'Ideographic Symbols and Punctuation'],
[u'\U00017000', u'\U000187ff', u'Tangut'],
[u'\U00018800', u'\U00018aff', u'Tangut Components'],
[u'\U0001b000', u'\U0001b0ff', u'Kana Supplement'],
[u'\U0001b100', u'\U0001b12f', u'Kana Extended-A'],
[u'\U0001b170', u'\U0001b2ff', u'Nushu'],
[u'\U0001bc00', u'\U0001bc9f', u'Duployan'],
[u'\U0001bca0', u'\U0001bcaf', u'Shorthand Format Controls'],
[u'\U0001d000', u'\U0001d0ff', u'Byzantine Musical Symbols'],
[u'\U0001d100', u'\U0001d1ff', u'Musical Symbols'],
[u'\U0001d200', u'\U0001d24f', u'Ancient Greek Musical Notation'],
[u'\U0001d300', u'\U0001d35f', u'Tai Xuan Jing Symbols'],
[u'\U0001d360', u'\U0001d37f', u'Counting Rod Numerals'],
[u'\U0001d400', u'\U0001d7ff', u'Mathematical Alphanumeric Symbols'],
[u'\U0001d800', u'\U0001daaf', u'Sutton SignWriting'],
[u'\U0001e000', u'\U0001e02f', u'Glagolitic Supplement'],
[u'\U0001e800', u'\U0001e8df', u'Mende Kikakui'],
[u'\U0001e900', u'\U0001e95f', u'Adlam'],
[u'\U0001ee00', u'\U0001eeff', u'Arabic Mathematical Alphabetic Symbols'],
[u'\U0001f000', u'\U0001f02f', u'Mahjong Tiles'],
[u'\U0001f030', u'\U0001f09f', u'Domino Tiles'],
[u'\U0001f0a0', u'\U0001f0ff', u'Playing Cards'],
[u'\U0001f100', u'\U0001f1ff', u'Enclosed Alphanumeric Supplement'],
[u'\U0001f200', u'\U0001f2ff', u'Enclosed Ideographic Supplement'],
[u'\U0001f300', u'\U0001f5ff', u'Miscellaneous Symbols and Pictographs'],
[u'\U0001f600', u'\U0001f64f', u'Emoticons (Emoji)'],
[u'\U0001f650', u'\U0001f67f', u'Ornamental Dingbats'],
[u'\U0001f680', u'\U0001f6ff', u'Transport and Map Symbols'],
[u'\U0001f700', u'\U0001f77f', u'Alchemical Symbols'],
[u'\U0001f780', u'\U0001f7ff', u'Geometric Shapes Extended'],
[u'\U0001f800', u'\U0001f8ff', u'Supplemental Arrows-C'],
[u'\U0001f900', u'\U0001f9ff', u'Supplemental Symbols and Pictographs'],
[u'\U00020000', u'\U0002a6df', u'CJK Unified Ideographs Extension B'],
[u'\U0002a700', u'\U0002b73f', u'CJK Unified Ideographs Extension C'],
[u'\U0002b740', u'\U0002b81f', u'CJK Unified Ideographs Extension D'],
[u'\U0002b820', u'\U0002ceaf', u'CJK Unified Ideographs Extension E'],
[u'\U0002ceb0', u'\U0002ebef', u'CJK Unified Ideographs Extension F'],
[u'\U0002f800', u'\U0002fa1f', u'CJK Compatibility Ideographs Supplement'],
[u'\U000e0000', u'\U000e007f', u'Tags'],
[u'\U000e0100', u'\U000e01ef', u'Variation Selectors Supplement']]
def get_block_name(char):
if type(char) != str:
raise Exception('not unicode')
if len(char) != 1:
raise Exception('len is not 1')
for u_range in UNICODE_RANGES:
if u_range[0] <= char <= u_range[1]:
return u_range[2]
raise Exception('not in unicode range')
def get_block_names(string):
return get_block_name(min(string)), get_block_name(max(string))
def is_cjk_only(string):
min_block, max_block = get_block_names(string)
return is_cjk_char(min_block) and is_cjk_char(max_block)
def is_cjk_char(block_name):
return 'CJK' in block_name and block_name != 'CJK Symbols and Punctuation'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment