From d1ecd7af687bcad0f87c37fe33515ff6c5ea0f1d Mon Sep 17 00:00:00 2001 From: Adam Lesinski Date: Mon, 23 Jan 2017 12:58:11 -0800 Subject: AssetManager2: Various fixes - Use FileMaps to open Assets (prevents closing of ApkAssets underlying zip) - Implement OpenDir and List methods - Fix issue where DynamicRefTable wasn't properly constructed Test: make libandroidfw_tests Change-Id: Ib21a84e1114d028120744aa3bc1c6eb9d9399fa8 --- libs/androidfw/Util.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'libs/androidfw/Util.cpp') diff --git a/libs/androidfw/Util.cpp b/libs/androidfw/Util.cpp index 202bc8e5743a..575cd18a36dd 100644 --- a/libs/androidfw/Util.cpp +++ b/libs/androidfw/Util.cpp @@ -41,5 +41,31 @@ void ReadUtf16StringFromDevice(const uint16_t* src, size_t len, std::string* out } } +std::u16string Utf8ToUtf16(const StringPiece& utf8) { + ssize_t utf16_length = + utf8_to_utf16_length(reinterpret_cast(utf8.data()), utf8.length()); + if (utf16_length <= 0) { + return {}; + } + + std::u16string utf16; + utf16.resize(utf16_length); + utf8_to_utf16(reinterpret_cast(utf8.data()), utf8.length(), &*utf16.begin(), + utf16_length + 1); + return utf16; +} + +std::string Utf16ToUtf8(const StringPiece16& utf16) { + ssize_t utf8_length = utf16_to_utf8_length(utf16.data(), utf16.length()); + if (utf8_length <= 0) { + return {}; + } + + std::string utf8; + utf8.resize(utf8_length); + utf16_to_utf8(utf16.data(), utf16.length(), &*utf8.begin(), utf8_length + 1); + return utf8; +} + } // namespace util } // namespace android -- cgit v1.2.3-59-g8ed1b