summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceUtils.cpp
diff options
context:
space:
mode:
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));