MCPcopy Create free account
hub / github.com/numpy/numpy / eliminate_quotes

Function eliminate_quotes

numpy/f2py/symbolic.py:1171–1197  ·  view source on GitHub ↗

Replace quoted substrings of input string. Return a new string and a mapping of replacements.

(s)

Source from the content-addressed store, hash-verified

1169
1170
1171def eliminate_quotes(s):
1172 """Replace quoted substrings of input string.
1173
1174 Return a new string and a mapping of replacements.
1175 """
1176 d = {}
1177
1178 def repl(m):
1179 kind, value = m.groups()[:2]
1180 if kind:
1181 # remove trailing underscore
1182 kind = kind[:-1]
1183 p = {"'": "SINGLE", '"': "DOUBLE"}[value[0]]
1184 k = f'{kind}@__f2py_QUOTES_{p}_{COUNTER.__next__()}@'
1185 d[k] = value
1186 return k
1187
1188 new_s = re.sub(r'({kind}_|)({single_quoted}|{double_quoted})'.format(
1189 kind=r'\w[\w\d_]*',
1190 single_quoted=r"('([^'\\]|(\\.))*')",
1191 double_quoted=r'("([^"\\]|(\\.))*")'),
1192 repl, s)
1193
1194 assert '"' not in new_s
1195 assert "'" not in new_s
1196
1197 return new_s, d
1198
1199
1200def insert_quotes(s, d):

Callers 2

workerMethod · 0.90
parseMethod · 0.85

Calls

no outgoing calls

Tested by 1

workerMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…