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 | #include "ScopedXmlPullParser.h" |
| 18 | |
| 19 | #include <string> |
| 20 | |
| 21 | namespace aapt { |
| 22 | |
| 23 | ScopedXmlPullParser::ScopedXmlPullParser(XmlPullParser* parser) : |
| 24 | mParser(parser), mDepth(parser->getDepth()), mDone(false) { |
| 25 | } |
| 26 | |
| 27 | ScopedXmlPullParser::~ScopedXmlPullParser() { |
| 28 | while (isGoodEvent(next())); |
| 29 | } |
| 30 | |
| 31 | XmlPullParser::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 | |
| 43 | XmlPullParser::Event ScopedXmlPullParser::getEvent() const { |
| 44 | return mParser->getEvent(); |
| 45 | } |
| 46 | |
| 47 | const std::string& ScopedXmlPullParser::getLastError() const { |
| 48 | return mParser->getLastError(); |
| 49 | } |
| 50 | |
| 51 | const std::u16string& ScopedXmlPullParser::getComment() const { |
| 52 | return mParser->getComment(); |
| 53 | } |
| 54 | |
| 55 | size_t ScopedXmlPullParser::getLineNumber() const { |
| 56 | return mParser->getLineNumber(); |
| 57 | } |
| 58 | |
| 59 | size_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 | |
| 67 | const std::u16string& ScopedXmlPullParser::getText() const { |
| 68 | return mParser->getText(); |
| 69 | } |
| 70 | |
| 71 | const std::u16string& ScopedXmlPullParser::getNamespacePrefix() const { |
| 72 | return mParser->getNamespacePrefix(); |
| 73 | } |
| 74 | |
| 75 | const std::u16string& ScopedXmlPullParser::getNamespaceUri() const { |
| 76 | return mParser->getNamespaceUri(); |
| 77 | } |
| 78 | |
| 79 | const std::u16string& ScopedXmlPullParser::getElementNamespace() const { |
| 80 | return mParser->getElementNamespace(); |
| 81 | } |
| 82 | |
| 83 | const std::u16string& ScopedXmlPullParser::getElementName() const { |
| 84 | return mParser->getElementName(); |
| 85 | } |
| 86 | |
| 87 | size_t ScopedXmlPullParser::getAttributeCount() const { |
| 88 | return mParser->getAttributeCount(); |
| 89 | } |
| 90 | |
| 91 | XmlPullParser::const_iterator ScopedXmlPullParser::beginAttributes() const { |
| 92 | return mParser->beginAttributes(); |
| 93 | } |
| 94 | |
| 95 | XmlPullParser::const_iterator ScopedXmlPullParser::endAttributes() const { |
| 96 | return mParser->endAttributes(); |
| 97 | } |
| 98 | |
| 99 | } // namespace aapt |