MCPcopy Create free account
hub / github.com/apache/mesos / CleanseRawStrings

Function CleanseRawStrings

support/cpplint.py:1293–1366  ·  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

1291
1292
1293def CleanseRawStrings(raw_lines):
1294 """Removes C++11 raw strings from lines.
1295
1296 Before:
1297 static const char kData[] = R"(
1298 multi-line string
1299 )";
1300
1301 After:
1302 static const char kData[] = ""
1303 (replaced by blank line)
1304 "";
1305
1306 Args:
1307 raw_lines: list of raw lines.
1308
1309 Returns:
1310 list of lines with C++11 raw strings replaced by empty strings.
1311 """
1312
1313 delimiter = None
1314 lines_without_raw_strings = []
1315 for line in raw_lines:
1316 if delimiter:
1317 # Inside a raw string, look for the end
1318 end = line.find(delimiter)
1319 if end >= 0:
1320 # Found the end of the string, match leading space for this
1321 # line and resume copying the original lines, and also insert
1322 # a "" on the last line.
1323 leading_space = Match(r'^(\s*)\S', line)
1324 line = leading_space.group(1) + '""' + line[end + len(delimiter):]
1325 delimiter = None
1326 else:
1327 # Haven't found the end yet, append a blank line.
1328 line = '""'
1329
1330 # Look for beginning of a raw string, and replace them with
1331 # empty strings. This is done in a loop to handle multiple raw
1332 # strings on the same line.
1333 while delimiter is None:
1334 # Look for beginning of a raw string.
1335 # See 2.14.15 [lex.string] for syntax.
1336 #
1337 # Once we have matched a raw string, we check the prefix of the
1338 # line to make sure that the line is not part of a single line
1339 # comment. It's done this way because we remove raw strings
1340 # before removing comments as opposed to removing comments
1341 # before removing raw strings. This is because there are some
1342 # cpplint checks that requires the comments to be preserved, but
1343 # we don't want to check comments that are inside raw strings.
1344 matched = Match(r'^(.*?)\b(?:R|u8R|uR|UR|LR)"([^\s\\()]*)\((.*)$', line)
1345 if (matched and
1346 not Match(r'^([^\'"]|\'(\\.|[^\'])*\'|"(\\.|[^"])*")*//',
1347 matched.group(1))):
1348 delimiter = ')' + matched.group(2) + '"'
1349
1350 end = matched.group(3).find(delimiter)

Callers 1

__init__Method · 0.85

Calls 3

MatchFunction · 0.85
findMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected