Skip to content

Commit

Permalink
Merge pull request #244 from AgriculturalModelExchangeInitiative/issu…
Browse files Browse the repository at this point in the history
…e243

Issue243
  • Loading branch information
pradal authored Oct 23, 2024
2 parents 8255bb3 + 90cb52c commit d16a62e
Showing 1 changed file with 10 additions and 20 deletions.
30 changes: 10 additions & 20 deletions src/pycropml/transpiler/codeGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,17 @@ def emit_string(self, node, prefix=u''):


def safe_double(self, node):
if sys.version_info.major<3:
if '"' in node.value:
if "'" in node.value:
s = '"%s"' % node.value.replace('"', '\\"')
else:
s = "'%s'" % node.value
else:
s = '"%s"' % node.value
else:
if b'"' in node.value:
if b"'" in node.value:
s = '"%s"' % node.value.replace('"', '\\"')
else:
#s = "'%s'" % node.value
s = node.value.decode()
else:
#s = '"%s"' % node.value
s = '"%s"' % node.value.decode()

self.write(s)
# Decode the byte string to a normal string if it's in byte form
value = node.value.decode() if isinstance(node.value, bytes) else node.value

# Escape any existing double quotes in the value
escaped_value = value.replace('"', '')
escaped_value = escaped_value.replace("'", "")

# Wrap the result in double quotes and return
self.write(f'"{escaped_value}"')


def visit_simpleCall(self, node):
self.visit(node.value)
self.write(" %s "%node.op)
Expand Down

0 comments on commit d16a62e

Please sign in to comment.