blob: 5c897832e9d5e5e3001dde302ce1886727b57cc8 [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>
Mårten Kongstad02751232018-04-27 13:16:32 +020018
19#include "androidfw/StringPiece.h"
20#include "androidfw/Util.h"
21
22#include "idmap2/ResourceUtils.h"
Mårten Kongstad0f763112018-11-19 14:14:37 +010023#include "idmap2/Result.h"
Mårten Kongstad02751232018-04-27 13:16:32 +020024
25using android::StringPiece16;
26using android::util::Utf16ToUtf8;
27
28namespace android {
29namespace idmap2 {
30namespace utils {
31
Mårten Kongstad0f763112018-11-19 14:14:37 +010032Result<std::string> WARN_UNUSED ResToTypeEntryName(const AssetManager2& am, ResourceId resid) {
Mårten Kongstad02751232018-04-27 13:16:32 +020033 AssetManager2::ResourceName name;
34 if (!am.GetResourceName(resid, &name)) {
Mårten Kongstad0f763112018-11-19 14:14:37 +010035 return {};
Mårten Kongstad02751232018-04-27 13:16:32 +020036 }
37 std::string out;
38 if (name.type != nullptr) {
39 out.append(name.type, name.type_len);
40 } else {
41 out += Utf16ToUtf8(StringPiece16(name.type16, name.type_len));
42 }
43 out.append("/");
44 if (name.entry != nullptr) {
45 out.append(name.entry, name.entry_len);
46 } else {
47 out += Utf16ToUtf8(StringPiece16(name.entry16, name.entry_len));
48 }
Mårten Kongstad0f763112018-11-19 14:14:37 +010049 return {out};
Mårten Kongstad02751232018-04-27 13:16:32 +020050}
51
52} // namespace utils
53} // namespace idmap2
54} // namespace android