summaryrefslogtreecommitdiff
path: root/cmds/idmap2/libidmap2/XmlParser.cpp
diff options
context:
space:
mode:
authorScott Lobdell <slobdell@google.com>2021-02-23 11:55:26 -0800
committerDaniel Norman <danielnorman@google.com>2021-03-01 15:24:51 -0800
commit24818fca475a6726f5ef0cae42149615079af6e9 (patch)
tree1a3163ac7ce01c335d8d1c05cacddf47c0a30bfd /cmds/idmap2/libidmap2/XmlParser.cpp
parent8deb6bda58c7ecd95285f4dc934269e0c98c989a (diff)
parent0f50c486e59546c32acf3f2cdf6667897600de5c (diff)
Merge SP1A.210222.001
Change-Id: If3509f3a660e820f4c8c0b29e007faa868e1f089
Diffstat (limited to 'cmds/idmap2/libidmap2/XmlParser.cpp')
-rw-r--r--cmds/idmap2/libidmap2/XmlParser.cpp18
1 files changed, 8 insertions, 10 deletions
diff --git a/cmds/idmap2/libidmap2/XmlParser.cpp b/cmds/idmap2/libidmap2/XmlParser.cpp
index 00baea46f909..70822c890288 100644
--- a/cmds/idmap2/libidmap2/XmlParser.cpp
+++ b/cmds/idmap2/libidmap2/XmlParser.cpp
@@ -151,16 +151,18 @@ Result<std::string> XmlParser::Node::GetAttributeStringValue(const std::string&
return value ? GetStringValue(parser_, *value, name) : value.GetError();
}
-Result<std::unique_ptr<const XmlParser>> XmlParser::Create(const void* data, size_t size,
- bool copy_data) {
- auto parser = std::unique_ptr<const XmlParser>(new XmlParser());
- if (parser->tree_.setTo(data, size, copy_data) != NO_ERROR) {
+XmlParser::XmlParser(std::unique_ptr<ResXMLTree> tree) : tree_(std::move(tree)) {
+}
+
+Result<XmlParser> XmlParser::Create(const void* data, size_t size, bool copy_data) {
+ auto tree = std::make_unique<ResXMLTree>();
+ if (tree->setTo(data, size, copy_data) != NO_ERROR) {
return Error("Malformed xml block");
}
// Find the beginning of the first tag.
XmlParser::Event event;
- while ((event = parser->tree_.next()) != XmlParser::Event::BAD_DOCUMENT &&
+ while ((event = tree->next()) != XmlParser::Event::BAD_DOCUMENT &&
event != XmlParser::Event::END_DOCUMENT && event != XmlParser::Event::START_TAG) {
}
@@ -172,11 +174,7 @@ Result<std::unique_ptr<const XmlParser>> XmlParser::Create(const void* data, siz
return Error("Bad xml document");
}
- return parser;
-}
-
-XmlParser::~XmlParser() {
- tree_.uninit();
+ return XmlParser{std::move(tree)};
}
} // namespace android::idmap2