blob: e98f843931c894ee0c738e60b2fafbc65e15eea7 [file] [log] [blame]
MÃ¥rten Kongstad02751232018-04-27 13:16:32 +02001/*
2 * Copyright (C) 2018 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 <string>
18#include <utility>
19
20#include "androidfw/StringPiece.h"
21#include "androidfw/Util.h"
22
23#include "idmap2/ResourceUtils.h"
24
25using android::StringPiece16;
26using android::util::Utf16ToUtf8;
27
28namespace android {
29namespace idmap2 {
30namespace utils {
31
32std::pair<bool, std::string> WARN_UNUSED ResToTypeEntryName(const AssetManager2& am,
33 ResourceId resid) {
34 AssetManager2::ResourceName name;
35 if (!am.GetResourceName(resid, &name)) {
36 return std::make_pair(false, "");
37 }
38 std::string out;
39 if (name.type != nullptr) {
40 out.append(name.type, name.type_len);
41 } else {
42 out += Utf16ToUtf8(StringPiece16(name.type16, name.type_len));
43 }
44 out.append("/");
45 if (name.entry != nullptr) {
46 out.append(name.entry, name.entry_len);
47 } else {
48 out += Utf16ToUtf8(StringPiece16(name.entry16, name.entry_len));
49 }
50 return std::make_pair(true, out);
51}
52
53} // namespace utils
54} // namespace idmap2
55} // namespace android