blob: 1aa6cf6da28d8a85884829595d8f430bf2b65aca [file] [log] [blame]
Adam Lesinski929d6512017-01-16 19:11:19 -08001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "androidfw/ResourceUtils.h"
18
19namespace android {
20
21bool ExtractResourceName(const StringPiece& str, StringPiece* out_package, StringPiece* out_type,
22 StringPiece* out_entry) {
23 *out_package = "";
24 *out_type = "";
25 bool has_package_separator = false;
26 bool has_type_separator = false;
27 const char* start = str.data();
28 const char* end = start + str.size();
29 const char* current = start;
30 while (current != end) {
31 if (out_type->size() == 0 && *current == '/') {
32 has_type_separator = true;
33 out_type->assign(start, current - start);
34 start = current + 1;
35 } else if (out_package->size() == 0 && *current == ':') {
36 has_package_separator = true;
37 out_package->assign(start, current - start);
38 start = current + 1;
39 }
40 current++;
41 }
42 out_entry->assign(start, end - start);
43
44 return !(has_package_separator && out_package->empty()) &&
45 !(has_type_separator && out_type->empty());
46}
47
48} // namespace android