Skip to content

Commit

Permalink
cope with raw strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ctiller committed Jan 25, 2025
1 parent f9cf29b commit 581e7bc
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tools/distrib/check_redundant_namespace_qualifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,18 @@ def find_closing_mustache(contents, initial_depth):
depth = initial_depth
start_len = len(contents)
while contents:
# Skip over raw strings.
if contents.startswith('R"'):
contents = contents[2:]
offset = contents.find('(')
assert offset != -1
prefix = contents[:offset]
contents = contents[offset:]
offset = contents.find(f'){prefix}"')
assert offset != -1
contents = contents[offset + len(prefix) + 2 :]
# Skip over strings.
if contents[0] == '"':
elif contents[0] == '"':
contents = contents[1:]
while contents[0] != '"':
if contents.startswith("\\\\"):
Expand Down Expand Up @@ -139,6 +149,9 @@ def update_file(contents, namespaces):
foo::a;
::foo::a;
}
{R"foo({
foo::a;
}foo)"}
"""
_TEST_EXPECTED = """
namespace bar {
Expand All @@ -150,6 +163,9 @@ def update_file(contents, namespaces):
a;
::foo::a;
}
{R"foo({
foo::a;
}foo)"}
"""
output = update_file(_TEST, ["foo"])
if output != _TEST_EXPECTED:
Expand Down Expand Up @@ -187,7 +203,7 @@ def update_file(contents, namespaces):
updated = update_file(contents, config.namespaces)
except:
print(f"error checking {file}")
continue
raise
if updated != contents:
changed.append(path)
with open(os.path.join(root, file), "w") as f:
Expand Down

0 comments on commit 581e7bc

Please sign in to comment.