Chromium Code Reviews| Index: components/password_manager/core/browser/export/csv_writer.h | 
| diff --git a/components/password_manager/core/browser/export/csv_writer.h b/components/password_manager/core/browser/export/csv_writer.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..28094a869333a5936c726502923f787d3f0c5382 | 
| --- /dev/null | 
| +++ b/components/password_manager/core/browser/export/csv_writer.h | 
| @@ -0,0 +1,41 @@ | 
| +// Copyright 2014 The Chromium Authors. All rights reserved. | 
| +// Use of this source code is governed by a BSD-style license that can be | 
| +// found in the LICENSE file. | 
| + | 
| +#ifndef COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_WRITER_H_ | 
| +#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_WRITER_H_ | 
| + | 
| +#include <map> | 
| +#include <string> | 
| +#include <vector> | 
| + | 
| +#include "base/basictypes.h" | 
| 
 
tfarina
2014/08/06 16:45:12
macros.h
 
engedy
2014/08/08 17:06:13
Done.
 
 | 
| + | 
| +namespace password_manager { | 
| + | 
| +// Writes tabular data into CSV (Comma Separated Values) format as defined in | 
| +// RFC 4180, with the following caveats: | 
| +// * The output encoding will be UTF-8. No code points will be escaped. | 
| +// * Lines will be separated by the platform-specific EOL terminator. | 
| 
 
vasilii
2014/08/06 17:42:16
Shouldn't we use CRLF as the RFC suggest? Otherwis
 
engedy
2014/08/08 17:06:13
Given that CSV files are text files after all, I t
 
 | 
| +// * Values will be enclosed in double-quotes iff they contain either of the | 
| 
 
vasilii
2014/08/06 17:42:16
s/iff/if
 
engedy
2014/08/08 17:06:13
That was intentional, but I have replaced with the
 
 | 
| +// following characters: CR, LF, double-quote ("), comma (,). | 
| +class CSVWriter { | 
| + public: | 
| + typedef std::map<std::string, std::string> ColumnNameToValueMap; | 
| + | 
| + // Generates the CSV representation of the supplied data into |csv|. The first | 
| + // line of the file will contain |column_names|, followed by as many lines as | 
| + // there are elements in |rows|. Each element in |rows| should be a dictionary | 
| 
 
vasilii
2014/08/06 17:42:16
There is no |row|.
 
engedy
2014/08/08 17:06:13
Renamed to |records|.
 
 | 
| + // that maps column names to values, so they can be output in the right order. | 
| + // All passed in strings should be UTF-8 encoded. | 
| + static void Write(const std::vector<std::string>& column_names, | 
| + const std::vector<ColumnNameToValueMap>& records, | 
| + std::string* csv); | 
| + | 
| + private: | 
| + DISALLOW_IMPLICIT_CONSTRUCTORS(CSVWriter); | 
| +}; | 
| + | 
| +} // namespace password_manager | 
| + | 
| +#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_WRITER_H_ |