blob: d9ae72cf643bc76e76efad016c5a7c24e33f7932 [file] [log] [blame]
Adam Lesinski6f6ceb72014-11-14 14:48:12 -08001/*
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#include "ScopedXmlPullParser.h"
18
19#include <string>
20
21namespace aapt {
22
23ScopedXmlPullParser::ScopedXmlPullParser(XmlPullParser* parser) :
24 mParser(parser), mDepth(parser->getDepth()), mDone(false) {
25}
26
27ScopedXmlPullParser::~ScopedXmlPullParser() {
28 while (isGoodEvent(next()));
29}
30
31XmlPullParser::Event ScopedXmlPullParser::next() {
32 if (mDone) {
33 return Event::kEndDocument;
34 }
35
36 const Event event = mParser->next();
37 if (mParser->getDepth() <= mDepth) {
38 mDone = true;
39 }
40 return event;
41}
42
43XmlPullParser::Event ScopedXmlPullParser::getEvent() const {
44 return mParser->getEvent();
45}
46
47const std::string& ScopedXmlPullParser::getLastError() const {
48 return mParser->getLastError();
49}
50
51const std::u16string& ScopedXmlPullParser::getComment() const {
52 return mParser->getComment();
53}
54
55size_t ScopedXmlPullParser::getLineNumber() const {
56 return mParser->getLineNumber();
57}
58
59size_t ScopedXmlPullParser::getDepth() const {
60 const size_t depth = mParser->getDepth();
61 if (depth < mDepth) {
62 return 0;
63 }
64 return depth - mDepth;
65}
66
67const std::u16string& ScopedXmlPullParser::getText() const {
68 return mParser->getText();
69}
70
71const std::u16string& ScopedXmlPullParser::getNamespacePrefix() const {
72 return mParser->getNamespacePrefix();
73}
74
75const std::u16string& ScopedXmlPullParser::getNamespaceUri() const {
76 return mParser->getNamespaceUri();
77}
78
79const std::u16string& ScopedXmlPullParser::getElementNamespace() const {
80 return mParser->getElementNamespace();
81}
82
83const std::u16string& ScopedXmlPullParser::getElementName() const {
84 return mParser->getElementName();
85}
86
87size_t ScopedXmlPullParser::getAttributeCount() const {
88 return mParser->getAttributeCount();
89}
90
91XmlPullParser::const_iterator ScopedXmlPullParser::beginAttributes() const {
92 return mParser->beginAttributes();
93}
94
95XmlPullParser::const_iterator ScopedXmlPullParser::endAttributes() const {
96 return mParser->endAttributes();
97}
98
99} // namespace aapt