forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjson_reader.cc
55 lines (43 loc) · 1.59 KB
/
json_reader.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (c) 2012 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.
#include "base/json/json_reader.h"
#include <utility>
#include <vector>
#include "base/json/json_parser.h"
#include "base/optional.h"
namespace base {
JSONReader::ValueWithError::ValueWithError() = default;
JSONReader::ValueWithError::ValueWithError(ValueWithError&& other) = default;
JSONReader::ValueWithError::~ValueWithError() = default;
JSONReader::ValueWithError& JSONReader::ValueWithError::operator=(
ValueWithError&& other) = default;
// static
Optional<Value> JSONReader::Read(StringPiece json,
int options,
size_t max_depth) {
internal::JSONParser parser(options, max_depth);
return parser.Parse(json);
}
// static
std::unique_ptr<Value> JSONReader::ReadDeprecated(StringPiece json,
int options,
size_t max_depth) {
Optional<Value> value = Read(json, options, max_depth);
return value ? Value::ToUniquePtrValue(std::move(*value)) : nullptr;
}
// static
JSONReader::ValueWithError JSONReader::ReadAndReturnValueWithError(
StringPiece json,
int options) {
ValueWithError ret;
internal::JSONParser parser(options);
ret.value = parser.Parse(json);
if (!ret.value) {
ret.error_message = parser.GetErrorMessage();
ret.error_line = parser.error_line();
ret.error_column = parser.error_column();
}
return ret;
}
} // namespace base