test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Functions | Variables
commentSkipper.cppCommentSkipper Namespace Reference

Functions

def filterFile
 
def filterFiles
 

Variables

string __author__ = "Aurelija"
 
string __date__ = "$2010-07-13 12.17.20$"
 

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 
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')
return lines
def commentSkipper.cppCommentSkipper.filterFiles (   fileList)

Definition at line 6 of file cppCommentSkipper.py.

References commentSkipper.cppCommentSkipper.filterFile().

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

Variable Documentation

string commentSkipper.cppCommentSkipper.__author__ = "Aurelija"

Definition at line 1 of file cppCommentSkipper.py.

string commentSkipper.cppCommentSkipper.__date__ = "$2010-07-13 12.17.20$"

Definition at line 2 of file cppCommentSkipper.py.