aboutsummaryrefslogtreecommitdiffstats
path: root/tools/snippets_translate/handlers.py
diff options
context:
space:
mode:
Diffstat (limited to 'tools/snippets_translate/handlers.py')
-rw-r--r--tools/snippets_translate/handlers.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/tools/snippets_translate/handlers.py b/tools/snippets_translate/handlers.py
index 05c3cfba1..57b00e9da 100644
--- a/tools/snippets_translate/handlers.py
+++ b/tools/snippets_translate/handlers.py
@@ -39,6 +39,7 @@ COUT_ENDL_PATTERN = re.compile(r"cout *<<(.*)<< *.*endl")
COUT1_PATTERN = re.compile(r" *<< *")
COUT2_PATTERN = re.compile(r".*cout *<<")
COUT_ENDL2_PATTERN = re.compile(r"<< +endl")
+NEW_PATTERN = re.compile(r"new +([a-zA-Z][a-zA-Z0-9_]*)")
def handle_condition(x, name):
@@ -512,6 +513,23 @@ def handle_useless_qt_classes(x):
return x
+def handle_new(x):
+ """Parse operator new() and add parentheses were needed:
+ func(new Foo, new Bar(x))" -> "func(Foo(), Bar(x))"""
+ result = ""
+ last_pos = 0
+ for match in NEW_PATTERN.finditer(x):
+ end = match.end(0)
+ parentheses_needed = end >= len(x) or x[end] != "("
+ type_name = match.group(1)
+ result += x[last_pos:match.start(0)] + type_name
+ if parentheses_needed:
+ result += "()"
+ last_pos = end
+ result += x[last_pos:]
+ return result
+
+
# The code below handles pairs of instance/pointer to member functions (PMF)
# which appear in Qt in connect statements like:
# "connect(fontButton, &QAbstractButton::clicked, this, &Dialog::setFont)".