AAPT2: Ensure style strings are always first in StringPool
Move the styled strings to a separate section of the StringPool so
that sorting can never mess up the order of Styles.
Bug: 63570514
Test: make aapt2_tests
Change-Id: Id2ce1355b92be1bb31ce0daa7e54ae9b5b6c2ffe
diff --git a/tools/aapt2/ResourceParser.cpp b/tools/aapt2/ResourceParser.cpp
index 9a37913..a5783a5 100644
--- a/tools/aapt2/ResourceParser.cpp
+++ b/tools/aapt2/ResourceParser.cpp
@@ -268,8 +268,7 @@
continue;
}
- if (!parser->element_namespace().empty() ||
- parser->element_name() != "resources") {
+ if (!parser->element_namespace().empty() || parser->element_name() != "resources") {
diag_->Error(DiagMessage(source_.WithLine(parser->line_number()))
<< "root element must be <resources>");
return false;
@@ -328,8 +327,7 @@
parsed_resource.comment = std::move(comment);
// Extract the product name if it exists.
- if (Maybe<StringPiece> maybe_product =
- xml::FindNonEmptyAttribute(parser, "product")) {
+ if (Maybe<StringPiece> maybe_product = xml::FindNonEmptyAttribute(parser, "product")) {
parsed_resource.product = maybe_product.value().to_string();
}
@@ -348,10 +346,8 @@
for (const ResourceName& stripped_resource : stripped_resources) {
if (!table_->FindResource(stripped_resource)) {
// Failed to find the resource.
- diag_->Error(DiagMessage(source_)
- << "resource '" << stripped_resource
- << "' "
- "was filtered out but no product variant remains");
+ diag_->Error(DiagMessage(source_) << "resource '" << stripped_resource
+ << "' was filtered out but no product variant remains");
error = true;
}
}
@@ -589,7 +585,7 @@
// This can only be a StyledString.
std::unique_ptr<StyledString> styled_string =
util::make_unique<StyledString>(table_->string_pool.MakeRef(
- style_string, StringPool::Context(StringPool::Context::kStylePriority, config_)));
+ style_string, StringPool::Context(StringPool::Context::kNormalPriority, config_)));
styled_string->untranslatable_sections = std::move(untranslatable_sections);
return std::move(styled_string);
}