OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/media_galleries/fileapi/itunes_xml_utils.h" |
| 6 #include <string> |
| 7 |
| 8 #include "base/logging.h" |
| 9 #include "third_party/libxml/chromium/libxml_utils.h" |
| 10 |
| 11 namespace itunes { |
| 12 |
| 13 bool SkipToNextElement(XmlReader* reader) { |
| 14 if (!reader->SkipToElement()) { |
| 15 // SkipToElement returns false if the current node is an end element, |
| 16 // try to advance to the next element and then try again. |
| 17 if (!reader->Read() || !reader->SkipToElement()) |
| 18 return false; |
| 19 } |
| 20 return true; |
| 21 } |
| 22 |
| 23 bool SeekToNodeAtCurrentDepth(XmlReader* reader, const std::string& name) { |
| 24 int depth = reader->Depth(); |
| 25 do { |
| 26 if (!SkipToNextElement(reader)) |
| 27 return false; |
| 28 DCHECK_EQ(depth, reader->Depth()); |
| 29 if (reader->NodeName() == name) |
| 30 return true; |
| 31 } while (reader->Next()); |
| 32 |
| 33 return false; |
| 34 } |
| 35 |
| 36 bool SeekInDict(XmlReader* reader, const std::string& key) { |
| 37 DCHECK_EQ("dict", reader->NodeName()); |
| 38 |
| 39 int dict_content_depth = reader->Depth() + 1; |
| 40 // Advance past the dict node and into the body of the dictionary. |
| 41 if (!reader->Read()) |
| 42 return false; |
| 43 |
| 44 while (reader->Depth() >= dict_content_depth) { |
| 45 if (!SeekToNodeAtCurrentDepth(reader, "key")) |
| 46 return false; |
| 47 std::string found_key; |
| 48 if (!reader->ReadElementContent(&found_key)) |
| 49 return false; |
| 50 DCHECK_EQ(dict_content_depth, reader->Depth()); |
| 51 if (found_key == key) |
| 52 return true; |
| 53 } |
| 54 return false; |
| 55 } |
| 56 |
| 57 } // namespace itunes |
OLD | NEW |