(source)
| 111 | # contents of the C/C++ string as a python string. None if |
| 112 | # the lines did not encode a C/C++ style string. |
| 113 | def extractCString(source): |
| 114 | returnString = "" |
| 115 | isInQuotes = False |
| 116 | prevWasEscape = False |
| 117 | |
| 118 | for line in source.splitlines(True): |
| 119 | for c in line: |
| 120 | if c == "\"" and not prevWasEscape: |
| 121 | isInQuotes = not isInQuotes |
| 122 | elif isInQuotes: |
| 123 | returnString += c |
| 124 | prevWasEscape = c == "\\" |
| 125 | else: |
| 126 | if not (c.isspace()): |
| 127 | return None |
| 128 | |
| 129 | if isInQuotes: |
| 130 | return None |
| 131 | |
| 132 | return returnString |
| 133 | |
| 134 | # Attempt to extract a single argument in a C++ function invocation given |
| 135 | # the argument's start position (immediately after left parenthesis or comma) |
no outgoing calls