Skip to content

Commit 908bc52

Browse files
committed
g++ workaround could still strip ++ if more ++ were encountered
This replaces cycle logic in chubin#312 with regex.
1 parent 4643429 commit 908bc52

File tree

2 files changed

+7
-18
lines changed

2 files changed

+7
-18
lines changed

lib/cheat_wrapper.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,9 @@ def _add_section_name(query):
2727
return query
2828
if ' ' in query:
2929
return re.sub(r' +', '/', query, count=1)
30-
elif '+' in query:
31-
delim = "+"
32-
33-
index = 0
34-
length = len(query)
35-
while index != length:
36-
37-
index = query.index(delim, index) + 1
38-
39-
try:
40-
comparison = query.index(delim, index)
41-
except ValueError:
42-
comparison = -1
43-
44-
if (index != comparison and index != length):
45-
return "%s/%s" % (query[:index-1], query[index:])
46-
47-
return query
30+
if '+' in query:
31+
# replace only single + to avoid catching g++ and friends
32+
return re.sub(r'([^\+])\+([^\+])', r'\1/\2', query, count=1)
4833

4934
def cheat_wrapper(query, request_options=None, output_format='ansi'):
5035
"""

lib/cheat_wrapper_test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
python/copy+file
1414
python/rosetta/:list
1515
emacs:go-mode/:list
16+
g++g++
1617
"""
1718

1819
split = """
@@ -22,6 +23,9 @@
2223
python file
2324
python/file
2425
26+
python+file
27+
python/file
28+
2529
g++ -O1
2630
g++/-O1
2731
"""

0 commit comments

Comments
 (0)