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

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

Issue 436293002: Created helper class for parsing Apple style XML dictionaries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Converted IPhotoLibraryParser 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 #ifndef CHROME_UTILITY_MEDIA_GALLERIES_IAPPS_XML_UTILS_H_ 5 #ifndef CHROME_UTILITY_MEDIA_GALLERIES_IAPPS_XML_UTILS_H_
6 #define CHROME_UTILITY_MEDIA_GALLERIES_IAPPS_XML_UTILS_H_ 6 #define CHROME_UTILITY_MEDIA_GALLERIES_IAPPS_XML_UTILS_H_
7 7
8 #include <set>
8 #include <string> 9 #include <string>
9 10
10 #include "base/files/file.h" 11 #include "base/files/file.h"
11 12
12 class XmlReader; 13 class XmlReader;
13 14
14 namespace iapps { 15 namespace iapps {
15 16
16 // Like XmlReader::SkipToElement, but will advance to the next open tag if the 17 // Like XmlReader::SkipToElement, but will advance to the next open tag if the
17 // cursor is on a close tag. 18 // cursor is on a close tag.
18 bool SkipToNextElement(XmlReader* reader); 19 bool SkipToNextElement(XmlReader* reader);
19 20
20 // Traverse |reader| looking for a node named |name| at the current depth 21 // Traverse |reader| looking for a node named |name| at the current depth
21 // of |reader|. 22 // of |reader|.
22 bool SeekToNodeAtCurrentDepth(XmlReader* reader, const std::string& name); 23 bool SeekToNodeAtCurrentDepth(XmlReader* reader, const std::string& name);
23 24
24 // Search within a "dict" node for |key|. The cursor must be on the starting 25 // Search within a "dict" node for |key|. The cursor must be on the starting
25 // "dict" node when entering this function. 26 // "dict" node when entering this function.
26 bool SeekInDict(XmlReader* reader, const std::string& key); 27 bool SeekInDict(XmlReader* reader, const std::string& key);
27 28
28 // Get the value out of a string node. 29 // Get the value out of a string node.
29 bool ReadString(XmlReader* reader, std::string* result); 30 bool ReadString(XmlReader* reader, std::string* result);
30 31
31 // Get the value out of an integer node. 32 // Get the value out of an integer node.
32 bool ReadInteger(XmlReader* reader, uint64* result); 33 bool ReadInteger(XmlReader* reader, uint64* result);
33 34
34 // Read in the contents of the given library xml |file| and return as a string. 35 // Read in the contents of the given library xml |file| and return as a string.
35 std::string ReadFileAsString(base::File file); 36 std::string ReadFileAsString(base::File file);
36 37
38 class XmlDictReader {
Lei Zhang 2014/08/05 19:38:24 This class can use some comments.
Kevin Bailey 2014/08/05 21:52:05 Done.
39 public:
40 XmlDictReader(XmlReader* reader);
Lei Zhang 2014/08/05 19:38:24 explicit
Kevin Bailey 2014/08/05 21:52:05 Done.
41
42 bool Read();
43
44 virtual bool ShouldLoop();
45
46 bool HandleKey(const std::string& key) {
Lei Zhang 2014/08/05 19:38:24 please put non-trivial impls in the .cc files.
Kevin Bailey 2014/08/05 21:52:05 Done.
47 if (found_.find(key) != found_.end())
Lei Zhang 2014/08/05 19:38:24 Just call Found()?
Kevin Bailey 2014/08/05 21:52:05 Done.
48 return false;
49 if (HandleKeyImpl(key)) {
50 found_.insert(key);
51 return true;
52 }
53 return false;
54 }
55
56 virtual bool HandleKeyImpl(const std::string& key) = 0;
57
58 bool SkipToNext();
59
60 virtual bool FinishedOk();
61 virtual bool AllowRepeats();
62
63 bool Found(const std::string& key) {
64 return found_.find(key) != found_.end();
Lei Zhang 2014/08/05 19:38:24 You can use ContainsKey() from base/stl_util.h.
Kevin Bailey 2014/08/05 21:52:05 Done.
65 }
66
67 virtual ~XmlDictReader();
Lei Zhang 2014/08/05 19:38:24 Put the dtor next to the ctor?
Kevin Bailey 2014/08/05 21:52:05 Done.
68
69 protected:
70 XmlReader* reader_;
71
72 private:
73 std::set<std::string> found_;
74 };
Lei Zhang 2014/08/05 19:38:24 DISALLOW_COPY_AND_ASSIGN(XmlDictReader);
Kevin Bailey 2014/08/05 21:52:05 Done.
75
37 } // namespace iapps 76 } // namespace iapps
38 77
39 #endif // CHROME_UTILITY_MEDIA_GALLERIES_IAPPS_XML_UTILS_H_ 78 #endif // CHROME_UTILITY_MEDIA_GALLERIES_IAPPS_XML_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/utility/media_galleries/iapps_xml_utils.cc » ('j') | chrome/utility/media_galleries/iapps_xml_utils.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698