AssetManager2: Add GetResourceId
Add ability to lookup a resource by name.
Test: make libandroidfw_tests
Change-Id: I262ba5ce4c9892458226fbdb44cf21f9877fb92d
diff --git a/tools/aapt2/ResourceUtils.cpp b/tools/aapt2/ResourceUtils.cpp
index 1123967..150dc58 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 @@
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 @@
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 @@
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 @@
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);
diff --git a/tools/aapt2/ResourceUtils.h b/tools/aapt2/ResourceUtils.h
index bd3a8e3..59b78f4 100644
--- a/tools/aapt2/ResourceUtils.h
+++ b/tools/aapt2/ResourceUtils.h
@@ -29,18 +29,6 @@
namespace aapt {
namespace ResourceUtils {
-/*
- * Extracts the package, type, and name from a string of the format:
- *
- * [package:]type/name
- *
- * where the package can be empty. Validation must be performed on each
- * individual extracted piece to verify that the pieces are valid.
- * Returns false if there was no package but a ':' was present.
- */
-bool ExtractResourceName(const android::StringPiece& str, android::StringPiece* out_package,
- android::StringPiece* out_type, android::StringPiece* out_entry);
-
/**
* Returns true if the string was parsed as a resource name
* ([*][package:]type/name), with