Code Duplication    Length = 74-74 lines in 2 locations

sdk/build-support/cpplint.py 1 location

@@ 1458-1531 (lines=74) @@
1455
  return ((line.count('"') - line.count(r'\"') - line.count("'\"'")) & 1) == 1
1456
1457
1458
def CleanseRawStrings(raw_lines):
1459
  """Removes C++11 raw strings from lines.
1460
1461
    Before:
1462
      static const char kData[] = R"(
1463
          multi-line string
1464
          )";
1465
1466
    After:
1467
      static const char kData[] = ""
1468
          (replaced by blank line)
1469
          "";
1470
1471
  Args:
1472
    raw_lines: list of raw lines.
1473
1474
  Returns:
1475
    list of lines with C++11 raw strings replaced by empty strings.
1476
  """
1477
1478
  delimiter = None
1479
  lines_without_raw_strings = []
1480
  for line in raw_lines:
1481
    if delimiter:
1482
      # Inside a raw string, look for the end
1483
      end = line.find(delimiter)
1484
      if end >= 0:
1485
        # Found the end of the string, match leading space for this
1486
        # line and resume copying the original lines, and also insert
1487
        # a "" on the last line.
1488
        leading_space = Match(r'^(\s*)\S', line)
1489
        line = leading_space.group(1) + '""' + line[end + len(delimiter):]
1490
        delimiter = None
1491
      else:
1492
        # Haven't found the end yet, append a blank line.
1493
        line = '""'
1494
1495
    # Look for beginning of a raw string, and replace them with
1496
    # empty strings.  This is done in a loop to handle multiple raw
1497
    # strings on the same line.
1498
    while delimiter is None:
1499
      # Look for beginning of a raw string.
1500
      # See 2.14.15 [lex.string] for syntax.
1501
      #
1502
      # Once we have matched a raw string, we check the prefix of the
1503
      # line to make sure that the line is not part of a single line
1504
      # comment.  It's done this way because we remove raw strings
1505
      # before removing comments as opposed to removing comments
1506
      # before removing raw strings.  This is because there are some
1507
      # cpplint checks that requires the comments to be preserved, but
1508
      # we don't want to check comments that are inside raw strings.
1509
      matched = Match(r'^(.*?)\b(?:R|u8R|uR|UR|LR)"([^\s\\()]*)\((.*)$', line)
1510
      if (matched and
1511
          not Match(r'^([^\'"]|\'(\\.|[^\'])*\'|"(\\.|[^"])*")*//',
1512
                    matched.group(1))):
1513
        delimiter = ')' + matched.group(2) + '"'
1514
1515
        end = matched.group(3).find(delimiter)
1516
        if end >= 0:
1517
          # Raw string ended on same line
1518
          line = (matched.group(1) + '""' +
1519
                  matched.group(3)[end + len(delimiter):])
1520
          delimiter = None
1521
        else:
1522
          # Start of a multi-line raw string
1523
          line = matched.group(1) + '""'
1524
      else:
1525
        break
1526
1527
    lines_without_raw_strings.append(line)
1528
1529
  # TODO(unknown): if delimiter is not None here, we might want to
1530
  # emit a warning for unterminated string.
1531
  return lines_without_raw_strings
1532
1533
1534
def FindNextMultiLineCommentStart(lines, lineix):

core/build-support/cpplint.py 1 location

@@ 1458-1531 (lines=74) @@
1455
  return ((line.count('"') - line.count(r'\"') - line.count("'\"'")) & 1) == 1
1456
1457
1458
def CleanseRawStrings(raw_lines):
1459
  """Removes C++11 raw strings from lines.
1460
1461
    Before:
1462
      static const char kData[] = R"(
1463
          multi-line string
1464
          )";
1465
1466
    After:
1467
      static const char kData[] = ""
1468
          (replaced by blank line)
1469
          "";
1470
1471
  Args:
1472
    raw_lines: list of raw lines.
1473
1474
  Returns:
1475
    list of lines with C++11 raw strings replaced by empty strings.
1476
  """
1477
1478
  delimiter = None
1479
  lines_without_raw_strings = []
1480
  for line in raw_lines:
1481
    if delimiter:
1482
      # Inside a raw string, look for the end
1483
      end = line.find(delimiter)
1484
      if end >= 0:
1485
        # Found the end of the string, match leading space for this
1486
        # line and resume copying the original lines, and also insert
1487
        # a "" on the last line.
1488
        leading_space = Match(r'^(\s*)\S', line)
1489
        line = leading_space.group(1) + '""' + line[end + len(delimiter):]
1490
        delimiter = None
1491
      else:
1492
        # Haven't found the end yet, append a blank line.
1493
        line = '""'
1494
1495
    # Look for beginning of a raw string, and replace them with
1496
    # empty strings.  This is done in a loop to handle multiple raw
1497
    # strings on the same line.
1498
    while delimiter is None:
1499
      # Look for beginning of a raw string.
1500
      # See 2.14.15 [lex.string] for syntax.
1501
      #
1502
      # Once we have matched a raw string, we check the prefix of the
1503
      # line to make sure that the line is not part of a single line
1504
      # comment.  It's done this way because we remove raw strings
1505
      # before removing comments as opposed to removing comments
1506
      # before removing raw strings.  This is because there are some
1507
      # cpplint checks that requires the comments to be preserved, but
1508
      # we don't want to check comments that are inside raw strings.
1509
      matched = Match(r'^(.*?)\b(?:R|u8R|uR|UR|LR)"([^\s\\()]*)\((.*)$', line)
1510
      if (matched and
1511
          not Match(r'^([^\'"]|\'(\\.|[^\'])*\'|"(\\.|[^"])*")*//',
1512
                    matched.group(1))):
1513
        delimiter = ')' + matched.group(2) + '"'
1514
1515
        end = matched.group(3).find(delimiter)
1516
        if end >= 0:
1517
          # Raw string ended on same line
1518
          line = (matched.group(1) + '""' +
1519
                  matched.group(3)[end + len(delimiter):])
1520
          delimiter = None
1521
        else:
1522
          # Start of a multi-line raw string
1523
          line = matched.group(1) + '""'
1524
      else:
1525
        break
1526
1527
    lines_without_raw_strings.append(line)
1528
1529
  # TODO(unknown): if delimiter is not None here, we might want to
1530
  # emit a warning for unterminated string.
1531
  return lines_without_raw_strings
1532
1533
1534
def FindNextMultiLineCommentStart(lines, lineix):