diff options
author | Matti Picus <matti.picus@gmail.com> | 2021-07-08 23:55:22 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-08 15:55:22 -0500 |
commit | 882f00bd47ceacbbcf34cad5d491be43fee0c99e (patch) | |
tree | ce212e48957891ab1e0362dc4553af0572a0acbb /numpy/f2py/crackfortran.py | |
parent | edb880dd9b3c7241b96ccef34c43bd9f90e4a6e4 (diff) | |
download | numpy-882f00bd47ceacbbcf34cad5d491be43fee0c99e.tar.gz |
BUG: f2py markinnerspace for multiple quotations (#19419)
Continuation of #15208
* BUG: markinnerspaces does not handle multiple quotations
* TST: test for markinnerspaces in f2py.crackfortran
* TST: tests for markinnerspaces with "
* DOC: markinnerspaces in f2py.crackfortran
* MAINT: more readable r strings in TestMarkinnerspaces
* ENH: give variables names, change 'inside' to bool
* :TEST, MAINT: add tests and changes from review
* MAINT: lint fixes
* BUG: typo
Co-authored-by: bdvd <bdvd001@gmail.com>
Diffstat (limited to 'numpy/f2py/crackfortran.py')
-rwxr-xr-x | numpy/f2py/crackfortran.py | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/numpy/f2py/crackfortran.py b/numpy/f2py/crackfortran.py index 984bd642b..2f491ed7e 100755 --- a/numpy/f2py/crackfortran.py +++ b/numpy/f2py/crackfortran.py @@ -1526,27 +1526,40 @@ def removespaces(expr): def markinnerspaces(line): - l = '' - f = 0 - cc = '\'' - cb = '' + """ + The function replace all spaces in the input variable line which are + surrounded with quotation marks, with the triplet "@_@". + + For instance, for the input "a 'b c'" the function returns "a 'b@_@c'" + + Parameters + ---------- + line : str + + Returns + ------- + str + + """ + fragment = '' + inside = False + current_quote = None + escaped = '' for c in line: - if cb == '\\' and c in ['\\', '\'', '"']: - l = l + c - cb = c + if escaped == '\\' and c in ['\\', '\'', '"']: + fragment += c + escaped = c continue - if f == 0 and c in ['\'', '"']: - cc = c - if c == cc: - f = f + 1 - elif c == cc: - f = f - 1 - elif c == ' ' and f == 1: - l = l + '@_@' + if not inside and c in ['\'', '"']: + current_quote = c + if c == current_quote: + inside = not inside + elif c == ' ' and inside: + fragment += '@_@' continue - l = l + c - cb = c - return l + fragment += c + escaped = c # reset to non-backslash + return fragment def updatevars(typespec, selector, attrspec, entitydecl): |