unicode.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright 2021 Behdad Esfahbod. All Rights Reserved.
  2. def is_Default_Ignorable(u):
  3. # http://www.unicode.org/reports/tr44/#Default_Ignorable_Code_Point
  4. #
  5. # TODO Move me to unicodedata module and autogenerate.
  6. #
  7. # Unicode 14.0:
  8. # $ grep '; Default_Ignorable_Code_Point ' DerivedCoreProperties.txt | sed 's/;.*#/#/'
  9. # 00AD # Cf SOFT HYPHEN
  10. # 034F # Mn COMBINING GRAPHEME JOINER
  11. # 061C # Cf ARABIC LETTER MARK
  12. # 115F..1160 # Lo [2] HANGUL CHOSEONG FILLER..HANGUL JUNGSEONG FILLER
  13. # 17B4..17B5 # Mn [2] KHMER VOWEL INHERENT AQ..KHMER VOWEL INHERENT AA
  14. # 180B..180D # Mn [3] MONGOLIAN FREE VARIATION SELECTOR ONE..MONGOLIAN FREE VARIATION SELECTOR THREE
  15. # 180E # Cf MONGOLIAN VOWEL SEPARATOR
  16. # 180F # Mn MONGOLIAN FREE VARIATION SELECTOR FOUR
  17. # 200B..200F # Cf [5] ZERO WIDTH SPACE..RIGHT-TO-LEFT MARK
  18. # 202A..202E # Cf [5] LEFT-TO-RIGHT EMBEDDING..RIGHT-TO-LEFT OVERRIDE
  19. # 2060..2064 # Cf [5] WORD JOINER..INVISIBLE PLUS
  20. # 2065 # Cn <reserved-2065>
  21. # 2066..206F # Cf [10] LEFT-TO-RIGHT ISOLATE..NOMINAL DIGIT SHAPES
  22. # 3164 # Lo HANGUL FILLER
  23. # FE00..FE0F # Mn [16] VARIATION SELECTOR-1..VARIATION SELECTOR-16
  24. # FEFF # Cf ZERO WIDTH NO-BREAK SPACE
  25. # FFA0 # Lo HALFWIDTH HANGUL FILLER
  26. # FFF0..FFF8 # Cn [9] <reserved-FFF0>..<reserved-FFF8>
  27. # 1BCA0..1BCA3 # Cf [4] SHORTHAND FORMAT LETTER OVERLAP..SHORTHAND FORMAT UP STEP
  28. # 1D173..1D17A # Cf [8] MUSICAL SYMBOL BEGIN BEAM..MUSICAL SYMBOL END PHRASE
  29. # E0000 # Cn <reserved-E0000>
  30. # E0001 # Cf LANGUAGE TAG
  31. # E0002..E001F # Cn [30] <reserved-E0002>..<reserved-E001F>
  32. # E0020..E007F # Cf [96] TAG SPACE..CANCEL TAG
  33. # E0080..E00FF # Cn [128] <reserved-E0080>..<reserved-E00FF>
  34. # E0100..E01EF # Mn [240] VARIATION SELECTOR-17..VARIATION SELECTOR-256
  35. # E01F0..E0FFF # Cn [3600] <reserved-E01F0>..<reserved-E0FFF>
  36. return (
  37. u == 0x00AD
  38. or u == 0x034F # Cf SOFT HYPHEN
  39. or u == 0x061C # Mn COMBINING GRAPHEME JOINER
  40. or 0x115F <= u <= 0x1160 # Cf ARABIC LETTER MARK
  41. or 0x17B4 # Lo [2] HANGUL CHOSEONG FILLER..HANGUL JUNGSEONG FILLER
  42. <= u
  43. <= 0x17B5
  44. or 0x180B # Mn [2] KHMER VOWEL INHERENT AQ..KHMER VOWEL INHERENT AA
  45. <= u
  46. <= 0x180D
  47. or u # Mn [3] MONGOLIAN FREE VARIATION SELECTOR ONE..MONGOLIAN FREE VARIATION SELECTOR THREE
  48. == 0x180E
  49. or u == 0x180F # Cf MONGOLIAN VOWEL SEPARATOR
  50. or 0x200B <= u <= 0x200F # Mn MONGOLIAN FREE VARIATION SELECTOR FOUR
  51. or 0x202A <= u <= 0x202E # Cf [5] ZERO WIDTH SPACE..RIGHT-TO-LEFT MARK
  52. or 0x2060 # Cf [5] LEFT-TO-RIGHT EMBEDDING..RIGHT-TO-LEFT OVERRIDE
  53. <= u
  54. <= 0x2064
  55. or u == 0x2065 # Cf [5] WORD JOINER..INVISIBLE PLUS
  56. or 0x2066 <= u <= 0x206F # Cn <reserved-2065>
  57. or u == 0x3164 # Cf [10] LEFT-TO-RIGHT ISOLATE..NOMINAL DIGIT SHAPES
  58. or 0xFE00 <= u <= 0xFE0F # Lo HANGUL FILLER
  59. or u == 0xFEFF # Mn [16] VARIATION SELECTOR-1..VARIATION SELECTOR-16
  60. or u == 0xFFA0 # Cf ZERO WIDTH NO-BREAK SPACE
  61. or 0xFFF0 <= u <= 0xFFF8 # Lo HALFWIDTH HANGUL FILLER
  62. or 0x1BCA0 <= u <= 0x1BCA3 # Cn [9] <reserved-FFF0>..<reserved-FFF8>
  63. or 0x1D173 # Cf [4] SHORTHAND FORMAT LETTER OVERLAP..SHORTHAND FORMAT UP STEP
  64. <= u
  65. <= 0x1D17A
  66. or u == 0xE0000 # Cf [8] MUSICAL SYMBOL BEGIN BEAM..MUSICAL SYMBOL END PHRASE
  67. or u == 0xE0001 # Cn <reserved-E0000>
  68. or 0xE0002 <= u <= 0xE001F # Cf LANGUAGE TAG
  69. or 0xE0020 <= u <= 0xE007F # Cn [30] <reserved-E0002>..<reserved-E001F>
  70. or 0xE0080 <= u <= 0xE00FF # Cf [96] TAG SPACE..CANCEL TAG
  71. or 0xE0100 <= u <= 0xE01EF # Cn [128] <reserved-E0080>..<reserved-E00FF>
  72. or 0xE01F0 # Mn [240] VARIATION SELECTOR-17..VARIATION SELECTOR-256
  73. <= u
  74. <= 0xE0FFF
  75. or False # Cn [3600] <reserved-E01F0>..<reserved-E0FFF>
  76. )