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

Side by Side Diff: base/json/json_string_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 | « base/json/json_reader.h ('k') | base/json/json_string_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_STRING_VALUE_SERIALIZER_H_ 5 #ifndef BASE_JSON_JSON_STRING_VALUE_SERIALIZER_H_
6 #define BASE_JSON_JSON_STRING_VALUE_SERIALIZER_H_ 6 #define BASE_JSON_JSON_STRING_VALUE_SERIALIZER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/base_export.h" 10 #include "base/base_export.h"
(...skipping 29 matching lines...) Expand all
40 // Owned by the caller of the constructor. 40 // Owned by the caller of the constructor.
41 std::string* json_string_; 41 std::string* json_string_;
42 bool pretty_print_; // If true, serialization will span multiple lines. 42 bool pretty_print_; // If true, serialization will span multiple lines.
43 43
44 DISALLOW_COPY_AND_ASSIGN(JSONStringValueSerializer); 44 DISALLOW_COPY_AND_ASSIGN(JSONStringValueSerializer);
45 }; 45 };
46 46
47 class BASE_EXPORT JSONStringValueDeserializer : public base::ValueDeserializer { 47 class BASE_EXPORT JSONStringValueDeserializer : public base::ValueDeserializer {
48 public: 48 public:
49 // This retains a reference to the contents of |json_string|, so the data 49 // This retains a reference to the contents of |json_string|, so the data
50 // must outlive the JSONStringValueDeserializer. 50 // must outlive the JSONStringValueDeserializer. |options| is a bitmask of
51 explicit JSONStringValueDeserializer(const base::StringPiece& json_string); 51 // JSONParserOptions.
52 explicit JSONStringValueDeserializer(const base::StringPiece& json_string,
53 int options = 0);
52 54
53 ~JSONStringValueDeserializer() override; 55 ~JSONStringValueDeserializer() override;
54 56
55 // Attempt to deserialize the data structure encoded in the string passed 57 // Attempt to deserialize the data structure encoded in the string passed
56 // 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
57 // 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
58 // contain an integer error code (a JsonParseError in this case). 60 // contain an integer error code (a JsonParseError in this case).
59 // 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
60 // error message including the location of the error if appropriate. 62 // error message including the location of the error if appropriate.
61 // The caller takes ownership of the returned value. 63 // The caller takes ownership of the returned value.
62 std::unique_ptr<base::Value> Deserialize(int* error_code, 64 std::unique_ptr<base::Value> Deserialize(int* error_code,
63 std::string* error_message) override; 65 std::string* error_message) override;
64 66
65 void set_allow_trailing_comma(bool new_value) {
66 allow_trailing_comma_ = new_value;
67 }
68
69 private: 67 private:
70 // Data is owned by the caller of the constructor. 68 // Data is owned by the caller of the constructor.
71 base::StringPiece json_string_; 69 base::StringPiece json_string_;
72 // If true, deserialization will allow trailing commas. 70 const int options_;
73 bool allow_trailing_comma_;
74 71
75 DISALLOW_COPY_AND_ASSIGN(JSONStringValueDeserializer); 72 DISALLOW_COPY_AND_ASSIGN(JSONStringValueDeserializer);
76 }; 73 };
77 74
78 #endif // BASE_JSON_JSON_STRING_VALUE_SERIALIZER_H_ 75 #endif // BASE_JSON_JSON_STRING_VALUE_SERIALIZER_H_
OLDNEW
« no previous file with comments | « base/json/json_reader.h ('k') | base/json/json_string_value_serializer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698