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

Function CleanseRawStrings

analytical_engine/misc/cpplint.py:1769–1842  ·  view source on GitHub ↗

Removes C++11 raw strings from lines. Before: static const char kData[] = R"( multi-line string )"; After: static const char kData[] = "" (replaced by blank line) ""; Args: raw_lines: list of raw lines. Returns: list of line

(raw_lines)

Source from the content-addressed store, hash-verified

1767
1768
1769def CleanseRawStrings(raw_lines):
1770 """Removes C++11 raw strings from lines.
1771
1772 Before:
1773 static const char kData[] = R"(
1774 multi-line string
1775 )";
1776
1777 After:
1778 static const char kData[] = ""
1779 (replaced by blank line)
1780 "";
1781
1782 Args:
1783 raw_lines: list of raw lines.
1784
1785 Returns:
1786 list of lines with C++11 raw strings replaced by empty strings.
1787 """
1788
1789 delimiter = None
1790 lines_without_raw_strings = []
1791 for line in raw_lines:
1792 if delimiter:
1793 # Inside a raw string, look for the end
1794 end = line.find(delimiter)
1795 if end >= 0:
1796 # Found the end of the string, match leading space for this
1797 # line and resume copying the original lines, and also insert
1798 # a "" on the last line.
1799 leading_space = Match(r'^(\s*)\S', line)
1800 line = leading_space.group(1) + '""' + line[end + len(delimiter):]
1801 delimiter = None
1802 else:
1803 # Haven't found the end yet, append a blank line.
1804 line = '""'
1805
1806 # Look for beginning of a raw string, and replace them with
1807 # empty strings. This is done in a loop to handle multiple raw
1808 # strings on the same line.
1809 while delimiter is None:
1810 # Look for beginning of a raw string.
1811 # See 2.14.15 [lex.string] for syntax.
1812 #
1813 # Once we have matched a raw string, we check the prefix of the
1814 # line to make sure that the line is not part of a single line
1815 # comment. It's done this way because we remove raw strings
1816 # before removing comments as opposed to removing comments
1817 # before removing raw strings. This is because there are some
1818 # cpplint checks that requires the comments to be preserved, but
1819 # we don't want to check comments that are inside raw strings.
1820 matched = Match(r'^(.*?)\b(?:R|u8R|uR|UR|LR)"([^\s\\()]*)\((.*)$', line)
1821 if (matched and
1822 not Match(r'^([^\'"]|\'(\\.|[^\'])*\'|"(\\.|[^"])*")*//',
1823 matched.group(1))):
1824 delimiter = ')' + matched.group(2) + '"'
1825
1826 end = matched.group(3).find(delimiter)

Callers 1

__init__Method · 0.85

Calls 4

findMethod · 0.80
MatchFunction · 0.70
appendMethod · 0.65
groupMethod · 0.45

Tested by

no test coverage detected