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

Unified Diff: components/password_manager/core/browser/import/csv_reader.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: Add build config header. Created 5 years, 11 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/import/csv_reader.h
diff --git a/components/password_manager/core/browser/import/csv_reader.h b/components/password_manager/core/browser/import/csv_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..986b7b2a1f0d44188e96c8a075839932392f3177
--- /dev/null
+++ b/components/password_manager/core/browser/import/csv_reader.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_READER_H_
+#define COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_READER_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/macros.h"
+#include "base/strings/string_piece.h"
+
+namespace password_manager {
+
+// Reads tabular data from CSV (Comma Separated Values) format as defined in RFC
+// 4180, with the following limitations/relaxations:
+// * The input should be UTF-8 encoded. No code points should be escaped.
+// * The first line must be a header that contains the column names.
+// * Records may be separated by either LF or CRLF sequences. Each CRLF will
+// be converted to LF characters inside quotes.
+// * Inconsistent number of fields within records is handled gracefully. Extra
+// fields are ignored. Missing fields will have no corresponding key-value
+// pair in the record's ColumnNameToValueMap.
+// * Repeated columns of the same name are not supported (the last value will
+// be preserved).
+//
+// The CSV representation of the data will be read from |csv|. The first line of
+// the file should be a header to extract |column_names| from. From each
+// subsequent line, the extracted values are put into a map mapping column names
+// to the value of the corresponding field, and inserted into |records|. Both
+// |column_names| and |records| will be overwritten. Returns false if parsing
+// failed due to a syntax error.
+bool ReadCSV(base::StringPiece csv,
+ std::vector<std::string>* column_names,
+ std::vector<std::map<std::string, std::string>>* records);
+
+} // namespace password_manager
+
+#endif // COMPONENTS_PASSWORD_MANAGER_CORE_BROWSER_EXPORT_CSV_READER_H_

Powered by Google App Engine
This is Rietveld 408576698