MCPcopy
hub / github.com/tensorflow/tfjs / CleanseRawStrings

Function CleanseRawStrings

tfjs-backend-wasm/tools/cpplint.py:1288–1361  ·  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

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

Callers 1

__init__Method · 0.85

Calls 3

MatchFunction · 0.85
findMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…