diff options
author | Adam Lesinski <adamlesinski@google.com> | 2017-01-06 15:20:04 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2017-02-08 06:23:45 -0800 |
commit | 7542162cb1b1fd2ce8a26dd7f3fedc8de8160d38 (patch) | |
tree | 0358684e3551d67eb93cb80ae81ef391ba1a9091 /tools/aapt2/ResourceValues.cpp | |
parent | c270de85cc0c398d9ce165592908d2740219a708 (diff) |
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
Diffstat (limited to 'tools/aapt2/ResourceValues.cpp')
-rw-r--r-- | tools/aapt2/ResourceValues.cpp | 47 |
1 files changed, 35 insertions, 12 deletions
diff --git a/tools/aapt2/ResourceValues.cpp b/tools/aapt2/ResourceValues.cpp index 7956ad826acd..f75ed7ad978a 100644 --- a/tools/aapt2/ResourceValues.cpp +++ b/tools/aapt2/ResourceValues.cpp @@ -140,7 +140,23 @@ bool String::Equals(const Value* value) const { 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* String::Clone(StringPool* new_pool) const { 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 @@ bool StyledString::Equals(const Value* value) const { 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; + } + + 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 false; + return true; } bool StyledString::Flatten(android::Res_value* out_value) const { @@ -200,6 +222,7 @@ StyledString* StyledString::Clone(StringPool* new_pool) const { 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 @@ bool FileReference::Equals(const Value* value) const { if (!other) { return false; } - return *path == *other->path; + return path == other->path; } bool FileReference::Flatten(android::Res_value* out_value) const { |