def main(): casegroups = unicode.CaseGroups() foldpairs = [] seen = {} for c in casegroups: if len(c) > MaxCasefoldGroup: raise unicode.Error("casefold group too long: %s" % (c, )) for i in range(len(c)): if c[i - 1] in seen: raise unicode.Error("bad casegroups %d -> %d" % (c[i - 1], c[i])) seen[c[i - 1]] = True foldpairs.append([c[i - 1], c[i]]) foldpairs.sort() foldranges = _MakeRanges(foldpairs) print _header print "// %d groups, %d pairs, %d ranges" % ( len(casegroups), len(foldpairs), len(foldranges)) print "CaseFold unicode_casefold[] = {" for lo, hi, delta in foldranges: print "\t{ %d, %d, %s }," % (lo, hi, delta) print "};" print "int num_unicode_casefold = %d;" % (len(foldranges), ) print _trailer
def main(): lowergroups, casegroups = unicode.CaseGroups() foldpairs = [] seen = {} for c in casegroups: if len(c) > MaxCasefoldGroup: raise unicode.Error("casefold group too long: %s" % (c,)) for i in range(len(c)): if c[i-1] in seen: raise unicode.Error("bad casegroups %d -> %d" % (c[i-1], c[i])) seen[c[i-1]] = True foldpairs.append([c[i-1], c[i]]) lowerpairs = [] for lower, group in lowergroups.iteritems(): for g in group: if g != lower: lowerpairs.append([g, lower]) def printpairs(name, foldpairs): foldpairs.sort() foldranges = _MakeRanges(foldpairs) print "// %d groups, %d pairs, %d ranges" % (len(casegroups), len(foldpairs), len(foldranges)) print "const CaseFold unicode_%s[] = {" % (name,) for lo, hi, delta in foldranges: print "\t{ %d, %d, %s }," % (lo, hi, delta) print "};" print "const int num_unicode_%s = %d;" % (name, len(foldranges),) print "" print _header printpairs("casefold", foldpairs) printpairs("tolower", lowerpairs) print _trailer
def _AddDelta(a, delta): """Return a + delta, handling EvenOdd and OddEven specially.""" if type(delta) == int: return a + delta if delta == 'EvenOdd': if a % 2 == 0: return a + 1 else: return a - 1 if delta == 'OddEven': if a % 2 == 1: return a + 1 else: return a - 1 print("Bad Delta:", delta, file=sys.stderr) raise unicode.Error("Bad Delta")