From 8f7c550e20a6edbc9af7bb48675afaf8bcb3783f Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Thu, 2 Mar 2017 17:45:01 -0800 Subject: AAPT2: Fix Plural::Equals() method Test: make aapt2_tests Bug: 35902437 Change-Id: I8797f89af58876f891f0b0c5cce85fd7781c4e24 --- tools/aapt2/ResourceValues.cpp | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) (limited to 'tools/aapt2/ResourceValues.cpp') diff --git a/tools/aapt2/ResourceValues.cpp b/tools/aapt2/ResourceValues.cpp index 2868b2acee2d..0cb8c67705f9 100644 --- a/tools/aapt2/ResourceValues.cpp +++ b/tools/aapt2/ResourceValues.cpp @@ -341,7 +341,7 @@ Attribute::Attribute(bool w, uint32_t t) } template -T* addPointer(T& val) { +constexpr T* add_pointer(T& val) { return &val; } @@ -362,7 +362,7 @@ bool Attribute::Equals(const Value* value) const { std::vector sorted_a; std::transform(symbols.begin(), symbols.end(), std::back_inserter(sorted_a), - addPointer); + add_pointer); std::sort(sorted_a.begin(), sorted_a.end(), [](const Symbol* a, const Symbol* b) -> bool { return a->symbol.name < b->symbol.name; @@ -370,7 +370,7 @@ bool Attribute::Equals(const Value* value) const { std::vector sorted_b; std::transform(other->symbols.begin(), other->symbols.end(), - std::back_inserter(sorted_b), addPointer); + std::back_inserter(sorted_b), add_pointer); std::sort(sorted_b.begin(), sorted_b.end(), [](const Symbol* a, const Symbol* b) -> bool { return a->symbol.name < b->symbol.name; @@ -599,7 +599,7 @@ bool Style::Equals(const Value* value) const { std::vector sorted_a; std::transform(entries.begin(), entries.end(), std::back_inserter(sorted_a), - addPointer); + add_pointer); std::sort(sorted_a.begin(), sorted_a.end(), [](const Entry* a, const Entry* b) -> bool { return a->key.name < b->key.name; @@ -607,7 +607,7 @@ bool Style::Equals(const Value* value) const { std::vector sorted_b; std::transform(other->entries.begin(), other->entries.end(), - std::back_inserter(sorted_b), addPointer); + std::back_inserter(sorted_b), add_pointer); std::sort(sorted_b.begin(), sorted_b.end(), [](const Entry* a, const Entry* b) -> bool { return a->key.name < b->key.name; @@ -695,18 +695,21 @@ bool Plural::Equals(const Value* value) const { return false; } - if (values.size() != other->values.size()) { - return false; + auto one_iter = values.begin(); + auto one_end_iter = values.end(); + auto two_iter = other->values.begin(); + for (; one_iter != one_end_iter; ++one_iter, ++two_iter) { + const std::unique_ptr& a = *one_iter; + const std::unique_ptr& b = *two_iter; + if (a != nullptr && b != nullptr) { + if (!a->Equals(b.get())) { + return false; + } + } else if (a != b) { + return false; + } } - - return std::equal(values.begin(), values.end(), other->values.begin(), - [](const std::unique_ptr& a, - const std::unique_ptr& b) -> bool { - if (bool(a) != bool(b)) { - return false; - } - return bool(a) == bool(b) || a->Equals(b.get()); - }); + return true; } Plural* Plural::Clone(StringPool* new_pool) const { @@ -743,6 +746,10 @@ void Plural::Print(std::ostream* out) const { if (values[Many]) { *out << " many=" << *values[Many]; } + + if (values[Other]) { + *out << " other=" << *values[Other]; + } } static ::std::ostream& operator<<(::std::ostream& out, -- cgit v1.2.3-59-g8ed1b