CMS 3D CMS Logo

cppCommentSkipper.py
Go to the documentation of this file.
1 from builtins import range
2 __author__="Aurelija"
3 __date__ ="$2010-07-13 12.17.20$"
4 
5 import string
6 
7 def filterFiles(fileList):
8  files = []
9 
10  for file in fileList:
11  files.append((file, filterFile(file)))
12  return files
13 
14 def filterFile(file): #ifstream& input)
15 
16  lines = open(file).readlines()
17  commentStage = False
18 
19  for i in range(len(lines)):
20  #for j in range(len(lines[i])):
21  j = 0
22 
23  while lines[i][j] != '\n':
24 
25  char = lines[i][j]
26  #char /
27  if char == '/':
28  #comment /*
29  if lines[i][j+1] == '*' and not commentStage: #why !commentStage? because it could be /*...../*.....*/
30  commentStage = True
31  commentStartLine, commentStartColumn = i, j
32  j += 1
33  #comment // why !commentStage? because, can be a variant of this example: /*....//.....*/
34  elif not commentStage and (lines[i][j+1] == '/'):
35  lines[i] = string.replace(lines[i], lines[i][j:],'\n', 1)
36  break
37  #char "
38  elif char == '"':
39  if not commentStage:
40  next = string.find(lines[i][j+1:], '"') #next "
41  lines[i] = string.replace(lines[i], lines[i][j:j+next+2], '', 1) # clear string in ""
42  #char '
43  elif char == '\'':
44  if not commentStage:
45  next = string.find(lines[i][j+1:], '\'') #next '
46  lines[i] = string.replace(lines[i], lines[i][j:j+next+2], '', 1) # clear string in ''
47  #char *
48  elif char == '*':
49  if (commentStage and (lines[i][j+1] == '/')):
50  commentStage = False;
51  if commentStartLine != i:
52  lines[i] = string.replace(lines[i], lines[i][:j+2],'', 1) # comment */ [..code]
53  j = -1 #because of j+=1 at the end
54  else:
55  lines[i] = string.replace(lines[i], lines[i][commentStartColumn:j+2], '', 1) # [code..] /*comment*/ [.. code]
56  j = commentStartColumn - 1 #because of j+=1 at the ends
57  if j != len(lines[i]) - 1:
58  j += 1
59  else:
60  j = 0
61  break
62  if commentStage:
63  if i == commentStartLine: lines[i] = lines[i].replace(lines[i][commentStartColumn:],'\n', 1)
64  else: lines[i] = lines[i].replace(lines[i][:], '\n')
65  return lines
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
commentSkipper.cppCommentSkipper.filterFile
def filterFile(file)
Definition: cppCommentSkipper.py:14
commentSkipper.cppCommentSkipper.filterFiles
def filterFiles(fileList)
Definition: cppCommentSkipper.py:7
python.rootplot.root2matplotlib.replace
def replace(string, replacements)
Definition: root2matplotlib.py:444