From 97f0f1e4ea9232e86ee839d5d9e5e6d029f3700c Mon Sep 17 00:00:00 2001 From: Yurii Zubrytskyi Date: Tue, 2 Jul 2024 15:31:01 -0700 Subject: [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 --- tools/aapt2/Debug.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'tools/aapt2/Debug.cpp') diff --git a/tools/aapt2/Debug.cpp b/tools/aapt2/Debug.cpp index 6a17ef85a755..df1d51e37660 100644 --- a/tools/aapt2/Debug.cpp +++ b/tools/aapt2/Debug.cpp @@ -763,10 +763,35 @@ class ChunkPrinter { pool->setTo(chunk, android::util::DeviceToHost32( (reinterpret_cast(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 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"); + } + } + } } } -- cgit v1.2.3-59-g8ed1b