MCPcopy Create free account
hub / github.com/alibaba/GraphScope / CleansedLines

Class CleansedLines

analytical_engine/misc/cpplint.py:1905–1997  ·  view source on GitHub ↗

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 is same

Source from the content-addressed store, hash-verified

1903
1904
1905class CleansedLines(object):
1906 """Holds 4 copies of all lines with different preprocessing applied to them.
1907
1908 1) elided member contains lines without strings and comments.
1909 2) lines member contains lines without comments.
1910 3) raw_lines member contains all the lines without processing.
1911 4) lines_without_raw_strings member is same as raw_lines, but with C++11 raw
1912 strings removed.
1913 All these members are of <type 'list'>, and of the same length.
1914 """
1915
1916 def __init__(self, lines):
1917 self.elided = []
1918 self.lines = []
1919 self.raw_lines = lines
1920 self.num_lines = len(lines)
1921 self.lines_without_raw_strings = CleanseRawStrings(lines)
1922 for linenum in range(len(self.lines_without_raw_strings)):
1923 self.lines.append(CleanseComments(
1924 self.lines_without_raw_strings[linenum]))
1925 elided = self._CollapseStrings(self.lines_without_raw_strings[linenum])
1926 self.elided.append(CleanseComments(elided))
1927
1928 def NumLines(self):
1929 """Returns the number of lines represented."""
1930 return self.num_lines
1931
1932 @staticmethod
1933 def _CollapseStrings(elided):
1934 """Collapses strings and chars on a line to simple "" or '' blocks.
1935
1936 We nix strings first so we're not fooled by text like '"http://"&#x27;
1937
1938 Args:
1939 elided: The line being processed.
1940
1941 Returns:
1942 The line with collapsed strings.
1943 """
1944 if _RE_PATTERN_INCLUDE.match(elided):
1945 return elided
1946
1947 # Remove escaped characters first to make quote/single quote collapsing
1948 # basic. Things that look like escaped characters shouldn't occur
1949 # outside of strings and chars.
1950 elided = _RE_PATTERN_CLEANSE_LINE_ESCAPES.sub('', elided)
1951
1952 # Replace quoted strings and digit separators. Both single quotes
1953 # and double quotes are processed in the same loop, otherwise
1954 # nested quotes wouldn't work.
1955 collapsed = ''
1956 while True:
1957 # Find the first quote character
1958 match = Match(r'^([^\'"]*)([\'"])(.*)$&#x27;, elided)
1959 if not match:
1960 collapsed += elided
1961 break
1962 head, quote, tail = match.groups()

Callers 1

ProcessFileDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected