From c3dea1ffca7e46319daed5b44895c6e09f51f3ea Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 19 Feb 2020 17:18:28 +0100 Subject: Move some shared code to a localetools module The time-zone script was importing two functions from the locale data generation script. Move them to a separate module, to which I'll shortly add some more shared utilities. Cleaned up some imports in the process. Combined qlocalexml2cpp's and xpathlit's error classes into a new Error class in the new module and made it a bit more like a proper python error class. Task-number: QTBUG-81344 Change-Id: Idbe0139ba9aaa2f823b8f7216dee1d2539c18b75 Reviewed-by: Cristian Maureira-Fredes --- util/locale_database/qlocalexml2cpp.py | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) (limited to 'util/locale_database/qlocalexml2cpp.py') diff --git a/util/locale_database/qlocalexml2cpp.py b/util/locale_database/qlocalexml2cpp.py index eb76f02faa..c54c3953ae 100755 --- a/util/locale_database/qlocalexml2cpp.py +++ b/util/locale_database/qlocalexml2cpp.py @@ -37,9 +37,10 @@ import os import sys import tempfile import datetime -from enumdata import language_aliases, country_aliases, script_aliases from qlocalexml import QLocaleXmlReader +from enumdata import language_aliases, country_aliases, script_aliases +from localetools import unicode2hex, wrap_list, Error # TODO: Make calendars a command-line parameter # map { CLDR name: Qt file name } @@ -59,19 +60,6 @@ generated_template = """ """ -class Error: - def __init__(self, msg): - self.msg = msg - def __str__(self): - return self.msg - -def wrap_list(lst): - def split(lst, size): - while lst: - head, lst = lst[:size], lst[size:] - yield head - return ",\n".join(", ".join(x) for x in split(lst, 20)) - def fixedScriptName(name, dupes): # Don't .capitalize() as some names are already camel-case (see enumdata.py): name = ''.join(word[0].upper() + word[1:] for word in name.split()) @@ -127,21 +115,6 @@ def compareLocaleKeys(key1, key2): return key1[1] - key2[1] -def unicode2hex(s): - lst = [] - for x in s: - v = ord(x) - if v > 0xFFFF: - # make a surrogate pair - # copied from qchar.h - high = (v >> 10) + 0xd7c0 - low = (v % 0x400 + 0xdc00) - lst.append(hex(high)) - lst.append(hex(low)) - else: - lst.append(hex(v)) - return lst - class StringDataToken: def __init__(self, index, length): if index > 0xFFFF or length > 0xFFFF: -- cgit v1.2.3