diff options
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 |
commit | 929d6517dfd338f0d481dbe6587643d5aef27ec6 (patch) | |
tree | b80a93b93946bd4e982b9f4abd97a4c3aa43feb3 /libs/androidfw/ResourceUtils.cpp | |
parent | c270de85cc0c398d9ce165592908d2740219a708 (diff) |
AssetManager2: Add GetResourceId
Add ability to lookup a resource by name.
Test: make libandroidfw_tests
Change-Id: I262ba5ce4c9892458226fbdb44cf21f9877fb92d
Diffstat (limited to 'libs/androidfw/ResourceUtils.cpp')
-rw-r--r-- | libs/androidfw/ResourceUtils.cpp | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/libs/androidfw/ResourceUtils.cpp b/libs/androidfw/ResourceUtils.cpp new file mode 100644 index 000000000000..1aa6cf6da28d --- /dev/null +++ b/libs/androidfw/ResourceUtils.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "androidfw/ResourceUtils.h" + +namespace android { + +bool ExtractResourceName(const StringPiece& str, StringPiece* out_package, StringPiece* out_type, + StringPiece* out_entry) { + *out_package = ""; + *out_type = ""; + 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()); +} + +} // namespace android |