MCPcopy Create free account
hub / github.com/XRay3D/GERBER_X3 / cleanAndFormatFile

Method cleanAndFormatFile

file_plugins/gerber/gbrparser.cpp:220–343  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

218}
219
220mvector<QString> Parser::cleanAndFormatFile(QString data)
221{
222 mvector<QString> gerberLines;
223 gerberLines.reserve(100000);
224
225 enum State {
226 Param,
227 Macro,
228 Data,
229 };
230
231 State state = Data;
232 QString lastLine;
233
234 auto gerberLinesAppend = [&gerberLines, &lastLine](State& state, const QString& val) -> void {
235 switch (state) {
236 case Macro:
237 lastLine.push_back(val);
238 if (lastLine.endsWith('%')) {
239 gerberLines << lastLine;
240 state = Data;
241 }
242 break;
243 case Param:
244 lastLine.push_back(val);
245 if (lastLine.endsWith('%')) {
246 for (QString& tmpline : lastLine.remove('%').split('*')) {
247 if (!tmpline.isEmpty()) {
248 gerberLines << ('%' + tmpline + "*%");
249 }
250 }
251 state = Data;
252 }
253 break;
254 case Data:
255 break;
256 }
257 };
258
259 auto lastLineClose = [&gerberLines](State state, QString& val) -> void {
260 switch (state) {
261 case Macro:
262 if (!val.endsWith('%'))
263 val.push_back('%');
264 if (!val.endsWith("*%"))
265 val.insert(val.length() - 2, '*');
266 gerberLines << val;
267 break;
268 case Param:
269 for (QString& tmpline : val.remove('%').split('*')) {
270 if (!tmpline.isEmpty()) {
271 gerberLines << ('%' + tmpline + "*%");
272 }
273 }
274 break;
275 case Data:
276 break;
277 }

Callers

nothing calls this directly

Calls 6

isEmptyMethod · 0.80
sizeMethod · 0.80
push_backMethod · 0.45
removeMethod · 0.45
clearMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected