From ea24606562cfa878e597ec7718243f9071a3150f Mon Sep 17 00:00:00 2001 From: Daniel Parker Date: Wed, 22 Jan 2025 10:51:23 -0500 Subject: [PATCH] csv_encoder --- include/jsoncons_ext/csv/csv_encoder.hpp | 32 +++++------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/include/jsoncons_ext/csv/csv_encoder.hpp b/include/jsoncons_ext/csv/csv_encoder.hpp index bfc14a75c..937a86190 100644 --- a/include/jsoncons_ext/csv/csv_encoder.hpp +++ b/include/jsoncons_ext/csv/csv_encoder.hpp @@ -316,10 +316,11 @@ class basic_csv_encoder final : public basic_json_visitor { if (stack_[0].count_ == 0) { - if (has_column_names_) + bool first = true; + for (std::size_t i = 0; i < column_paths_.size(); ++i) { - bool first = true; - for (const auto& item : column_names_) + auto it = column_path_name_map_.find(column_paths_[i]); + if (it != column_path_name_map_.end()) { if (!first) { @@ -329,31 +330,10 @@ class basic_csv_encoder final : public basic_json_visitor { first = false; } - sink_.append(item.data(), item.length()); - } - sink_.append(line_delimiter_.data(), line_delimiter_.length()); - } - else - { - bool first = true; - for (std::size_t i = 0; i < column_paths_.size(); ++i) - { - auto it = column_path_name_map_.find(column_paths_[i]); - if (it != column_path_name_map_.end()) - { - if (!first) - { - sink_.push_back(field_delimiter_); - } - else - { - first = false; - } - sink_.append(it->second.data(), it->second.length()); - } + sink_.append(it->second.data(), it->second.length()); } - sink_.append(line_delimiter_.data(), line_delimiter_.length()); } + sink_.append(line_delimiter_.data(), line_delimiter_.length()); } for (std::size_t i = 0; i < column_paths_.size(); ++i) {