mirror of
https://github.com/deskflow/deskflow.git
synced 2026-07-01 21:02:39 +08:00
Some checks failed
CodeQL Analysis / Analyze (cpp) (push) Has been cancelled
Continuous Integration / reuse-lint (push) Has been cancelled
Continuous Integration / pr-comment-flags (push) Has been cancelled
Continuous Integration / ci-passed (push) Has been cancelled
Continuous Integration / test-results (push) Has been cancelled
Continuous Integration / lint-check (push) Has been cancelled
Continuous Integration / analyse-valgrind (push) Has been cancelled
Continuous Integration / analyse-sonarcloud (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-DCMAKE_OSX_ARCHITECTURES="arm64" -DCMAKE_OSX_SYSROOT=/Applications/Xcode_15.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk name:macos-14-arm64 qt-version:6.9.1 runs-on:macos-14 t… (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-DCMAKE_OSX_ARCHITECTURES="x86_64" -DCMAKE_OSX_SYSROOT=/Applications/Xcode_15.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk name:macos-13-x64 qt-version:6.9.1 runs-on:macos-13 ti… (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr -DBUILD_DEV_DOCS=ON container:archlinux:latest like:arch name:archlinux-x86_84 runs-on:ubuntu-latest timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr container:debian:trixie-slim like:debian name:debian-13-arm64 runs-on:ubuntu-24.04-arm timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr container:debian:trixie-slim like:debian name:debian-13-x86_64 runs-on:ubuntu-latest timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr container:fedora:40 like:fedora name:fedora-40-arm64 runs-on:ubuntu-24.04-arm timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr container:fedora:40 like:fedora name:fedora-40-x86_84 runs-on:ubuntu-latest timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr container:fedora:41 like:fedora name:fedora-41-arm64 runs-on:ubuntu-24.04-arm timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr container:fedora:41 like:fedora name:fedora-41-x86_64 runs-on:ubuntu-latest timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr container:fedora:42 like:fedora name:fedora-42-arm64 runs-on:ubuntu-24.04-arm timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr container:fedora:42 like:fedora name:fedora-42-x86_64 runs-on:ubuntu-latest timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr container:opensuse/tumbleweed:latest like:suse name:opensuse-arm64 runs-on:ubuntu-24.04-arm timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr container:opensuse/tumbleweed:latest like:suse name:opensuse-x86_84 runs-on:ubuntu-latest timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr container:ubuntu:25.04 like:debian name:ubuntu-25.04-arm64 runs-on:ubuntu-24.04-arm timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja -DCMAKE_INSTALL_PREFIX=/usr container:ubuntu:25.04 like:debian name:ubuntu-25.04-x86_64 runs-on:ubuntu-latest timeout:20]) (push) Has been cancelled
Continuous Integration / ${{ matrix.target.name }} (map[config-args:-G Ninja name:windows-2022-x64 qt-version:6.8.3 runs-on:windows-2022 timeout:30]) (push) Has been cancelled
Continuous Integration / unix-${{ matrix.distro.name }} (map[name:freebsd]) (push) Has been cancelled
Continuous Integration / flatpak-${{matrix.flatpak.arch}} (map[arch:aarch64 runs-on:ubuntu-24.04-arm]) (push) Has been cancelled
Continuous Integration / flatpak-${{matrix.flatpak.arch}} (map[arch:x86_64 runs-on:ubuntu-latest]) (push) Has been cancelled
Continuous Integration / release (push) Has been cancelled
Continuous Integration / winget-publish (push) Has been cancelled
164 lines
3.5 KiB
C++
164 lines
3.5 KiB
C++
/*
|
|
* Deskflow -- mouse and keyboard sharing utility
|
|
* SPDX-FileCopyrightText: (C) 2012 - 2016 Symless Ltd.
|
|
* SPDX-FileCopyrightText: (C) 2002 Chris Schoeneman
|
|
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
|
*/
|
|
|
|
#include "arch/ArchString.h"
|
|
|
|
#include <climits>
|
|
#include <cstdlib>
|
|
#include <cstring>
|
|
#include <mutex>
|
|
|
|
std::mutex s_mutex;
|
|
|
|
//
|
|
// use C library non-reentrant multibyte conversion with mutex
|
|
//
|
|
|
|
int ArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, bool *errors) const
|
|
{
|
|
std::scoped_lock lock{s_mutex};
|
|
ptrdiff_t len = 0;
|
|
|
|
bool dummyErrors;
|
|
if (errors == nullptr) {
|
|
errors = &dummyErrors;
|
|
}
|
|
*errors = false;
|
|
|
|
if (dst == nullptr) {
|
|
char dummy[MB_LEN_MAX];
|
|
const wchar_t *scan = src;
|
|
for (; n > 0; --n) {
|
|
ptrdiff_t mblen = wctomb(dummy, *scan);
|
|
if (mblen == -1) {
|
|
*errors = true;
|
|
mblen = 1;
|
|
}
|
|
len += mblen;
|
|
++scan;
|
|
}
|
|
if (ptrdiff_t mblen = wctomb(dummy, L'\0'); mblen != -1) {
|
|
len += mblen - 1;
|
|
}
|
|
} else {
|
|
const char *dst0 = dst;
|
|
const wchar_t *scan = src;
|
|
for (; n > 0; --n) {
|
|
if (ptrdiff_t mblen = wctomb(dst, *scan); mblen == -1) {
|
|
*errors = true;
|
|
*dst++ = '?';
|
|
} else {
|
|
dst += mblen;
|
|
}
|
|
++scan;
|
|
}
|
|
if (ptrdiff_t mblen = wctomb(dst, L'\0'); mblen != -1) {
|
|
// don't include nul terminator
|
|
dst += mblen - 1;
|
|
}
|
|
len = dst - dst0;
|
|
}
|
|
|
|
return static_cast<int>(len);
|
|
}
|
|
|
|
ArchString::EWideCharEncoding ArchString::getWideCharEncoding() const
|
|
{
|
|
#ifdef SYSAPI_WIN32
|
|
return EWideCharEncoding::kUTF16;
|
|
#else
|
|
return EWideCharEncoding::kUCS4;
|
|
#endif
|
|
}
|
|
|
|
int ArchString::convStringMBToWC(wchar_t *dst, const char *src, uint32_t n, bool *errors) const
|
|
{
|
|
std::scoped_lock lock{s_mutex};
|
|
ptrdiff_t len = 0;
|
|
wchar_t dummy;
|
|
|
|
bool dummyErrors;
|
|
if (errors == nullptr) {
|
|
errors = &dummyErrors;
|
|
}
|
|
*errors = false;
|
|
|
|
if (dst == nullptr) {
|
|
const char *scan = src;
|
|
while (n > 0) {
|
|
switch (ptrdiff_t mblen = mbtowc(&dummy, scan, n); mblen) {
|
|
case -2:
|
|
// incomplete last character. convert to unknown character.
|
|
*errors = true;
|
|
len += 1;
|
|
n = 0;
|
|
break;
|
|
|
|
case -1:
|
|
// invalid character. count one unknown character and
|
|
// start at the next byte.
|
|
*errors = true;
|
|
len += 1;
|
|
scan += 1;
|
|
n -= 1;
|
|
break;
|
|
|
|
case 0:
|
|
len += 1;
|
|
scan += 1;
|
|
n -= 1;
|
|
break;
|
|
|
|
default:
|
|
// normal character
|
|
len += 1;
|
|
scan += static_cast<int>(mblen);
|
|
n -= static_cast<int>(mblen);
|
|
break;
|
|
}
|
|
}
|
|
} else {
|
|
const wchar_t *dst0 = dst;
|
|
const char *scan = src;
|
|
while (n > 0) {
|
|
switch (ptrdiff_t mblen = mbtowc(dst, scan, n); mblen) {
|
|
case -2:
|
|
// incomplete character. convert to unknown character.
|
|
*errors = true;
|
|
*dst = (wchar_t)0xfffd;
|
|
n = 0;
|
|
break;
|
|
|
|
case -1:
|
|
// invalid character. count one unknown character and
|
|
// start at the next byte.
|
|
*errors = true;
|
|
*dst = (wchar_t)0xfffd;
|
|
scan += 1;
|
|
n -= 1;
|
|
break;
|
|
|
|
case 0:
|
|
*dst = (wchar_t)0x0000;
|
|
scan += 1;
|
|
n -= 1;
|
|
break;
|
|
|
|
default:
|
|
// normal character
|
|
scan += static_cast<int>(mblen);
|
|
n -= static_cast<int>(mblen);
|
|
break;
|
|
}
|
|
++dst;
|
|
}
|
|
len = dst - dst0;
|
|
}
|
|
|
|
return static_cast<int>(len);
|
|
}
|