Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(418)

Unified Diff: components/password_manager/core/browser/export/csv_writer.h

Issue 447763002: Implement CSVReader and CSVWriter to be used for password import and export. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nit. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d485b4b87b40559dbbd063d4e30552ebc7950641
--- /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/macros.h"
+
+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.
+// * Values will be enclosed in double-quotes if and only if they contain
+// either of the following characters: CR, LF, double-quote ("), comma (,).
+class CSVWriter {
vabr (Chromium) 2014/09/25 14:44:27 Why is this a class and not just a helper method?
engedy 2014/11/06 14:55:39 For consistency with JSONWriter.
vabr (Chromium) 2014/11/06 16:16:02 But the situation is different for JSONWriter -- J
engedy 2014/11/07 16:26:11 Yes, this is what I mean by consistency: there is
Peter Kasting 2014/11/07 18:38:29 I think it would be better as a global*, assuming
engedy 2014/11/07 19:39:43 OK, I have to concede. The typedef cannot be remo
Peter Kasting 2014/11/07 21:33:44 Oh, you can't just write "const std::vector<std::m
engedy 2014/11/10 09:33:29 Done. It turned out not so ugly after all.
+ public:
+ typedef std::map<std::string, std::string> ColumnNameToValueMap;
+
+ // Generates the CSV representation of the supplied data into |csv|. The first
vabr (Chromium) 2014/09/25 14:44:27 nit: Please specify if the generated data gets app
engedy 2014/11/06 14:55:39 Done.
+ // line of the file will contain |column_names|, followed by as many lines as
+ // there are elements in |records|. Each element in |records| should be a
+ // dictionary 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_

Powered by Google App Engine
This is Rietveld 408576698