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

Function markinnerspaces

numpy/f2py/crackfortran.py:1654–1688  ·  view source on GitHub ↗

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

(line)

Source from the content-addressed store, hash-verified

1652
1653
1654def markinnerspaces(line):
1655 """
1656 The function replace all spaces in the input variable line which are
1657 surrounded with quotation marks, with the triplet "@_@".
1658
1659 For instance, for the input "a 'b c'" the function returns "a 'b@_@c'"
1660
1661 Parameters
1662 ----------
1663 line : str
1664
1665 Returns
1666 -------
1667 str
1668
1669 """
1670 fragment = ''
1671 inside = False
1672 current_quote = None
1673 escaped = ''
1674 for c in line:
1675 if escaped == '\\' and c in ['\\', '\'', '"']:
1676 fragment += c
1677 escaped = c
1678 continue
1679 if not inside and c in ['\'', '"']:
1680 current_quote = c
1681 if c == current_quote:
1682 inside = not inside
1683 elif c == ' ' and inside:
1684 fragment += '@_@'
1685 continue
1686 fragment += c
1687 escaped = c # reset to non-backslash
1688 return fragment
1689
1690
1691def updatevars(typespec, selector, attrspec, entitydecl):

Callers 5

updatevarsFunction · 0.85

Calls

no outgoing calls