Skip to content

Commit 0ff765a

Browse files
authored
Merge pull request chubin#312 from Jan200101/PR/g++
Catch edge cases were delimiter are wrongfully caught, such as in g++ Fixes chubin#308.
2 parents 2463185 + f8d2720 commit 0ff765a

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/cheat_wrapper.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,25 @@ def _add_section_name(query):
2626
if '/' in query:
2727
return query
2828
if ' ' in query:
29-
# for standalone queries only that may contain ' '
30-
return "%s/%s" % tuple(query.split(' ', 1))
31-
return "%s/%s" % tuple(query.split('+', 1))
29+
delim = " "
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
3248

3349
def cheat_wrapper(query, request_options=None, output_format='ansi'):
3450
"""

lib/cheat_wrapper_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
unchanged = """
44
python/:list
55
ls
6+
+
7+
g++
8+
g/+
9+
clang++
610
btrfs~volume
711
:intro
812
:cht.sh
@@ -14,6 +18,9 @@
1418
split = """
1519
python copy file
1620
python/copy file
21+
22+
g++ -O1
23+
g++/-O1
1724
"""
1825

1926
def test_header_split():

0 commit comments

Comments
 (0)