summaryrefslogtreecommitdiff
path: root/tools/aapt/XMLNode.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2014-09-22 19:45:27 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-09-22 19:45:27 +0000
commitdc03c9f292a93806a30a3a32009ff75ff8d419cc (patch)
treeae22bc693aced61651c28f48efc1ecc520333857 /tools/aapt/XMLNode.cpp
parentc2ece0002baf8731fedddc3f6053ef97863df497 (diff)
parent534b739118b6af4c4f27dc7a2d991f1b7d7c1e88 (diff)
am d4e5b601: am 37e3df38: am 1aa4db07: am 81745c51: Merge "AAPT: Continuation of public/private attribute fix" into lmp-dev
* commit 'd4e5b601c7da5c662d8cf9c46177810fdeeed23f': AAPT: Continuation of public/private attribute fix
Diffstat (limited to 'tools/aapt/XMLNode.cpp')
-rw-r--r--tools/aapt/XMLNode.cpp56
1 files changed, 56 insertions, 0 deletions
diff --git a/tools/aapt/XMLNode.cpp b/tools/aapt/XMLNode.cpp
index 03c66c117415..899fb63e2a4c 100644
--- a/tools/aapt/XMLNode.cpp
+++ b/tools/aapt/XMLNode.cpp
@@ -621,6 +621,12 @@ sp<XMLNode> XMLNode::parse(const sp<AaptFile>& file)
return state.root;
}
+XMLNode::XMLNode()
+ : mNextAttributeIndex(0x80000000)
+ , mStartLineNumber(0)
+ , mEndLineNumber(0)
+ , mUTF8(false) {}
+
XMLNode::XMLNode(const String8& filename, const String16& s1, const String16& s2, bool isNamespace)
: mNextAttributeIndex(0x80000000)
, mFilename(filename)
@@ -810,6 +816,32 @@ status_t XMLNode::addAttribute(const String16& ns, const String16& name,
return NO_ERROR;
}
+status_t XMLNode::removeAttribute(size_t index)
+{
+ if (getType() == TYPE_CDATA) {
+ return UNKNOWN_ERROR;
+ }
+
+ if (index >= mAttributes.size()) {
+ return UNKNOWN_ERROR;
+ }
+
+ const attribute_entry& e = mAttributes[index];
+ const uint32_t key = e.nameResId ? e.nameResId : e.index;
+ mAttributeOrder.removeItem(key);
+ mAttributes.removeAt(index);
+
+ // Shift all the indices.
+ const size_t attrCount = mAttributeOrder.size();
+ for (size_t i = 0; i < attrCount; i++) {
+ size_t attrIdx = mAttributeOrder[i];
+ if (attrIdx > index) {
+ mAttributeOrder.replaceValueAt(i, attrIdx - 1);
+ }
+ }
+ return NO_ERROR;
+}
+
void XMLNode::setAttributeResID(size_t attrIdx, uint32_t resId)
{
attribute_entry& e = mAttributes.editItemAt(attrIdx);
@@ -999,6 +1031,30 @@ status_t XMLNode::assignResourceIds(const sp<AaptAssets>& assets,
return hasErrors ? UNKNOWN_ERROR : NO_ERROR;
}
+sp<XMLNode> XMLNode::clone() const {
+ sp<XMLNode> copy = new XMLNode();
+ copy->mNamespacePrefix = mNamespacePrefix;
+ copy->mNamespaceUri = mNamespaceUri;
+ copy->mElementName = mElementName;
+
+ const size_t childCount = mChildren.size();
+ for (size_t i = 0; i < childCount; i++) {
+ copy->mChildren.add(mChildren[i]->clone());
+ }
+
+ copy->mAttributes = mAttributes;
+ copy->mAttributeOrder = mAttributeOrder;
+ copy->mNextAttributeIndex = mNextAttributeIndex;
+ copy->mChars = mChars;
+ memcpy(&copy->mCharsValue, &mCharsValue, sizeof(mCharsValue));
+ copy->mComment = mComment;
+ copy->mFilename = mFilename;
+ copy->mStartLineNumber = mStartLineNumber;
+ copy->mEndLineNumber = mEndLineNumber;
+ copy->mUTF8 = mUTF8;
+ return copy;
+}
+
status_t XMLNode::flatten(const sp<AaptFile>& dest,
bool stripComments, bool stripRawValues) const
{