mirror of
https://github.com/chubin/cheat.sh.git
synced 2026-06-20 13:16:44 +02:00
g++ workaround could still strip ++ if more ++ were encountered
This replaces cycle logic in #312 with regex.
This commit is contained in:
+3
-18
@@ -27,24 +27,9 @@ def _add_section_name(query):
|
||||
return query
|
||||
if ' ' in query:
|
||||
return re.sub(r' +', '/', query, count=1)
|
||||
elif '+' in query:
|
||||
delim = "+"
|
||||
|
||||
index = 0
|
||||
length = len(query)
|
||||
while index != length:
|
||||
|
||||
index = query.index(delim, index) + 1
|
||||
|
||||
try:
|
||||
comparison = query.index(delim, index)
|
||||
except ValueError:
|
||||
comparison = -1
|
||||
|
||||
if (index != comparison and index != length):
|
||||
return "%s/%s" % (query[:index-1], query[index:])
|
||||
|
||||
return query
|
||||
if '+' in query:
|
||||
# replace only single + to avoid catching g++ and friends
|
||||
return re.sub(r'([^\+])\+([^\+])', r'\1/\2', query, count=1)
|
||||
|
||||
def cheat_wrapper(query, request_options=None, output_format='ansi'):
|
||||
"""
|
||||
|
||||
@@ -13,6 +13,7 @@ btrfs~volume
|
||||
python/copy+file
|
||||
python/rosetta/:list
|
||||
emacs:go-mode/:list
|
||||
g++g++
|
||||
"""
|
||||
|
||||
split = """
|
||||
@@ -22,6 +23,9 @@ python/copy file
|
||||
python file
|
||||
python/file
|
||||
|
||||
python+file
|
||||
python/file
|
||||
|
||||
g++ -O1
|
||||
g++/-O1
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user