Adam Lesinski | 6f6ceb7 | 2014-11-14 14:48:12 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef AAPT_SOURCE_XML_PULL_PARSER_H |
| 18 | #define AAPT_SOURCE_XML_PULL_PARSER_H |
| 19 | |
| 20 | #include <istream> |
| 21 | #include <libexpat/expat.h> |
| 22 | #include <queue> |
| 23 | #include <stack> |
| 24 | #include <string> |
| 25 | #include <vector> |
| 26 | |
| 27 | #include "XmlPullParser.h" |
| 28 | |
| 29 | namespace aapt { |
| 30 | |
| 31 | class SourceXmlPullParser : public XmlPullParser { |
| 32 | public: |
| 33 | SourceXmlPullParser(std::istream& in); |
| 34 | SourceXmlPullParser(const SourceXmlPullParser& rhs) = delete; |
| 35 | ~SourceXmlPullParser(); |
| 36 | |
| 37 | Event getEvent() const; |
| 38 | const std::string& getLastError() const; |
| 39 | Event next(); |
| 40 | |
| 41 | const std::u16string& getComment() const; |
| 42 | size_t getLineNumber() const; |
| 43 | size_t getDepth() const; |
| 44 | |
| 45 | const std::u16string& getText() const; |
| 46 | |
| 47 | const std::u16string& getNamespacePrefix() const; |
| 48 | const std::u16string& getNamespaceUri() const; |
| 49 | |
| 50 | const std::u16string& getElementNamespace() const; |
| 51 | const std::u16string& getElementName() const; |
| 52 | |
| 53 | const_iterator beginAttributes() const; |
| 54 | const_iterator endAttributes() const; |
| 55 | size_t getAttributeCount() const; |
| 56 | |
| 57 | private: |
| 58 | static void XMLCALL startNamespaceHandler(void* userData, const char* prefix, const char* uri); |
| 59 | static void XMLCALL startElementHandler(void* userData, const char* name, const char** attrs); |
| 60 | static void XMLCALL characterDataHandler(void* userData, const char* s, int len); |
| 61 | static void XMLCALL endElementHandler(void* userData, const char* name); |
| 62 | static void XMLCALL endNamespaceHandler(void* userData, const char* prefix); |
| 63 | static void XMLCALL commentDataHandler(void* userData, const char* comment); |
| 64 | |
| 65 | struct EventData { |
| 66 | Event event; |
| 67 | size_t lineNumber; |
| 68 | size_t depth; |
| 69 | std::u16string data1; |
| 70 | std::u16string data2; |
| 71 | std::u16string comment; |
| 72 | std::vector<Attribute> attributes; |
| 73 | }; |
| 74 | |
| 75 | std::istream& mIn; |
| 76 | XML_Parser mParser; |
| 77 | char mBuffer[16384]; |
| 78 | std::queue<EventData> mEventQueue; |
| 79 | std::string mLastError; |
| 80 | const std::u16string mEmpty; |
| 81 | size_t mDepth; |
| 82 | std::stack<std::u16string> mNamespaceUris; |
| 83 | }; |
| 84 | |
| 85 | } // namespace aapt |
| 86 | |
| 87 | #endif // AAPT_SOURCE_XML_PULL_PARSER_H |