diff options
Diffstat (limited to 'tools/snippets_translate')
| -rw-r--r-- | tools/snippets_translate/handlers.py | 18 | ||||
| -rw-r--r-- | tools/snippets_translate/tests/test_converter.py | 5 |
2 files changed, 18 insertions, 5 deletions
diff --git a/tools/snippets_translate/handlers.py b/tools/snippets_translate/handlers.py index 1af97ff64..6b9614880 100644 --- a/tools/snippets_translate/handlers.py +++ b/tools/snippets_translate/handlers.py @@ -30,8 +30,12 @@ ARRAY_DECLARATION_PATTERN = re.compile(r"^[a-zA-Z0-9\<\>]+ ([\w\*]+) *\[?\]?") RETURN_TYPE_PATTERN = re.compile(r"^ *[a-zA-Z0-9]+ [\w]+::([\w\*\&]+\(.*\)$)") CAPTURE_PATTERN = re.compile(r"^ *([a-zA-Z0-9]+) ([\w\*\&]+\(.*\)$)") USELESS_QT_CLASSES_PATTERNS = [ - re.compile(r"QLatin1String\((.*)\)"), - re.compile(r"QLatin1Char\((.*)\)") + re.compile(r'QLatin1StringView\(("[^"]*")\)'), + re.compile(r'QLatin1String\(("[^"]*")\)'), + re.compile(r'QString\.fromLatin1\(("[^"]*")\)'), + re.compile(r"QLatin1Char\(('[^']*')\)"), + re.compile(r'QStringLiteral\(("[^"]*")\)'), + re.compile(r'QString\.fromUtf8\(("[^"]*")\)') ] COMMENT1_PATTERN = re.compile(r" *# *[\w\ ]+$") COMMENT2_PATTERN = re.compile(r" *# *(.*)$") @@ -510,9 +514,13 @@ def handle_functions(x): def handle_useless_qt_classes(x): for c in USELESS_QT_CLASSES_PATTERNS: - content = c.search(x) - if content: - x = x.replace(content.group(0), content.group(1)) + while True: + match = c.search(x) + if match: + x = x[0:match.start()] + match.group(1) + x[match.end():] + else: + break + x = x.replace('"_s', '"') # New string literals return x diff --git a/tools/snippets_translate/tests/test_converter.py b/tools/snippets_translate/tests/test_converter.py index 4cf614d1e..1be9af553 100644 --- a/tools/snippets_translate/tests/test_converter.py +++ b/tools/snippets_translate/tests/test_converter.py @@ -368,7 +368,12 @@ def test_ternary_operator(): def test_useless_qt_classes(): assert st('result += QLatin1String("; ");') == 'result += "; "' + assert st('result += QString::fromLatin1("; ");') == 'result += "; "' + assert ( + st('result = QStringLiteral("A") + QStringLiteral("B");') + == 'result = "A" + "B"') assert st("<< QLatin1Char('\0') << endl;") == "print('\0')" + assert st('result = "A"_s;') == 'result = "A"' def test_special_cases(): |
