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

Side by Side Diff: base/json/json_file_value_serializer.h

Issue 2475583002: Adds option for JSON reader to allow invalid utf characters (Closed)
Patch Set: comment Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « no previous file | base/json/json_file_value_serializer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #ifndef BASE_JSON_JSON_FILE_VALUE_SERIALIZER_H_ 5 #ifndef BASE_JSON_JSON_FILE_VALUE_SERIALIZER_H_
6 #define BASE_JSON_JSON_FILE_VALUE_SERIALIZER_H_ 6 #define BASE_JSON_JSON_FILE_VALUE_SERIALIZER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <string> 10 #include <string>
(...skipping 30 matching lines...) Expand all
41 bool SerializeInternal(const base::Value& root, bool omit_binary_values); 41 bool SerializeInternal(const base::Value& root, bool omit_binary_values);
42 42
43 const base::FilePath json_file_path_; 43 const base::FilePath json_file_path_;
44 44
45 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer); 45 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueSerializer);
46 }; 46 };
47 47
48 class BASE_EXPORT JSONFileValueDeserializer : public base::ValueDeserializer { 48 class BASE_EXPORT JSONFileValueDeserializer : public base::ValueDeserializer {
49 public: 49 public:
50 // |json_file_path_| is the path of a file that will be source of the 50 // |json_file_path_| is the path of a file that will be source of the
51 // deserialization. 51 // deserialization. |options| is a bitmask of JSONParserOptions.
52 explicit JSONFileValueDeserializer(const base::FilePath& json_file_path); 52 explicit JSONFileValueDeserializer(const base::FilePath& json_file_path,
53 int options = 0);
53 54
54 ~JSONFileValueDeserializer() override; 55 ~JSONFileValueDeserializer() override;
55 56
56 // Attempt to deserialize the data structure encoded in the file passed 57 // Attempt to deserialize the data structure encoded in the file passed
57 // in to the constructor into a structure of Value objects. If the return 58 // in to the constructor into a structure of Value objects. If the return
58 // value is NULL, and if |error_code| is non-null, |error_code| will 59 // value is NULL, and if |error_code| is non-null, |error_code| will
59 // contain an integer error code (either JsonFileError or JsonParseError). 60 // contain an integer error code (either JsonFileError or JsonParseError).
60 // If |error_message| is non-null, it will be filled in with a formatted 61 // If |error_message| is non-null, it will be filled in with a formatted
61 // error message including the location of the error if appropriate. 62 // error message including the location of the error if appropriate.
62 // The caller takes ownership of the returned value. 63 // The caller takes ownership of the returned value.
(...skipping 12 matching lines...) Expand all
75 // File-specific error messages that can be returned. 76 // File-specific error messages that can be returned.
76 static const char kAccessDenied[]; 77 static const char kAccessDenied[];
77 static const char kCannotReadFile[]; 78 static const char kCannotReadFile[];
78 static const char kFileLocked[]; 79 static const char kFileLocked[];
79 static const char kNoSuchFile[]; 80 static const char kNoSuchFile[];
80 81
81 // Convert an error code into an error message. |error_code| is assumed to 82 // Convert an error code into an error message. |error_code| is assumed to
82 // be a JsonFileError. 83 // be a JsonFileError.
83 static const char* GetErrorMessageForCode(int error_code); 84 static const char* GetErrorMessageForCode(int error_code);
84 85
85 void set_allow_trailing_comma(bool new_value) {
86 allow_trailing_comma_ = new_value;
87 }
88
89 // Returns the size (in bytes) of JSON string read from disk in the last 86 // Returns the size (in bytes) of JSON string read from disk in the last
90 // successful |Deserialize()| call. 87 // successful |Deserialize()| call.
91 size_t get_last_read_size() const { return last_read_size_; } 88 size_t get_last_read_size() const { return last_read_size_; }
92 89
93 private: 90 private:
94 // A wrapper for ReadFileToString which returns a non-zero JsonFileError if 91 // A wrapper for ReadFileToString which returns a non-zero JsonFileError if
95 // there were file errors. 92 // there were file errors.
96 int ReadFileToString(std::string* json_string); 93 int ReadFileToString(std::string* json_string);
97 94
98 const base::FilePath json_file_path_; 95 const base::FilePath json_file_path_;
99 bool allow_trailing_comma_; 96 const int options_;
100 size_t last_read_size_; 97 size_t last_read_size_;
101 98
102 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueDeserializer); 99 DISALLOW_IMPLICIT_CONSTRUCTORS(JSONFileValueDeserializer);
103 }; 100 };
104 101
105 #endif // BASE_JSON_JSON_FILE_VALUE_SERIALIZER_H_ 102 #endif // BASE_JSON_JSON_FILE_VALUE_SERIALIZER_H_
106 103
OLDNEW
« no previous file with comments | « no previous file | base/json/json_file_value_serializer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698