OLD | NEW |
---|---|
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 Loading... | |
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 bool XmlDictReader::Read() { | |
103 if (reader_->NodeName() != "dict") | |
104 return false; | |
105 | |
106 int dict_content_depth = reader_->Depth() + 1; | |
107 // Advance past the dict node and into the body of the dictionary. | |
108 if (!reader_->Read()) | |
109 return false; | |
110 | |
111 while (reader_->Depth() >= dict_content_depth && ShouldLoop()) { | |
112 if (!iapps::SeekToNodeAtCurrentDepth(reader_, "key")) | |
113 break; | |
114 std::string found_key; | |
115 if (!reader_->ReadElementContent(&found_key)) | |
116 break; | |
117 DCHECK_EQ(dict_content_depth, reader_->Depth()); | |
118 | |
119 if (Found(found_key) && AllowRepeats()) | |
120 continue; | |
121 | |
122 if (!HandleKey(found_key)) | |
123 break; | |
124 } | |
125 // Seek to the end of the dictionary. | |
126 // Bail on end or error. | |
127 while (reader_->Depth() >= dict_content_depth && reader_->Next()) | |
Lei Zhang
2014/08/05 19:38:24
while (...) {}, rather than the semi-colon on the
Kevin Bailey
2014/08/05 21:52:05
Done.
| |
128 ; | |
129 return FinishedOk(); | |
130 } | |
131 | |
132 bool XmlDictReader::ShouldLoop() { | |
133 return true; | |
134 } | |
135 | |
136 bool XmlDictReader::SkipToNext() { | |
137 return SkipToNextElement(reader_) && reader_->Next(); | |
138 } | |
139 | |
140 bool XmlDictReader::FinishedOk() { | |
141 return true; | |
142 } | |
143 | |
144 bool XmlDictReader::AllowRepeats() { | |
145 return false; | |
146 } | |
147 | |
148 XmlDictReader::~XmlDictReader() { | |
149 } | |
150 | |
100 } // namespace iapps | 151 } // namespace iapps |
OLD | NEW |