summaryrefslogtreecommitdiff
path: root/libs/androidfw/Util.cpp
diff options
context:
space:
mode:
authorAdam Lesinski <adamlesinski@google.com>2017-01-23 12:58:11 -0800
committerAdam Lesinski <adamlesinski@google.com>2017-02-15 10:50:23 -0800
commitd1ecd7af687bcad0f87c37fe33515ff6c5ea0f1d (patch)
tree63822987507c52532481ca86333751e4fb329953 /libs/androidfw/Util.cpp
parentc535d122c6a58a152ff2581f936070c2695c45ba (diff)
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
Diffstat (limited to 'libs/androidfw/Util.cpp')
-rw-r--r--libs/androidfw/Util.cpp26
1 files changed, 26 insertions, 0 deletions
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<const uint8_t*>(utf8.data()), utf8.length());
+ if (utf16_length <= 0) {
+ return {};
+ }
+
+ std::u16string utf16;
+ utf16.resize(utf16_length);
+ utf8_to_utf16(reinterpret_cast<const uint8_t*>(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