OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/password_manager/core/browser/export/csv_writer.h" | 5 #include "components/password_manager/core/browser/export/csv_writer.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
10 | 10 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 #endif | 58 #endif |
59 output_->append(kLineEnding); | 59 output_->append(kLineEnding); |
60 at_beginning_of_line_ = true; | 60 at_beginning_of_line_ = true; |
61 } | 61 } |
62 | 62 |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 namespace password_manager { | 65 namespace password_manager { |
66 | 66 |
67 void WriteCSV(const std::vector<std::string>& column_names, | 67 void WriteCSV(const std::vector<std::string>& column_names, |
68 const std::vector<std::map<std::string, std::string>>& records, | 68 const std::vector<ColumnNameToValueMap>& records, |
69 std::string* csv) { | 69 std::string* csv) { |
70 DCHECK(csv); | 70 DCHECK(csv); |
71 csv->clear(); | 71 csv->clear(); |
72 | 72 |
73 // Append header row. | 73 // Append header row. |
74 CSVFormatter formatter(csv); | 74 CSVFormatter formatter(csv); |
75 for (const auto& column_name : column_names) { | 75 for (const auto& column_name : column_names) { |
76 formatter.AppendValue(column_name); | 76 formatter.AppendValue(column_name); |
77 } | 77 } |
78 formatter.EndLine(); | 78 formatter.EndLine(); |
79 | 79 |
80 // Append every other data record row. | 80 // Append every other data record row. |
81 for (const auto& row : records) { | 81 for (const auto& row : records) { |
82 for (const auto& column_name : column_names) { | 82 for (const auto& column_name : column_names) { |
83 auto it_field = row.find(column_name); | 83 auto it_field = row.find(column_name); |
84 formatter.AppendValue(it_field != row.end() ? | 84 formatter.AppendValue(it_field != row.end() ? |
85 it_field->second : std::string()); | 85 it_field->second : std::string()); |
86 } | 86 } |
87 formatter.EndLine(); | 87 formatter.EndLine(); |
88 } | 88 } |
89 } | 89 } |
90 | 90 |
91 } // namespace password_manager | 91 } // namespace password_manager |
OLD | NEW |