emoji: repair one-shot candidate selection
This commit is contained in:
15
map/mkemoji
15
map/mkemoji
@@ -7,6 +7,7 @@ from pathlib import Path
|
||||
|
||||
|
||||
SOURCE = Path(__file__).with_name("emoji.src")
|
||||
MAXRUNES = 64
|
||||
|
||||
|
||||
def fold(s):
|
||||
@@ -14,22 +15,30 @@ def fold(s):
|
||||
return unicodedata.normalize("NFC", s)
|
||||
|
||||
|
||||
def hascontrol(s):
|
||||
return any(unicodedata.category(c) == "Cc" for c in s)
|
||||
|
||||
|
||||
def read(path):
|
||||
entries = []
|
||||
with path.open(encoding="utf-8") as src:
|
||||
for lineno, raw in enumerate(src, 1):
|
||||
line = raw.rstrip("\r\n")
|
||||
if not line.strip() or line.lstrip().startswith("#"):
|
||||
if not line.strip():
|
||||
continue
|
||||
if "\t" not in line and line.lstrip().startswith("#"):
|
||||
continue
|
||||
fields = line.split("\t")
|
||||
if len(fields) < 2:
|
||||
raise ValueError(f"{path}:{lineno}: need a result and an alias")
|
||||
result = unicodedata.normalize("NFC", fields[0])
|
||||
if not result or any(c.isspace() for c in result):
|
||||
if (not result or len(result) > MAXRUNES or hascontrol(result)
|
||||
or any(c.isspace() for c in result)):
|
||||
raise ValueError(f"{path}:{lineno}: bad result")
|
||||
for field in fields[1:]:
|
||||
alias = fold(field)
|
||||
if not alias or alias != alias.strip():
|
||||
if (not alias or len(alias) > MAXRUNES or hascontrol(alias)
|
||||
or alias != alias.strip()):
|
||||
raise ValueError(f"{path}:{lineno}: bad alias")
|
||||
entries.append((result, alias))
|
||||
return entries
|
||||
|
||||
Reference in New Issue
Block a user