File indexing completed on 2023-03-17 11:26:47
0001 from builtins import range
0002 __author__="Aurelija"
0003 __date__ ="$2010-07-13 12.17.20$"
0004
0005 import string
0006
0007 def filterFiles(fileList):
0008 files = []
0009
0010 for file in fileList:
0011 files.append((file, filterFile(file)))
0012 return files
0013
0014 def filterFile(file):
0015 try:
0016 lines = open(file).readlines()
0017 except UnicodeDecodeError as e:
0018 print("CppCommentSkipper: WARNING: Invalid UTF-8 sequence in {0}".format(file))
0019 lines = open(file, errors='replace').readlines()
0020 commentStage = False
0021
0022 for i in range(len(lines)):
0023
0024 j = 0
0025
0026 while lines[i][j] != '\n':
0027
0028 char = lines[i][j]
0029
0030 if char == '/':
0031
0032 if lines[i][j+1] == '*' and not commentStage:
0033 commentStage = True
0034 commentStartLine, commentStartColumn = i, j
0035 j += 1
0036
0037 elif not commentStage and (lines[i][j+1] == '/'):
0038 lines[i] = lines[i].replace(lines[i][j:],'\n', 1)
0039 break
0040
0041 elif char == '"':
0042 if not commentStage:
0043 next = lines[i][j+1:].find('"')
0044 lines[i] = lines[i].replace(lines[i][j:j+next+2], '', 1)
0045
0046 elif char == '\'':
0047 if not commentStage:
0048 next = lines[i][j+1:].find('\'')
0049 lines[i] = lines[i].replace(lines[i][j:j+next+2], '', 1)
0050
0051 elif char == '*':
0052 if (commentStage and (lines[i][j+1] == '/')):
0053 commentStage = False;
0054 if commentStartLine != i:
0055 lines[i] = lines[i].replace(lines[i][:j+2],'', 1)
0056 j = -1
0057 else:
0058 lines[i] = lines[i].replace(lines[i][commentStartColumn:j+2], '', 1)
0059 j = commentStartColumn - 1
0060 if j < len(lines[i]) - 1:
0061 j += 1
0062 else:
0063 j = 0
0064 break
0065 if commentStage:
0066 if i == commentStartLine: lines[i] = lines[i].replace(lines[i][commentStartColumn:],'\n', 1)
0067 else: lines[i] = lines[i].replace(lines[i][:], '\n')
0068 return lines