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

Side by Side Diff: chrome/utility/media_galleries/iapps_xml_utils.cc

Issue 436293002: Created helper class for parsing Apple style XML dictionaries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: One more tweak Created 6 years, 4 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/utility/media_galleries/iapps_xml_utils.h" 5 #include "chrome/utility/media_galleries/iapps_xml_utils.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "third_party/libxml/chromium/libxml_utils.h" 10 #include "third_party/libxml/chromium/libxml_utils.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 return result; 90 return result;
91 91
92 result.resize(file_info.size); 92 result.resize(file_info.size);
93 int bytes_read = file.Read(0, string_as_array(&result), file_info.size); 93 int bytes_read = file.Read(0, string_as_array(&result), file_info.size);
94 if (bytes_read != file_info.size) 94 if (bytes_read != file_info.size)
95 result.clear(); 95 result.clear();
96 96
97 return result; 97 return result;
98 } 98 }
99 99
100 XmlDictReader::XmlDictReader(XmlReader* reader) : reader_(reader) {}
101
102 XmlDictReader::~XmlDictReader() {}
103
104 bool XmlDictReader::Read() {
105 if (reader_->NodeName() != "dict")
106 return false;
107
108 int dict_content_depth = reader_->Depth() + 1;
109 // Advance past the dict node and into the body of the dictionary.
110 if (!reader_->Read())
111 return false;
112
113 while (reader_->Depth() >= dict_content_depth && ShouldLoop()) {
114 if (!iapps::SeekToNodeAtCurrentDepth(reader_, "key"))
115 break;
116 std::string found_key;
117 if (!reader_->ReadElementContent(&found_key))
118 break;
119 DCHECK_EQ(dict_content_depth, reader_->Depth());
120
121 if (!HandleKey(found_key))
122 break;
123 }
124 // Seek to the end of the dictionary. Bail on end or error.
125 while (reader_->Depth() >= dict_content_depth && reader_->Next()) {
126 }
127 return FinishedOk();
128 }
129
130 bool XmlDictReader::ShouldLoop() {
131 return true;
132 }
133
134 bool XmlDictReader::HandleKey(const std::string& key) {
135 if (Found(key))
136 return AllowRepeats();
137 if (HandleKeyImpl(key)) {
138 found_.insert(key);
139 return true;
140 }
141 return false;
142 }
143
144 bool XmlDictReader::AllowRepeats() {
145 return false;
146 }
147
148 bool XmlDictReader::FinishedOk() {
149 return true;
150 }
151
152 bool XmlDictReader::SkipToNext() {
153 return SkipToNextElement(reader_) && reader_->Next();
154 }
155
156 bool XmlDictReader::Found(const std::string& key) const {
157 return ContainsKey(found_, key);
158 }
159
100 } // namespace iapps 160 } // namespace iapps
OLDNEW
« no previous file with comments | « chrome/utility/media_galleries/iapps_xml_utils.h ('k') | chrome/utility/media_galleries/iphoto_library_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698