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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/utility/media_galleries/iapps_xml_utils.cc
diff --git a/chrome/utility/media_galleries/iapps_xml_utils.cc b/chrome/utility/media_galleries/iapps_xml_utils.cc
index 987b6c193ecd7f1618b64840cb7773a65b3f1bf6..aed0ae92406b8cc6470990f7b104a12f3e275cd2 100644
--- a/chrome/utility/media_galleries/iapps_xml_utils.cc
+++ b/chrome/utility/media_galleries/iapps_xml_utils.cc
@@ -97,4 +97,64 @@ std::string ReadFileAsString(base::File file) {
return result;
}
+XmlDictReader::XmlDictReader(XmlReader* reader) : reader_(reader) {}
+
+XmlDictReader::~XmlDictReader() {}
+
+bool XmlDictReader::Read() {
+ if (reader_->NodeName() != "dict")
+ return false;
+
+ int dict_content_depth = reader_->Depth() + 1;
+ // Advance past the dict node and into the body of the dictionary.
+ if (!reader_->Read())
+ return false;
+
+ while (reader_->Depth() >= dict_content_depth && ShouldLoop()) {
+ if (!iapps::SeekToNodeAtCurrentDepth(reader_, "key"))
+ break;
+ std::string found_key;
+ if (!reader_->ReadElementContent(&found_key))
+ break;
+ DCHECK_EQ(dict_content_depth, reader_->Depth());
+
+ if (!HandleKey(found_key))
+ break;
+ }
+ // Seek to the end of the dictionary. Bail on end or error.
+ while (reader_->Depth() >= dict_content_depth && reader_->Next()) {
+ }
+ return FinishedOk();
+}
+
+bool XmlDictReader::ShouldLoop() {
+ return true;
+}
+
+bool XmlDictReader::HandleKey(const std::string& key) {
+ if (Found(key))
+ return AllowRepeats();
+ if (HandleKeyImpl(key)) {
+ found_.insert(key);
+ return true;
+ }
+ return false;
+}
+
+bool XmlDictReader::AllowRepeats() {
+ return false;
+}
+
+bool XmlDictReader::FinishedOk() {
+ return true;
+}
+
+bool XmlDictReader::SkipToNext() {
+ return SkipToNextElement(reader_) && reader_->Next();
+}
+
+bool XmlDictReader::Found(const std::string& key) const {
+ return ContainsKey(found_, key);
+}
+
} // namespace iapps
« 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