diff options
author | Spartan322 <Megacake1234@gmail.com> | 2023-09-12 01:12:18 +0200 |
---|---|---|
committer | Spartan322 <Megacake1234@gmail.com> | 2023-09-14 10:30:42 +0200 |
commit | fed40d5dd5203bae678be7aea6fd91c73b43e298 (patch) | |
tree | 1c6dd3021397aa6b75b684ff7647b9ffbd2a4025 /src/openvic-dataloader/csv/Parser.cpp | |
parent | 3017487fa30b7f6593bd14e9c9d952ab948a6b80 (diff) |
Overhaul CSV parsing and align with Victoria 2 CSVs
Fix "" not being converted into " in Csv files
Move duplicated Grammar in CsvGrammar.hpp to Grammar.inc
Add ParseOptions to simplify template options
Add StringValue disable option:
Inlines value escapes
Add strings namespace to grammars for `ParseOptions.SupportStrings = true`
Add string parse handling to parse_csv via argument
Diffstat (limited to 'src/openvic-dataloader/csv/Parser.cpp')
-rw-r--r-- | src/openvic-dataloader/csv/Parser.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/openvic-dataloader/csv/Parser.cpp b/src/openvic-dataloader/csv/Parser.cpp index 86ad02e..14ef553 100644 --- a/src/openvic-dataloader/csv/Parser.cpp +++ b/src/openvic-dataloader/csv/Parser.cpp @@ -165,16 +165,23 @@ constexpr Parser<Encoding>& Parser<Encoding>::load_from_file(const detail::Has_c } template<EncodingType Encoding> -bool Parser<Encoding>::parse_csv() { +bool Parser<Encoding>::parse_csv(bool handle_strings) { if (!_buffer_handler->is_valid()) { return false; } std::optional<std::vector<ParseError>> errors; + auto report_error = ovdl::detail::ReporError.path(_file_path).to(detail::OStreamOutputIterator { _error_stream }); if constexpr (Encoding == EncodingType::Windows1252) { - errors = _buffer_handler->template parse<csv::grammar::windows1252::SemiColonFile>(ovdl::detail::ReporError.path(_file_path).to(detail::OStreamOutputIterator { _error_stream })); + if (handle_strings) + errors = _buffer_handler->template parse<csv::grammar::windows1252::strings::SemiColonFile>(report_error); + else + errors = _buffer_handler->template parse<csv::grammar::windows1252::SemiColonFile>(report_error); } else { - errors = _buffer_handler->template parse<csv::grammar::utf8::SemiColonFile>(ovdl::detail::ReporError.path(_file_path).to(detail::OStreamOutputIterator { _error_stream })); + if (handle_strings) + errors = _buffer_handler->template parse<csv::grammar::utf8::strings::SemiColonFile>(report_error); + else + errors = _buffer_handler->template parse<csv::grammar::utf8::SemiColonFile>(report_error); } if (errors) { _errors.reserve(errors->size()); |