MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / CleanseRawStrings

Function CleanseRawStrings

steps/cpplint.py:1780–1853  ·  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

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

Callers 1

__init__Method · 0.85

Calls 2

MatchFunction · 0.85
appendMethod · 0.80

Tested by

no test coverage detected