d
This commit is contained in:
@@ -10,12 +10,15 @@ def includes():
|
||||
def replaceAnd(s):
|
||||
return s.replace("and", "&&")
|
||||
|
||||
def replaceAppend(s):
|
||||
return s.replace(".append(", ".push_back(")
|
||||
|
||||
def replaceComment(s):
|
||||
return s.replace("#", "//")
|
||||
|
||||
def replaceLen(s):
|
||||
posLen = s.find("len(")
|
||||
posEnd = s.find(")")
|
||||
posEnd = s.find(")", posLen)
|
||||
if (
|
||||
posLen == -1 or
|
||||
posEnd == -1
|
||||
@@ -26,6 +29,9 @@ def replaceLen(s):
|
||||
after = s[posEnd + len(")"):]
|
||||
return f"{before}{name}.size(){after}"
|
||||
|
||||
def replaceTrue(s):
|
||||
return s.replace("True", "true")
|
||||
|
||||
def translateParameter(s):
|
||||
# name: type -> type name
|
||||
parts = s.split(": ")
|
||||
@@ -147,7 +153,11 @@ class CPP:
|
||||
for i in range(0, len(self.fn.statements)):
|
||||
s = translateStatement(self.fn.statements[i], self)
|
||||
s = replaceAnd(s)
|
||||
s = replaceAppend(s)
|
||||
# Replace len twice to account for double invocation.
|
||||
s = replaceLen(s)
|
||||
s = replaceLen(s)
|
||||
s = replaceTrue(s)
|
||||
sts.append(s)
|
||||
strstatements = "\n".join(sts)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user