AAPT2: Fix pseudolocalization to respect <xliff:g>
The XLIFF 'g' tag specifies content that should NOT be translated.
AAPT2's pseudolocalization process should respect it.
Bug:34064599
Test: make libandroidfw_tests
Change-Id: Ice437d7f0ff246730ee04896fd035e2d846148fb
diff --git a/tools/aapt2/ResourceValues.cpp b/tools/aapt2/ResourceValues.cpp
index 7956ad8..f75ed7a 100644
--- a/tools/aapt2/ResourceValues.cpp
+++ b/tools/aapt2/ResourceValues.cpp
@@ -140,7 +140,23 @@
if (!other) {
return false;
}
- return *this->value == *other->value;
+
+ if (this->value != other->value) {
+ return false;
+ }
+
+ if (untranslatable_sections.size() != other->untranslatable_sections.size()) {
+ return false;
+ }
+
+ auto other_iter = other->untranslatable_sections.begin();
+ for (const UntranslatableSection& this_section : untranslatable_sections) {
+ if (this_section != *other_iter) {
+ return false;
+ }
+ ++other_iter;
+ }
+ return true;
}
bool String::Flatten(android::Res_value* out_value) const {
@@ -158,6 +174,7 @@
String* str = new String(new_pool->MakeRef(*value));
str->comment_ = comment_;
str->source_ = source_;
+ str->untranslatable_sections = untranslatable_sections;
return str;
}
@@ -173,17 +190,22 @@
return false;
}
- if (*this->value->str == *other->value->str) {
- const std::vector<StringPool::Span>& spans_a = this->value->spans;
- const std::vector<StringPool::Span>& spans_b = other->value->spans;
- return std::equal(
- spans_a.begin(), spans_a.end(), spans_b.begin(),
- [](const StringPool::Span& a, const StringPool::Span& b) -> bool {
- return *a.name == *b.name && a.first_char == b.first_char &&
- a.last_char == b.last_char;
- });
+ if (this->value != other->value) {
+ return false;
}
- return false;
+
+ if (untranslatable_sections.size() != other->untranslatable_sections.size()) {
+ return false;
+ }
+
+ auto other_iter = other->untranslatable_sections.begin();
+ for (const UntranslatableSection& this_section : untranslatable_sections) {
+ if (this_section != *other_iter) {
+ return false;
+ }
+ ++other_iter;
+ }
+ return true;
}
bool StyledString::Flatten(android::Res_value* out_value) const {
@@ -200,6 +222,7 @@
StyledString* str = new StyledString(new_pool->MakeRef(value));
str->comment_ = comment_;
str->source_ = source_;
+ str->untranslatable_sections = untranslatable_sections;
return str;
}
@@ -218,7 +241,7 @@
if (!other) {
return false;
}
- return *path == *other->path;
+ return path == other->path;
}
bool FileReference::Flatten(android::Res_value* out_value) const {