blob: 04e0ec7560452bffee6d2e99f65c0e2d6b49b626 [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
Mårten Kongstad0eba72a2018-11-29 08:23:14 +010028namespace android::idmap2::utils {
Mårten Kongstad02751232018-04-27 13:16:32 +020029
Mårten Kongstad0f763112018-11-19 14:14:37 +010030Result<std::string> WARN_UNUSED ResToTypeEntryName(const AssetManager2& am, ResourceId resid) {
Mårten Kongstad02751232018-04-27 13:16:32 +020031 AssetManager2::ResourceName name;
32 if (!am.GetResourceName(resid, &name)) {
Mårten Kongstad0f763112018-11-19 14:14:37 +010033 return {};
Mårten Kongstad02751232018-04-27 13:16:32 +020034 }
35 std::string out;
36 if (name.type != nullptr) {
37 out.append(name.type, name.type_len);
38 } else {
39 out += Utf16ToUtf8(StringPiece16(name.type16, name.type_len));
40 }
41 out.append("/");
42 if (name.entry != nullptr) {
43 out.append(name.entry, name.entry_len);
44 } else {
45 out += Utf16ToUtf8(StringPiece16(name.entry16, name.entry_len));
46 }
Mårten Kongstad0f763112018-11-19 14:14:37 +010047 return {out};
Mårten Kongstad02751232018-04-27 13:16:32 +020048}
49
Mårten Kongstad0eba72a2018-11-29 08:23:14 +010050} // namespace android::idmap2::utils