Holds 4 copies of all lines with different preprocessing applied to them. 1) elided member contains lines without strings and comments. 2) lines member contains lines without comments. 3) raw_lines member contains all the lines without processing. 4) lines_without_raw_strings member
| 2141 | |
| 2142 | |
| 2143 | class CleansedLines: |
| 2144 | """Holds 4 copies of all lines with different preprocessing applied to them. |
| 2145 | |
| 2146 | 1) elided member contains lines without strings and comments. |
| 2147 | 2) lines member contains lines without comments. |
| 2148 | 3) raw_lines member contains all the lines without processing. |
| 2149 | 4) lines_without_raw_strings member is same as raw_lines, but with C++11 raw |
| 2150 | strings removed. |
| 2151 | All these members are of <type 'list'>, and of the same length. |
| 2152 | """ |
| 2153 | |
| 2154 | def __init__(self, lines): |
| 2155 | if "-readability/alt_tokens" in _cpplint_state.filters: |
| 2156 | for i, line in enumerate(lines): |
| 2157 | lines[i] = ReplaceAlternateTokens(line) |
| 2158 | self.elided = [] |
| 2159 | self.lines = [] |
| 2160 | self.raw_lines = lines |
| 2161 | self.num_lines = len(lines) |
| 2162 | self.lines_without_raw_strings = CleanseRawStrings(lines) |
| 2163 | for line in self.lines_without_raw_strings: |
| 2164 | self.lines.append(CleanseComments(line)) |
| 2165 | elided = self._CollapseStrings(line) |
| 2166 | self.elided.append(CleanseComments(elided)) |
| 2167 | |
| 2168 | def NumLines(self): |
| 2169 | """Returns the number of lines represented.""" |
| 2170 | return self.num_lines |
| 2171 | |
| 2172 | @staticmethod |
| 2173 | def _CollapseStrings(elided): |
| 2174 | """Collapses strings and chars on a line to simple "" or '' blocks. |
| 2175 | |
| 2176 | We nix strings first so we're not fooled by text like '"http://"' |
| 2177 | |
| 2178 | Args: |
| 2179 | elided: The line being processed. |
| 2180 | |
| 2181 | Returns: |
| 2182 | The line with collapsed strings. |
| 2183 | """ |
| 2184 | if _RE_PATTERN_INCLUDE.match(elided): |
| 2185 | return elided |
| 2186 | |
| 2187 | # Remove escaped characters first to make quote/single quote collapsing |
| 2188 | # basic. Things that look like escaped characters shouldn't occur |
| 2189 | # outside of strings and chars. |
| 2190 | elided = _RE_PATTERN_CLEANSE_LINE_ESCAPES.sub("", elided) |
| 2191 | |
| 2192 | # Replace quoted strings and digit separators. Both single quotes |
| 2193 | # and double quotes are processed in the same loop, otherwise |
| 2194 | # nested quotes wouldn't work. |
| 2195 | collapsed = "" |
| 2196 | while True: |
| 2197 | # Find the first quote character |
| 2198 | match = re.match(r'^([^\'"]*)([\'"])(.*)$', elided) |
| 2199 | if not match: |
| 2200 | collapsed += elided |
no outgoing calls
no test coverage detected
searching dependent graphs…