Skip to content

Commit

Permalink
csv_encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
danielaparker committed Jan 22, 2025
1 parent 1f58fe9 commit ea24606
Showing 1 changed file with 6 additions and 26 deletions.
32 changes: 6 additions & 26 deletions include/jsoncons_ext/csv/csv_encoder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,11 @@ class basic_csv_encoder final : public basic_json_visitor<CharT>
{
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)
{
Expand All @@ -329,31 +330,10 @@ class basic_csv_encoder final : public basic_json_visitor<CharT>
{
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)
{
Expand Down

0 comments on commit ea24606

Please sign in to comment.