MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / combinelines

Method combinelines

tools/reduce.py:155–194  ·  view source on GitHub ↗
(self, filedata)

Source from the content-addressed store, hash-verified

153 return par == 0
154
155 def combinelines(self, filedata):
156 if len(filedata) < 3:
157 return filedata
158
159 lines = []
160
161 for i in range(len(filedata) - 1):
162 fd1 = filedata[i].rstrip()
163 if fd1.endswith(','):
164 fd2 = filedata[i + 1].lstrip()
165 if fd2 != '':
166 lines.append(i)
167
168 chunksize = len(lines)
169 while chunksize > 10:
170 i = 0
171 while i < len(lines):
172 i1 = i
173 i2 = i + chunksize
174 i = i2
175 i2 = min(i2, len(lines))
176
177 filedata2 = list(filedata)
178 for line in lines[i1:i2]:
179 filedata2[line] = filedata2[line].rstrip() + filedata2[line + 1].lstrip()
180 filedata2[line + 1] = ''
181
182 if self.replaceandrun('combine lines (chunk)', filedata2, lines[i1] + 1, ''):
183 filedata = filedata2
184 lines[i1:i2] = []
185 i = i1
186
187 chunksize = int(chunksize / 2)
188
189 for line in lines:
190 fd1 = filedata[line].rstrip()
191 fd2 = filedata[line + 1].lstrip()
192 self.replaceandrun2('combine lines', filedata, line, fd1 + fd2, '')
193
194 return filedata
195
196 def removedirectives(self, filedata):
197 for i in range(len(filedata)):

Callers 3

mainFunction · 0.95
test_combinelines_chunkFunction · 0.80

Calls 2

replaceandrunMethod · 0.95
replaceandrun2Method · 0.95

Tested by 2

test_combinelines_chunkFunction · 0.64