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

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

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_file_value_serializer.h ('k') | base/json/json_parser.h » ('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 #include "base/json/json_file_value_serializer.h" 5 #include "base/json/json_file_value_serializer.h"
6 6
7 #include "base/files/file_util.h" 7 #include "base/files/file_util.h"
8 #include "base/json/json_string_value_serializer.h" 8 #include "base/json/json_string_value_serializer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 int data_size = static_cast<int>(json_string.size()); 47 int data_size = static_cast<int>(json_string.size());
48 if (base::WriteFile(json_file_path_, json_string.data(), data_size) != 48 if (base::WriteFile(json_file_path_, json_string.data(), data_size) !=
49 data_size) 49 data_size)
50 return false; 50 return false;
51 51
52 return true; 52 return true;
53 } 53 }
54 54
55 JSONFileValueDeserializer::JSONFileValueDeserializer( 55 JSONFileValueDeserializer::JSONFileValueDeserializer(
56 const base::FilePath& json_file_path) 56 const base::FilePath& json_file_path,
57 : json_file_path_(json_file_path), 57 int options)
58 allow_trailing_comma_(false), 58 : json_file_path_(json_file_path), options_(options), last_read_size_(0U) {}
59 last_read_size_(0U) {
60 }
61 59
62 JSONFileValueDeserializer::~JSONFileValueDeserializer() { 60 JSONFileValueDeserializer::~JSONFileValueDeserializer() {
63 } 61 }
64 62
65 int JSONFileValueDeserializer::ReadFileToString(std::string* json_string) { 63 int JSONFileValueDeserializer::ReadFileToString(std::string* json_string) {
66 DCHECK(json_string); 64 DCHECK(json_string);
67 if (!base::ReadFileToString(json_file_path_, json_string)) { 65 if (!base::ReadFileToString(json_file_path_, json_string)) {
68 #if defined(OS_WIN) 66 #if defined(OS_WIN)
69 int error = ::GetLastError(); 67 int error = ::GetLastError();
70 if (error == ERROR_SHARING_VIOLATION || error == ERROR_LOCK_VIOLATION) { 68 if (error == ERROR_SHARING_VIOLATION || error == ERROR_LOCK_VIOLATION) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 std::string json_string; 105 std::string json_string;
108 int error = ReadFileToString(&json_string); 106 int error = ReadFileToString(&json_string);
109 if (error != JSON_NO_ERROR) { 107 if (error != JSON_NO_ERROR) {
110 if (error_code) 108 if (error_code)
111 *error_code = error; 109 *error_code = error;
112 if (error_str) 110 if (error_str)
113 *error_str = GetErrorMessageForCode(error); 111 *error_str = GetErrorMessageForCode(error);
114 return NULL; 112 return NULL;
115 } 113 }
116 114
117 JSONStringValueDeserializer deserializer(json_string); 115 JSONStringValueDeserializer deserializer(json_string, options_);
118 deserializer.set_allow_trailing_comma(allow_trailing_comma_);
119 return deserializer.Deserialize(error_code, error_str); 116 return deserializer.Deserialize(error_code, error_str);
120 } 117 }
OLDNEW
« no previous file with comments | « base/json/json_file_value_serializer.h ('k') | base/json/json_parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698