diff options
Diffstat (limited to 'tools/aapt2/ResourceParser.cpp')
| -rw-r--r-- | tools/aapt2/ResourceParser.cpp | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp index e7e824c..13f916b 100644 --- a/tools/aapt2/ResourceParser.cpp +++ b/tools/aapt2/ResourceParser.cpp @@ -193,18 +193,18 @@ std::unique_ptr<Reference> ResourceParser::tryParseReference(const StringPiece16 std::unique_ptr<BinaryPrimitive> ResourceParser::tryParseNullOrEmpty(const StringPiece16& str) { StringPiece16 trimmedStr(util::trimWhitespace(str)); - uint32_t data = 0; + android::Res_value value = {}; if (trimmedStr == u"@null") { - data = android::Res_value::DATA_NULL_UNDEFINED; + // TYPE_NULL with data set to 0 is interpreted by the runtime as an error. + // Instead we set the data type to TYPE_REFERENCE with a value of 0. + value.dataType = android::Res_value::TYPE_REFERENCE; } else if (trimmedStr == u"@empty") { - data = android::Res_value::DATA_NULL_EMPTY; + // TYPE_NULL with value of DATA_NULL_EMPTY is handled fine by the runtime. + value.dataType = android::Res_value::TYPE_NULL; + value.data = android::Res_value::DATA_NULL_EMPTY; } else { return {}; } - - android::Res_value value = {}; - value.dataType = android::Res_value::TYPE_NULL; - value.data = data; return util::make_unique<BinaryPrimitive>(value); } @@ -1163,7 +1163,7 @@ bool ResourceParser::parseUntypedItem(XmlPullParser* parser, Style& style) { bool ResourceParser::parseStyle(XmlPullParser* parser, const ResourceNameRef& resourceName) { const SourceLine source = mSource.line(parser->getLineNumber()); - std::unique_ptr<Style> style = util::make_unique<Style>(false); + std::unique_ptr<Style> style = util::make_unique<Style>(); const auto endAttrIter = parser->endAttributes(); const auto parentAttrIter = parser->findAttribute(u"", u"parent"); @@ -1181,6 +1181,16 @@ bool ResourceParser::parseStyle(XmlPullParser* parser, const ResourceNameRef& re // If no package is specified, this can not be an alias and is the local package. style->parent.name.package = mTable->getPackage(); } + } else { + // No parent was specified, so try inferring it from the style name. + std::u16string styleName = resourceName.entry.toString(); + size_t pos = styleName.find_last_of(u'.'); + if (pos != std::string::npos) { + style->parentInferred = true; + style->parent.name.package = mTable->getPackage(); + style->parent.name.type = ResourceType::kStyle; + style->parent.name.entry = styleName.substr(0, pos); + } } bool success = true; |
