CMS 3D CMS Logo

Functions | Variables
commentSkipper.cppCommentSkipper Namespace Reference

Functions

def filterFile (file)
 
def filterFiles (fileList)
 

Variables

 __author__
 
 __date__
 

Function Documentation

◆ filterFile()

def commentSkipper.cppCommentSkipper.filterFile (   file)

Definition at line 14 of file cppCommentSkipper.py.

References spr.find(), print(), FastTimerService_cff.range, and python.rootplot.root2matplotlib.replace().

Referenced by commentSkipper.cppCommentSkipper.filterFiles().

14 def filterFile(file): #ifstream& input)
15  try:
16  lines = open(file).readlines()
17  except UnicodeDecodeError as e:
18  print("CppCommentSkipper: WARNING: Invalid UTF-8 sequence in {0}".format(file))
19  lines = open(file, errors='replace').readlines()
20  commentStage = False
21 
22  for i in range(len(lines)):
23  #for j in range(len(lines[i])):
24  j = 0
25 
26  while lines[i][j] != '\n':
27 
28  char = lines[i][j]
29  #char /
30  if char == '/':
31  #comment /*
32  if lines[i][j+1] == '*' and not commentStage: #why !commentStage? because it could be /*...../*.....*/
33  commentStage = True
34  commentStartLine, commentStartColumn = i, j
35  j += 1
36  #comment // why !commentStage? because, can be a variant of this example: /*....//.....*/
37  elif not commentStage and (lines[i][j+1] == '/'):
38  lines[i] = lines[i].replace(lines[i][j:],'\n', 1)
39  break
40  #char "
41  elif char == '"':
42  if not commentStage:
43  next = lines[i][j+1:].find('"') #next "
44  lines[i] = lines[i].replace(lines[i][j:j+next+2], '', 1) # clear string in ""
45  #char '
46  elif char == '\'':
47  if not commentStage:
48  next = lines[i][j+1:].find('\'') #next '
49  lines[i] = lines[i].replace(lines[i][j:j+next+2], '', 1) # clear string in ''
50  #char *
51  elif char == '*':
52  if (commentStage and (lines[i][j+1] == '/')):
53  commentStage = False;
54  if commentStartLine != i:
55  lines[i] = lines[i].replace(lines[i][:j+2],'', 1) # comment */ [..code]
56  j = -1 #because of j+=1 at the end
57  else:
58  lines[i] = lines[i].replace(lines[i][commentStartColumn:j+2], '', 1) # [code..] /*comment*/ [.. code]
59  j = commentStartColumn - 1 #because of j+=1 at the ends
60  if j < len(lines[i]) - 1:
61  j += 1
62  else:
63  j = 0
64  break
65  if commentStage:
66  if i == commentStartLine: lines[i] = lines[i].replace(lines[i][commentStartColumn:],'\n', 1)
67  else: lines[i] = lines[i].replace(lines[i][:], '\n')
68  return lines
69 
def replace(string, replacements)
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:47

◆ filterFiles()

def commentSkipper.cppCommentSkipper.filterFiles (   fileList)

Definition at line 7 of file cppCommentSkipper.py.

References commentSkipper.cppCommentSkipper.filterFile().

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

Variable Documentation

◆ __author__

commentSkipper.cppCommentSkipper.__author__
private

Definition at line 2 of file cppCommentSkipper.py.

◆ __date__

commentSkipper.cppCommentSkipper.__date__
private

Definition at line 3 of file cppCommentSkipper.py.