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

Side by Side Diff: third_party/libaddressinput/chromium/cpp/src/util/json.cc

Issue 106863006: [rac] Add AddressValidator API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix typo in comment. Created 7 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (C) 2013 Google Inc. 1 // Copyright (C) 2013 Google Inc.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 15 matching lines...) Expand all
26 26
27 namespace i18n { 27 namespace i18n {
28 namespace addressinput { 28 namespace addressinput {
29 29
30 namespace { 30 namespace {
31 31
32 class Rapidjson : public Json { 32 class Rapidjson : public Json {
33 public: 33 public:
34 Rapidjson() : document_(new rapidjson::Document), valid_(false) {} 34 Rapidjson() : document_(new rapidjson::Document), valid_(false) {}
35 35
36 virtual ~RapidJson() {} 36 virtual ~Rapidjson() {}
37 37
38 virtual bool ParseObject(const std::string& json) { 38 virtual bool ParseObject(const std::string& json) {
39 document_->Parse<rapidjson::kParseValidateEncodingFlag>(json.c_str()); 39 document_->Parse<rapidjson::kParseValidateEncodingFlag>(json.c_str());
40 valid_ = !document_->HasParseError() && document_->IsObject(); 40 valid_ = !document_->HasParseError() && document_->IsObject();
41 return valid_; 41 return valid_;
42 } 42 }
43 43
44 virtual bool HasStringValueForKey(const std::string& key) const { 44 virtual bool HasStringValueForKey(const std::string& key) const {
45 assert(valid_); 45 assert(valid_);
46 const rapidjson::Value::Member* member = document_->FindMember(key.c_str()); 46 const rapidjson::Value::Member* member = document_->FindMember(key.c_str());
47 return member != NULL && member->value.IsString(); 47 return member != NULL && member->value.IsString();
48 } 48 }
49 49
50 virtual std::string GetStringValueForKey(const std::string& key) const { 50 virtual std::string GetStringValueForKey(const std::string& key) const {
51 assert(valid_); 51 assert(valid_);
52 const rapidjson::Value::Member* member = document_->FindMember(key.c_str()); 52 const rapidjson::Value::Member* member = document_->FindMember(key.c_str());
53 assert(member != NULL); 53 assert(member != NULL);
54 assert(member->value.IsString()); 54 assert(member->value.IsString());
55 return std::string(member->value.GetString(), 55 return std::string(member->value.GetString(),
56 member->value.GetStringLength()); 56 member->value.GetStringLength());
57 } 57 }
58 58
59 protected: 59 protected:
60 // JSON document. 60 // JSON document.
61 scoped_ptr<rapidjson::Document> document_; 61 scoped_ptr<rapidjson::Document> document_;
62 62
63 // True if the parsed string is a valid JSON object. 63 // True if the parsed string is a valid JSON object.
64 bool valid_; 64 bool valid_;
65 65
66 DISALLOW_COPY_AND_ASSIGN(Rapidjson); 66 DISALLOW_COPY_AND_ASSIGN(Rapidjson);
67 }; 67 };
68 68
69 } // namespace 69 } // namespace
70 70
71 Json::~Json() {} 71 Json::~Json() {}
72 72
73 // static 73 // static
74 Json* Json::Build() { 74 Json* Json::Build() {
75 return new Rapidjson; 75 return new Rapidjson;
76 } 76 }
77 77
78 Json::Json() {} 78 Json::Json() {}
79 79
80 } // namespace addressinput 80 } // namespace addressinput
81 } // namespace i18n 81 } // namespace i18n
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698