summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceUtils.cpp
diff options
context:
space:
mode:
author TreeHugger Robot <treehugger-gerrit@google.com> 2016-06-30 03:51:17 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2016-06-30 03:51:19 +0000
commitd4e80c6a4b99a24b0cf3a14a42123ec593412a7f (patch)
tree43d4a0f629c9cc9693a72236ff41c3020fa8769f /tools/aapt2/ResourceUtils.cpp
parent4f21575074133c83b8a8c4f871cae7d8553a90dc (diff)
parentfb6312fe93a8544e6a95d1c619c8cea3940cbe1a (diff)
Merge "AAPT2: Add version collapsing"
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 a0a7efc46476..302c04fc3780 100644
--- a/tools/aapt2/ResourceUtils.cpp
+++ b/tools/aapt2/ResourceUtils.cpp
@@ -16,6 +16,7 @@
#include "NameMangler.h"
#include "ResourceUtils.h"
+#include "SdkConstants.h"
#include "flatten/ResourceTypeExtensions.h"
#include "util/Files.h"
#include "util/Util.h"
@@ -402,6 +403,21 @@ bool tryParseBool(const StringPiece16& str, bool* outValue) {
return false;
}
+Maybe<int> tryParseSdkVersion(const StringPiece16& str) {
+ StringPiece16 trimmedStr(util::trimWhitespace(str));
+ android::Res_value value;
+ if (android::ResTable::stringToInt(trimmedStr.data(), trimmedStr.size(), &value)) {
+ return static_cast<int>(value.data);
+ }
+
+ // Try parsing the code name.
+ std::pair<StringPiece16, int> entry = getDevelopmentSdkCodeNameAndVersion();
+ if (entry.first == trimmedStr) {
+ return entry.second;
+ }
+ return {};
+}
+
std::unique_ptr<BinaryPrimitive> tryParseBool(const StringPiece16& str) {
bool result = false;
if (tryParseBool(str, &result)) {