MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / parseCSV

Method parseCSV

app/src/DataModel/Importers/ModbusMapImporter.cpp:460–493  ·  view source on GitHub ↗

* @brief Parses a CSV register map with header-based column auto-detection. */

Source from the content-addressed store, hash-verified

458 * @brief Parses a CSV register map with header-based column auto-detection.
459 */
460bool DataModel::ModbusMapImporter::parseCSV(const QString& path)
461{
462 QFile file(path);
463 if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
464 return false;
465
466 if (file.size() > kMaxImportFileBytes)
467 return false;
468
469 const QString content = QString::fromUtf8(file.readAll());
470 file.close();
471
472 const auto lines = content.split('\n', Qt::SkipEmptyParts);
473 if (lines.count() < 2)
474 return false;
475
476 const auto map = buildCsvColumnMap(lines[0].trimmed().split(','));
477 if (map.addr < 0)
478 return false;
479
480 for (int row = 1; row < lines.count(); ++row) {
481 const auto line = lines[row].trimmed();
482 if (line.isEmpty() || line.startsWith('#'))
483 continue;
484
485 RegisterEntry entry;
486 if (!parseCsvRow(line.split(','), map, row, entry))
487 continue;
488
489 m_registers.append(entry);
490 }
491
492 return !m_registers.isEmpty();
493}
494
495//--------------------------------------------------------------------------------------------------
496// XML parser

Callers

nothing calls this directly

Calls 8

buildCsvColumnMapFunction · 0.85
parseCsvRowFunction · 0.85
isEmptyMethod · 0.80
openMethod · 0.45
sizeMethod · 0.45
closeMethod · 0.45
countMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected