Go to the documentation of this file.00001 __author__="Aurelija"
00002 __date__ ="$2010-09-23 15.00.20$"
00003
00004 import re
00005
00006 declarator = '(\*|&)?(\w|<|>|$|::)+'
00007 cv_decl = '\s*(const|volatile|noexcept)\s*'
00008 exception = 'throw\(((::)|\w|\s|,|<|>)*\)'
00009 decl_param = '\s((\(%s\))|(%s))\s*\((\w|\s|\*|&|\.|=|\'|\"|-|<|>|,|(::))*\)'%(declarator, declarator)
00010 operator = '(%s|)operator\s*(\(\)|\[\]|\s+(new|delete)(\s*\[\]|)|\->[*]{0,1}|[+\-*/%%^&|~!=<>,]{1,2}(=|))'%(declarator)
00011 dm_init = '(:[^{]*)'
00012 functStart_re = re.compile('(\s|~|^)((\(%s\))|(%s)|(%s))\s*\((%s|\w|\s|\*|&|\.|=|\'|\"|-|<|>|,|::)*\)(%s)?(%s)?\s*(%s)?\s*{'%(declarator, declarator, operator, decl_param, cv_decl, exception,dm_init), re.MULTILINE)
00013
00014 def filterFiles(fileList):
00015 files = []
00016
00017 for i in range(len(fileList)):
00018 if type(fileList[0]).__name__ != 'tuple':
00019 file = fileList[i]
00020 fileLines = filterFile(fileList[i])
00021 else:
00022 file = fileList[i][0]
00023 fileLines = filterFile(fileList[i][1])
00024
00025 files.append((file, fileLines))
00026 return files
00027
00028 def filterFile(file):
00029
00030 lines = ""
00031
00032 if type(file).__name__ != 'list':
00033 lines = open(file).read()
00034 else:
00035 for line in file:
00036 lines += line
00037 fileLines = lines[:]
00038 prevEndPosition = 0
00039 endPosition = 0
00040 while(True):
00041 m = functStart_re.search(lines)
00042 if m != None:
00043 openBracket = 1
00044 closeBracket = 0
00045 startPosition = m.start()
00046
00047 for i, character in enumerate(lines[m.end():]):
00048 if character == "{":
00049 openBracket += 1
00050 elif character == "}":
00051 closeBracket += 1
00052 if openBracket == closeBracket :
00053 prevEndPosition += endPosition
00054 endPosition = m.end() + i + 1
00055 break
00056 if openBracket != closeBracket:
00057 print "Error in file. To much open brackets. Run commentSkipper before you run functionSkipper."
00058 break
00059 else:
00060
00061
00062 lines = delLines(lines, startPosition, endPosition)
00063 fileLines = fileLines[:prevEndPosition] + lines
00064 lines = lines[endPosition:]
00065 else:
00066 break
00067
00068 listOfLines = []
00069 startLine = 0
00070 for index, character in enumerate(fileLines):
00071 if character == "\n":
00072 listOfLines.append(fileLines[startLine:index+1])
00073 startLine = index + 1
00074 listOfLines.append(fileLines[startLine:])
00075 return listOfLines
00076
00077 def delLines(string, startPosition, endPosition):
00078 i = startPosition - 1
00079 end = startPosition
00080 while(True):
00081 if i != -1 and string[i] != '\n':
00082 i -= 1
00083 else:
00084 string = string[:i+1] + (end - i - 1)*' ' + string[end:]
00085 break
00086
00087 i = startPosition
00088 start = startPosition
00089 while(i != endPosition):
00090 if string[i] != '\n':
00091 i += 1
00092 else:
00093 string = string[:start] + (i-start)*str(" ") + string[i:]
00094 i = i+1
00095 start = i
00096 string = string[:start] + (endPosition-start)*str(" ") + string[endPosition:]
00097
00098 return string