MCPcopy Index your code
hub / github.com/python/cpython / makeunicodename

Function makeunicodename

Tools/unicode/makeunicodedata.py:710–802  ·  view source on GitHub ↗
(unicode, trace)

Source from the content-addressed store, hash-verified

708# unicode name database
709
710def makeunicodename(unicode, trace):
711 from dawg import build_compression_dawg
712
713 FILE = "Modules/unicodename_db.h"
714
715 print("--- Preparing", FILE, "...")
716
717 # unicode name hash table
718
719 # extract names
720 data = []
721 for char in unicode.chars:
722 record = unicode.table[char]
723 if record:
724 name = record.name.strip()
725 if name and name[0] != "<":
726 data.append((name, char))
727
728 print("--- Writing", FILE, "...")
729
730 with open(FILE, "w") as fp:
731 fprint = partial(print, file=fp)
732
733 fprint("/* this file was generated by %s %s */" % (SCRIPT, VERSION))
734 fprint()
735 fprint("#define NAME_MAXLEN", 256)
736 assert max(len(x) for x in data) < 256
737 fprint()
738
739 fprint("/* name->code dictionary */")
740 packed_dawg, pos_to_codepoint = build_compression_dawg(data)
741 notfound = len(pos_to_codepoint)
742 inverse_list = [notfound] * len(unicode.chars)
743 for pos, codepoint in enumerate(pos_to_codepoint):
744 inverse_list[codepoint] = pos
745 Array("packed_name_dawg", list(packed_dawg)).dump(fp, trace)
746 Array("dawg_pos_to_codepoint", pos_to_codepoint).dump(fp, trace)
747 index1, index2, shift = splitbins(inverse_list, trace)
748 fprint("#define DAWG_CODEPOINT_TO_POS_SHIFT", shift)
749 fprint("#define DAWG_CODEPOINT_TO_POS_NOTFOUND", notfound)
750 Array("dawg_codepoint_to_pos_index1", index1).dump(fp, trace)
751 Array("dawg_codepoint_to_pos_index2", index2).dump(fp, trace)
752
753 fprint()
754 fprint('static const unsigned int aliases_start = %#x;' %
755 NAME_ALIASES_START)
756 fprint('static const unsigned int aliases_end = %#x;' %
757 (NAME_ALIASES_START + len(unicode.aliases)))
758
759 fprint('static const unsigned int name_aliases[] = {')
760 for name, codepoint in unicode.aliases:
761 fprint(' 0x%04X,' % codepoint)
762 fprint('};')
763
764 # In Unicode 6.0.0, the sequences contain at most 4 BMP chars,
765 # so we are using Py_UCS2 seq[4]. This needs to be updated if longer
766 # sequences or sequences with non-BMP chars are added.
767 # unicodedata_lookup should be adapted too.

Callers 1

maketablesFunction · 0.85

Calls 12

partialClass · 0.90
build_compression_dawgFunction · 0.90
dedentFunction · 0.90
enumerateFunction · 0.85
listClass · 0.85
splitbinsFunction · 0.85
ArrayClass · 0.70
openFunction · 0.50
stripMethod · 0.45
appendMethod · 0.45
dumpMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…