Skip to content

Commit

Permalink
Update cppCommentSkipper.py
Browse files Browse the repository at this point in the history
Change `string.find(foo, bar)` into `foo.find(bar)`, `string.replace(foo, bar, baz, n)` into `foo.replace(bar, baz, n)`. The new syntax was already present in 2.7 series, and was removed in 3.x
  • Loading branch information
iarspider authored Jul 20, 2021
1 parent 5edc87f commit bb7e3c2
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,27 @@ def filterFile(file): #ifstream& input)
j += 1
#comment // why !commentStage? because, can be a variant of this example: /*....//.....*/
elif not commentStage and (lines[i][j+1] == '/'):
lines[i] = string.replace(lines[i], lines[i][j:],'\n', 1)
lines[i] = lines[i].replace(lines[i][j:],'\n', 1)
break
#char "
elif char == '"':
if not commentStage:
next = string.find(lines[i][j+1:], '"') #next "
lines[i] = string.replace(lines[i], lines[i][j:j+next+2], '', 1) # clear string in ""
next = lines[i][j+1:].find('"') #next "
lines[i] = lines[i].replace(lines[i][j:j+next+2], '', 1) # clear string in ""
#char '
elif char == '\'':
if not commentStage:
next = string.find(lines[i][j+1:], '\'') #next '
lines[i] = string.replace(lines[i], lines[i][j:j+next+2], '', 1) # clear string in ''
next = lines[i][j+1:].find('\'') #next '
lines[i] = lines[i].replace(lines[i][j:j+next+2], '', 1) # clear string in ''
#char *
elif char == '*':
if (commentStage and (lines[i][j+1] == '/')):
commentStage = False;
if commentStartLine != i:
lines[i] = string.replace(lines[i], lines[i][:j+2],'', 1) # comment */ [..code]
lines[i] = lines[i].replace(lines[i][:j+2],'', 1) # comment */ [..code]
j = -1 #because of j+=1 at the end
else:
lines[i] = string.replace(lines[i], lines[i][commentStartColumn:j+2], '', 1) # [code..] /*comment*/ [.. code]
lines[i] = lines[i].replace(lines[i][commentStartColumn:j+2], '', 1) # [code..] /*comment*/ [.. code]
j = commentStartColumn - 1 #because of j+=1 at the ends
if j != len(lines[i]) - 1:
j += 1
Expand All @@ -62,4 +62,4 @@ def filterFile(file): #ifstream& input)
if commentStage:
if i == commentStartLine: lines[i] = lines[i].replace(lines[i][commentStartColumn:],'\n', 1)
else: lines[i] = lines[i].replace(lines[i][:], '\n')
return lines
return lines

0 comments on commit bb7e3c2

Please sign in to comment.