From 149938cc445f99b1aa40c490014aad72cf698dec Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Sun, 15 Dec 2024 06:41:07 +0100 Subject: lxdrgen-cpp: add a Qt backend Motivation: some Android NDKs do not have iconv. --- tools/lxdrgen-cpp-qt.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tools/lxdrgen-cpp-qt.cpp (limited to 'tools') diff --git a/tools/lxdrgen-cpp-qt.cpp b/tools/lxdrgen-cpp-qt.cpp new file mode 100644 index 0000000..60e7293 --- /dev/null +++ b/tools/lxdrgen-cpp-qt.cpp @@ -0,0 +1,23 @@ +// lxdrgen-cpp-qt.cpp: Qt support code for lxdrgen-cpp.awk. +// +// Copyright (c) 2024, Přemysl Eric Janouch +// SPDX-License-Identifier: 0BSD +#include +#include + +namespace LibertyXDR { + +bool utf8_to_wstring(const uint8_t *utf8, size_t length, std::wstring &wide) { + QByteArrayView view(reinterpret_cast(utf8), length); + if (!view.isValidUtf8()) + return false; + wide = QString::fromUtf8(view).toStdWString(); + return true; +} + +bool wstring_to_utf8(const std::wstring &wide, std::string &utf8) { + utf8 = QString::fromStdWString(wide).toUtf8().toStdString(); + return true; +} + +} // namespace LibertyXDR -- cgit v1.2.3-70-g09d2