blob: 202bc8e5743a5a2d3dc077786635b4e0006f7db8 [file] [log] [blame]
Adam Lesinskida431a22016-12-29 16:08:16 -05001/*
2 * Copyright (C) 2016 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 "androidfw/Util.h"
18
19#include <string>
20
21#include "utils/ByteOrder.h"
22#include "utils/Unicode.h"
23
24#ifdef _WIN32
25#ifdef ERROR
26#undef ERROR
27#endif
28#endif
29
30namespace android {
31namespace util {
32
33void ReadUtf16StringFromDevice(const uint16_t* src, size_t len, std::string* out) {
34 char buf[5];
35 while (*src && len != 0) {
36 char16_t c = static_cast<char16_t>(dtohs(*src));
37 utf16_to_utf8(&c, 1, buf, sizeof(buf));
38 out->append(buf, strlen(buf));
39 ++src;
40 --len;
41 }
42}
43
44} // namespace util
45} // namespace android