MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / CleanseRawStrings

Function CleanseRawStrings

rtpose_wrapper/scripts/cpp_lint.py:1062–1120  ·  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

1060
1061
1062def CleanseRawStrings(raw_lines):
1063 """Removes C++11 raw strings from lines.
1064
1065 Before:
1066 static const char kData[] = R"(
1067 multi-line string
1068 )";
1069
1070 After:
1071 static const char kData[] = ""
1072 (replaced by blank line)
1073 "";
1074
1075 Args:
1076 raw_lines: list of raw lines.
1077
1078 Returns:
1079 list of lines with C++11 raw strings replaced by empty strings.
1080 """
1081
1082 delimiter = None
1083 lines_without_raw_strings = []
1084 for line in raw_lines:
1085 if delimiter:
1086 # Inside a raw string, look for the end
1087 end = line.find(delimiter)
1088 if end >= 0:
1089 # Found the end of the string, match leading space for this
1090 # line and resume copying the original lines, and also insert
1091 # a "" on the last line.
1092 leading_space = Match(r'^(\s*)\S', line)
1093 line = leading_space.group(1) + '""' + line[end + len(delimiter):]
1094 delimiter = None
1095 else:
1096 # Haven't found the end yet, append a blank line.
1097 line = ''
1098
1099 else:
1100 # Look for beginning of a raw string.
1101 # See 2.14.15 [lex.string] for syntax.
1102 matched = Match(r'^(.*)\b(?:R|u8R|uR|UR|LR)"([^\s\\()]*)\((.*)$', line)
1103 if matched:
1104 delimiter = ')' + matched.group(2) + '"'
1105
1106 end = matched.group(3).find(delimiter)
1107 if end >= 0:
1108 # Raw string ended on same line
1109 line = (matched.group(1) + '""' +
1110 matched.group(3)[end + len(delimiter):])
1111 delimiter = None
1112 else:
1113 # Start of a multi-line raw string
1114 line = matched.group(1) + '""'
1115
1116 lines_without_raw_strings.append(line)
1117
1118 # TODO(unknown): if delimiter is not None here, we might want to
1119 # emit a warning for unterminated string.

Callers 1

__init__Method · 0.85

Calls 1

MatchFunction · 0.85

Tested by

no test coverage detected