CMS 3D CMS Logo

Functions | Variables
commentSkipper.cppCommentSkipper Namespace Reference

Functions

def filterFile (file)
 
def filterFiles (fileList)
 

Variables

 __author__
 
 __date__
 

Function Documentation

def commentSkipper.cppCommentSkipper.filterFile (   file)

Definition at line 13 of file cppCommentSkipper.py.

References python.rootplot.root2matplotlib.replace().

Referenced by commentSkipper.cppCommentSkipper.filterFiles().

13 def filterFile(file): #ifstream& input)
14 
15  lines = open(file).readlines()
16  commentStage = False
17 
18  for i in range(len(lines)):
19  #for j in range(len(lines[i])):
20  j = 0
21 
22  while lines[i][j] != '\n':
23 
24  char = lines[i][j]
25  #char /
26  if char == '/':
27  #comment /*
28  if lines[i][j+1] == '*' and not commentStage: #why !commentStage? because it could be /*...../*.....*/
29  commentStage = True
30  commentStartLine, commentStartColumn = i, j
31  j += 1
32  #comment // why !commentStage? because, can be a variant of this example: /*....//.....*/
33  elif not commentStage and (lines[i][j+1] == '/'):
34  lines[i] = string.replace(lines[i], lines[i][j:],'\n', 1)
35  break
36  #char "
37  elif char == '"':
38  if not commentStage:
39  next = string.find(lines[i][j+1:], '"') #next "
40  lines[i] = string.replace(lines[i], lines[i][j:j+next+2], '', 1) # clear string in ""
41  #char '
42  elif char == '\'':
43  if not commentStage:
44  next = string.find(lines[i][j+1:], '\'') #next '
45  lines[i] = string.replace(lines[i], lines[i][j:j+next+2], '', 1) # clear string in ''
46  #char *
47  elif char == '*':
48  if (commentStage and (lines[i][j+1] == '/')):
49  commentStage = False;
50  if commentStartLine != i:
51  lines[i] = string.replace(lines[i], lines[i][:j+2],'', 1) # comment */ [..code]
52  j = -1 #because of j+=1 at the end
53  else:
54  lines[i] = string.replace(lines[i], lines[i][commentStartColumn:j+2], '', 1) # [code..] /*comment*/ [.. code]
55  j = commentStartColumn - 1 #because of j+=1 at the ends
56  if j != len(lines[i]) - 1:
57  j += 1
58  else:
59  j = 0
60  break
61  if commentStage:
62  if i == commentStartLine: lines[i] = lines[i].replace(lines[i][commentStartColumn:],'\n', 1)
63  else: lines[i] = lines[i].replace(lines[i][:], '\n')
64  return lines
def replace(string, replacements)
def commentSkipper.cppCommentSkipper.filterFiles (   fileList)

Definition at line 6 of file cppCommentSkipper.py.

References commentSkipper.cppCommentSkipper.filterFile().

6 def filterFiles(fileList):
7  files = []
8 
9  for file in fileList:
10  files.append((file, filterFile(file)))
11  return files
12 

Variable Documentation

commentSkipper.cppCommentSkipper.__author__
private

Definition at line 1 of file cppCommentSkipper.py.

commentSkipper.cppCommentSkipper.__date__
private

Definition at line 2 of file cppCommentSkipper.py.