summaryrefslogtreecommitdiffstats
path: root/util/locale_database/qlocalexml2cpp.py
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2020-02-19 17:18:28 +0100
committerEdward Welbourne <eddy@chaos.org.uk>2020-04-02 19:42:40 +0100
commitc3dea1ffca7e46319daed5b44895c6e09f51f3ea (patch)
tree141da0f6c8cacc0d13459d06ff921594b763b954 /util/locale_database/qlocalexml2cpp.py
parent4d9f1a87de7a6e50e89f96836bc2f0cf6e229dda (diff)
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 <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'util/locale_database/qlocalexml2cpp.py')
-rwxr-xr-xutil/locale_database/qlocalexml2cpp.py31
1 files changed, 2 insertions, 29 deletions
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: