tools/categories.py: generate category lookup tables for the full unicode range.

This commit is contained in:
Reece H. Dunn
2012-12-21 23:55:27 +00:00
parent e6133fcafd
commit 12bafa6b4d
4 changed files with 119 additions and 7 deletions
+22 -3
View File
@@ -22,13 +22,28 @@ import sys
class CodePoint:
def __init__(self, x):
self.codepoint = int(x, 16)
if isinstance(x, str):
self.codepoint = int(x, 16)
else:
self.codepoint = x
def __repr__(self):
return '%04X' % self.codepoint
return '%06X' % self.codepoint
def __str__(self):
return '%04X' % self.codepoint
return '%06X' % self.codepoint
def __hash__(self):
return self.codepoint
def __eq__(self, other):
return self.codepoint == other.codepoint
def __ne__(self, other):
return self.codepoint != other.codepoint
def __lt__(self, other):
return self.codepoint < other.codepoint
class CodeRange:
def __init__(self, x):
@@ -42,6 +57,10 @@ class CodeRange:
def __str__(self):
return '%s..%s' % (self.first, self.last)
def __iter__(self):
for c in range(self.first.codepoint, self.last.codepoint + 1):
yield CodePoint(c)
def size(self):
return self.last.codepoint - self.first.codepoint + 1