DelimitedText.h header

#include <ew/app/DelimitedText.h>

Namespace ew::app

Functions

QString ew::app::text::escapeDelimitedField(const QString &field, QChar separator)

Quotes field for delimited-text output when it contains separator, a quote, or a newline.

RFC 4180: the field is wrapped in quotes and every inner quote is doubled. A field needing none of that is returned untouched, so an ordinary file stays readable.

std::vector< std::vector< QString > > ew::app::text::parseDelimitedRows(const QString &text, QChar separator)

Parses delimited text into rows of fields. separator is ',' for CSV, '\t' for TSV.

Quoted fields (with doubled inner quotes) and CRLF or LF line endings are both handled, because a file comes back from whatever the other person happened to use.

A quote only opens a quoted field at the field's START. A quote in the middle of an unquoted field – a 12" pipe measurement, an inches mark in prose – is a literal character, matching Excel and RFC 4180, rather than silently switching modes and swallowing the rest of the line.

Lives here rather than inside either caller because two unrelated features exchange delimited text with the outside world – the spreadsheet's CSV/TSV import-export and the localization pipeline's translator files – and a second hand-rolled parser is a second set of quoting bugs.