diff options
author | Adam Lesinski <adamlesinski@google.com> | 2018-02-23 16:18:10 -0800 |
---|---|---|
committer | Adam Lesinski <adamlesinski@google.com> | 2018-03-01 11:18:23 -0800 |
commit | 34a1687a67cfc08dd2baca6e92180e0930006c6f (patch) | |
tree | 5f2d9f08a58c44faab6377bf02dc412dbf18daf3 /tools/aapt2/ResourceTable.cpp | |
parent | c2c1d7094b9b4d22d99c62df234054b37548092b (diff) |
AAPT2: Remove resources that define locales but no default values.
According to our docs:
https://developer.android.com/guide/topics/resources/localization.html#defaults-r-important
Some resources *require* that there is a default definition. So far,
the pain is felt when doing translations for strings that have been
renamed, etc.
This CL strips out resources that don't have a default value and define
a resource for a locale. This is conservative, but should be expanded
to other configuration properties moving forward.
Bug: 36572857
Test: make aapt2_tests
Change-Id: Ife94a1f8a2ee221f8532ffa856541a9c8c4e7143
Diffstat (limited to 'tools/aapt2/ResourceTable.cpp')
-rw-r--r-- | tools/aapt2/ResourceTable.cpp | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/tools/aapt2/ResourceTable.cpp b/tools/aapt2/ResourceTable.cpp index 95bf9210ba97..d0faac30425a 100644 --- a/tools/aapt2/ResourceTable.cpp +++ b/tools/aapt2/ResourceTable.cpp @@ -162,7 +162,7 @@ struct ConfigKey { const StringPiece& product; }; -bool ltConfigKeyRef(const std::unique_ptr<ResourceConfigValue>& lhs, const ConfigKey& rhs) { +bool lt_config_key_ref(const std::unique_ptr<ResourceConfigValue>& lhs, const ConfigKey& rhs) { int cmp = lhs->config.compare(*rhs.config); if (cmp == 0) { cmp = StringPiece(lhs->product).compare(rhs.product); @@ -172,8 +172,8 @@ bool ltConfigKeyRef(const std::unique_ptr<ResourceConfigValue>& lhs, const Confi ResourceConfigValue* ResourceEntry::FindValue(const ConfigDescription& config, const StringPiece& product) { - auto iter = - std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product}, ltConfigKeyRef); + auto iter = std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product}, + lt_config_key_ref); if (iter != values.end()) { ResourceConfigValue* value = iter->get(); if (value->config == config && StringPiece(value->product) == product) { @@ -185,8 +185,8 @@ ResourceConfigValue* ResourceEntry::FindValue(const ConfigDescription& config, ResourceConfigValue* ResourceEntry::FindOrCreateValue(const ConfigDescription& config, const StringPiece& product) { - auto iter = - std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product}, ltConfigKeyRef); + auto iter = std::lower_bound(values.begin(), values.end(), ConfigKey{&config, product}, + lt_config_key_ref); if (iter != values.end()) { ResourceConfigValue* value = iter->get(); if (value->config == config && StringPiece(value->product) == product) { @@ -220,15 +220,16 @@ std::vector<ResourceConfigValue*> ResourceEntry::FindAllValues(const ConfigDescr return results; } -std::vector<ResourceConfigValue*> ResourceEntry::FindValuesIf( - const std::function<bool(ResourceConfigValue*)>& f) { - std::vector<ResourceConfigValue*> results; - for (auto& configValue : values) { - if (f(configValue.get())) { - results.push_back(configValue.get()); +bool ResourceEntry::HasDefaultValue() const { + const ConfigDescription& default_config = ConfigDescription::DefaultConfig(); + + // The default config should be at the top of the list, since the list is sorted. + for (auto& config_value : values) { + if (config_value->config == default_config) { + return true; } } - return results; + return false; } // The default handler for collisions. |