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 ScopedXmlPullParser(XmlPullParser * parser)23ScopedXmlPullParser::ScopedXmlPullParser(XmlPullParser* parser) : 24 mParser(parser), mDepth(parser->getDepth()), mDone(false) { 25 } 26 ~ScopedXmlPullParser()27ScopedXmlPullParser::~ScopedXmlPullParser() { 28 while (isGoodEvent(next())); 29 } 30 next()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 getEvent() const43XmlPullParser::Event ScopedXmlPullParser::getEvent() const { 44 return mParser->getEvent(); 45 } 46 getLastError() const47const std::string& ScopedXmlPullParser::getLastError() const { 48 return mParser->getLastError(); 49 } 50 getComment() const51const std::u16string& ScopedXmlPullParser::getComment() const { 52 return mParser->getComment(); 53 } 54 getLineNumber() const55size_t ScopedXmlPullParser::getLineNumber() const { 56 return mParser->getLineNumber(); 57 } 58 getDepth() const59size_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 getText() const67const std::u16string& ScopedXmlPullParser::getText() const { 68 return mParser->getText(); 69 } 70 getNamespacePrefix() const71const std::u16string& ScopedXmlPullParser::getNamespacePrefix() const { 72 return mParser->getNamespacePrefix(); 73 } 74 getNamespaceUri() const75const std::u16string& ScopedXmlPullParser::getNamespaceUri() const { 76 return mParser->getNamespaceUri(); 77 } 78 applyPackageAlias(std::u16string * package,const std::u16string & defaultPackage) const79bool ScopedXmlPullParser::applyPackageAlias(std::u16string* package, 80 const std::u16string& defaultPackage) const { 81 return mParser->applyPackageAlias(package, defaultPackage); 82 } 83 getElementNamespace() const84const std::u16string& ScopedXmlPullParser::getElementNamespace() const { 85 return mParser->getElementNamespace(); 86 } 87 getElementName() const88const std::u16string& ScopedXmlPullParser::getElementName() const { 89 return mParser->getElementName(); 90 } 91 getAttributeCount() const92size_t ScopedXmlPullParser::getAttributeCount() const { 93 return mParser->getAttributeCount(); 94 } 95 beginAttributes() const96XmlPullParser::const_iterator ScopedXmlPullParser::beginAttributes() const { 97 return mParser->beginAttributes(); 98 } 99 endAttributes() const100XmlPullParser::const_iterator ScopedXmlPullParser::endAttributes() const { 101 return mParser->endAttributes(); 102 } 103 104 } // namespace aapt 105