CMS 3D CMS Logo

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.

00013                     : #ifstream& input)
00014 
00015     lines = open(file).readlines()
00016     commentStage = False
00017 
00018     for i in range(len(lines)):
00019         #for j in range(len(lines[i])):
00020         j = 0
00021         
00022         while lines[i][j] != '\n':
00023             
00024             char = lines[i][j]
00025             #char /
00026             if char == '/':
00027                 #comment /*
00028                 if lines[i][j+1] == '*' and not commentStage: #why !commentStage? because it could be /*...../*.....*/
00029                     commentStage = True
00030                     commentStartLine, commentStartColumn = i, j
00031                     j += 1
00032                 #comment //  why !commentStage? because, can be a variant of this example: /*....//.....*/
00033                 elif not commentStage and (lines[i][j+1] == '/'):
00034                     lines[i] = string.replace(lines[i], lines[i][j:],'\n', 1)
00035                     break
00036             #char "
00037             elif char == '"':
00038                 if not commentStage:
00039                     next = string.find(lines[i][j+1:], '"') #next "
00040                     lines[i] = string.replace(lines[i], lines[i][j:j+next+2], '', 1) # clear string in ""
00041             #char '
00042             elif char == '\'':
00043                 if not commentStage:
00044                     next = string.find(lines[i][j+1:], '\'') #next '
00045                     lines[i] = string.replace(lines[i], lines[i][j:j+next+2], '', 1) # clear string in ''
00046             #char *
00047             elif char == '*':
00048                 if (commentStage and (lines[i][j+1] == '/')):
00049                     commentStage = False;
00050                     if commentStartLine != i:
00051                         lines[i] = string.replace(lines[i], lines[i][:j+2],'', 1) # comment */ [..code]
00052                         j = -1 #because of j+=1 at the end
00053                     else:
00054                         lines[i] = string.replace(lines[i], lines[i][commentStartColumn:j+2], '', 1) # [code..] /*comment*/ [.. code]
00055                         j = commentStartColumn - 1 #because of j+=1 at the ends
00056             if j != len(lines[i]) - 1:
00057                 j += 1
00058             else:
00059                 j = 0
00060                 break
00061         if commentStage:
00062             if i == commentStartLine: lines[i] = lines[i].replace(lines[i][commentStartColumn:],'\n', 1)
00063             else: lines[i] = lines[i].replace(lines[i][:], '\n')
00064     return lines
def commentSkipper::cppCommentSkipper::filterFiles (   fileList)

Definition at line 6 of file cppCommentSkipper.py.

00007                          :
00008     files = []
00009 
00010     for file in fileList:
00011         files.append((file, filterFile(file)))
00012     return files


Variable Documentation

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.