summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceUtils.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2016-06-01 15:31:50 -0700
committerAdam Lesinski <adamlesinski@google.com>2016-07-25 16:02:18 -0700
commitbf0bd0f9ac1ffa0231cff0f6591dede48b3c6d52 (patch)
treefa0def8a1f754872ce6b912e30b7badc6470e208 /tools/aapt2/ResourceUtils.cpp
parentef556916aa75ae5e992b7c92345dc1011899a660 (diff)
AAPT2: Add support to specify stable IDs
The --stable-ids flag allows the user to specify a file containing a list of resource name and resource ID pairs in the form of: package:type/name = 0xPPTTEEEE This assigns the given resource the specified ID. It helps ensure that when adding or removing resources, IDs are assigned in a stable fashion. If a package, type, or name is not found, no error or warning is raised. Change-Id: Ibc2f4e05cc924be255fedd862d835cb5b18d7584
Diffstat (limited to 'tools/aapt2/ResourceUtils.cpp')
-rw-r--r--tools/aapt2/ResourceUtils.cpp16
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp
index 31d6435a6184..7dc88dedc96e 100644
--- a/tools/aapt2/ResourceUtils.cpp
+++ b/tools/aapt2/ResourceUtils.cpp
@@ -436,6 +436,22 @@ bool tryParseBool(const StringPiece& str, bool* outValue) {
return false;
}
+Maybe<ResourceId> tryParseResourceId(const StringPiece& str) {
+ StringPiece trimmedStr(util::trimWhitespace(str));
+
+ std::u16string str16 = util::utf8ToUtf16(trimmedStr);
+ android::Res_value value;
+ if (android::ResTable::stringToInt(str16.data(), str16.size(), &value)) {
+ if (value.dataType == android::Res_value::TYPE_INT_HEX) {
+ ResourceId id(value.data);
+ if (id.isValid()) {
+ return id;
+ }
+ }
+ }
+ return {};
+}
+
Maybe<int> tryParseSdkVersion(const StringPiece& str) {
StringPiece trimmedStr(util::trimWhitespace(str));