summaryrefslogtreecommitdiff
path: root/tools/aapt2/ResourceUtils.cpp
diff options
context:
space:
mode:
author Adam Lesinski <adamlesinski@google.com> 2017-01-16 19:11:19 -0800
committer Adam Lesinski <adamlesinski@google.com> 2017-02-08 06:04:52 -0800
commit929d6517dfd338f0d481dbe6587643d5aef27ec6 (patch)
treeb80a93b93946bd4e982b9f4abd97a4c3aa43feb3 /tools/aapt2/ResourceUtils.cpp
parentc270de85cc0c398d9ce165592908d2740219a708 (diff)
AssetManager2: Add GetResourceId
Add ability to lookup a resource by name. Test: make libandroidfw_tests Change-Id: I262ba5ce4c9892458226fbdb44cf21f9877fb92d
Diffstat (limited to 'tools/aapt2/ResourceUtils.cpp')
-rw-r--r--tools/aapt2/ResourceUtils.cpp36
1 files changed, 6 insertions, 30 deletions
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp
index 11239673272e..150dc58290d4 100644
--- a/tools/aapt2/ResourceUtils.cpp
+++ b/tools/aapt2/ResourceUtils.cpp
@@ -19,6 +19,7 @@
#include <sstream>
#include "androidfw/ResourceTypes.h"
+#include "androidfw/ResourceUtils.h"
#include "NameMangler.h"
#include "SdkConstants.h"
@@ -69,31 +70,6 @@ Maybe<ResourceName> ToResourceName(
return name_out;
}
-bool ExtractResourceName(const StringPiece& str, StringPiece* out_package,
- StringPiece* out_type, StringPiece* out_entry) {
- bool has_package_separator = false;
- bool has_type_separator = false;
- const char* start = str.data();
- const char* end = start + str.size();
- const char* current = start;
- while (current != end) {
- if (out_type->size() == 0 && *current == '/') {
- has_type_separator = true;
- out_type->assign(start, current - start);
- start = current + 1;
- } else if (out_package->size() == 0 && *current == ':') {
- has_package_separator = true;
- out_package->assign(start, current - start);
- start = current + 1;
- }
- current++;
- }
- out_entry->assign(start, end - start);
-
- return !(has_package_separator && out_package->empty()) &&
- !(has_type_separator && out_type->empty());
-}
-
bool ParseResourceName(const StringPiece& str, ResourceNameRef* out_ref,
bool* out_private) {
if (str.empty()) {
@@ -110,8 +86,8 @@ bool ParseResourceName(const StringPiece& str, ResourceNameRef* out_ref,
StringPiece package;
StringPiece type;
StringPiece entry;
- if (!ExtractResourceName(str.substr(offset, str.size() - offset), &package,
- &type, &entry)) {
+ if (!android::ExtractResourceName(str.substr(offset, str.size() - offset), &package, &type,
+ &entry)) {
return false;
}
@@ -197,8 +173,8 @@ bool ParseAttributeReference(const StringPiece& str, ResourceNameRef* out_ref) {
StringPiece package;
StringPiece type;
StringPiece entry;
- if (!ExtractResourceName(trimmed_str.substr(1, trimmed_str.size() - 1),
- &package, &type, &entry)) {
+ if (!android::ExtractResourceName(trimmed_str.substr(1, trimmed_str.size() - 1), &package,
+ &type, &entry)) {
return false;
}
@@ -258,7 +234,7 @@ Maybe<Reference> ParseStyleParentReference(const StringPiece& str,
ref.type = ResourceType::kStyle;
StringPiece type_str;
- ExtractResourceName(name, &ref.package, &type_str, &ref.entry);
+ android::ExtractResourceName(name, &ref.package, &type_str, &ref.entry);
if (!type_str.empty()) {
// If we have a type, make sure it is a Style.
const ResourceType* parsed_type = ParseResourceType(type_str);