Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 1 | /* |
| 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 Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 18 | |
| 19 | #include "androidfw/StringPiece.h" |
| 20 | #include "androidfw/Util.h" |
| 21 | |
| 22 | #include "idmap2/ResourceUtils.h" |
Mårten Kongstad | 0f76311 | 2018-11-19 14:14:37 +0100 | [diff] [blame] | 23 | #include "idmap2/Result.h" |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 24 | |
| 25 | using android::StringPiece16; |
| 26 | using android::util::Utf16ToUtf8; |
| 27 | |
| 28 | namespace android { |
| 29 | namespace idmap2 { |
| 30 | namespace utils { |
| 31 | |
Mårten Kongstad | 0f76311 | 2018-11-19 14:14:37 +0100 | [diff] [blame] | 32 | Result<std::string> WARN_UNUSED ResToTypeEntryName(const AssetManager2& am, ResourceId resid) { |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 33 | AssetManager2::ResourceName name; |
| 34 | if (!am.GetResourceName(resid, &name)) { |
Mårten Kongstad | 0f76311 | 2018-11-19 14:14:37 +0100 | [diff] [blame] | 35 | return {}; |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 36 | } |
| 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 Kongstad | 0f76311 | 2018-11-19 14:14:37 +0100 | [diff] [blame] | 49 | return {out}; |
Mårten Kongstad | 0275123 | 2018-04-27 13:16:32 +0200 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | } // namespace utils |
| 53 | } // namespace idmap2 |
| 54 | } // namespace android |