[aapt2] Improve dump chunks for string pools, fix diff
- `dump chunks` command now prints extra header data for the
string pool, and outputs all style information for styled
strings.
- `diff` command used to only correctly compare the first span
in the StyledString data type, making them appear different
if there was a string with more than one span
Flag: EXEMPT bugfix
Test: atest aapt2_tests
Change-Id: I377718c03d6a464cb4db22399b0f067e6a6e04d6
diff --git a/tools/aapt2/Debug.cpp b/tools/aapt2/Debug.cpp
index 6a17ef8..df1d51e 100644
--- a/tools/aapt2/Debug.cpp
+++ b/tools/aapt2/Debug.cpp
@@ -763,10 +763,35 @@
pool->setTo(chunk, android::util::DeviceToHost32(
(reinterpret_cast<const ResChunk_header*>(chunk))->size));
- printer_->Print("\n");
+ printer_->Print(StringPrintf(" strings: %zd styles %zd flags: %s|%s\n", pool->size(),
+ pool->styleCount(), pool->isUTF8() ? "UTF-8" : "UTF-16",
+ pool->isSorted() ? "SORTED" : "NON-SORTED"));
for (size_t i = 0; i < pool->size(); i++) {
printer_->Print(StringPrintf("#%zd : %s\n", i, android::util::GetString(*pool, i).c_str()));
+ if (i < pool->styleCount()) {
+ printer_->Print(" [Style] ");
+ auto maybe_style = pool->styleAt(i);
+ if (!maybe_style) {
+ printer_->Print("??? missing\n");
+ } else {
+ std::vector<const ResStringPool_span*> spans;
+ for (auto style = maybe_style.value().unsafe_ptr();
+ style->name.index != android::ResStringPool_span::END; ++style) {
+ spans.push_back(style);
+ }
+ printer_->Print(StringPrintf("(%zd)", spans.size()));
+ if (!spans.empty()) {
+ printer_->Print(" :");
+ for (const auto& span : spans) {
+ printer_->Print(StringPrintf(
+ " %s:%u,%u", android::util::GetString(*pool, span->name.index).c_str(),
+ span->firstChar, span->lastChar));
+ }
+ printer_->Print("\n");
+ }
+ }
+ }
}
}