refactor: consolidate IArchString subclasses into ArchString
This commit is contained in:
@ -24,6 +24,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "arch/ArchString.h"
|
||||
#include "common/Common.h"
|
||||
|
||||
#if SYSAPI_WIN32
|
||||
@ -33,7 +34,6 @@
|
||||
#include "arch/win32/ArchMultithreadWindows.h"
|
||||
#include "arch/win32/ArchNetworkWinsock.h"
|
||||
#include "arch/win32/ArchSleepWindows.h"
|
||||
#include "arch/win32/ArchStringWindows.h"
|
||||
#include "arch/win32/ArchTimeWindows.h"
|
||||
|
||||
#elif SYSAPI_UNIX
|
||||
@ -42,7 +42,6 @@
|
||||
#include "arch/unix/ArchLogUnix.h"
|
||||
#include "arch/unix/ArchNetworkBSD.h"
|
||||
#include "arch/unix/ArchSleepUnix.h"
|
||||
#include "arch/unix/ArchStringUnix.h"
|
||||
#include "arch/unix/ArchTimeUnix.h"
|
||||
|
||||
#if HAVE_PTHREAD
|
||||
@ -72,7 +71,7 @@ class Arch : public ARCH_DAEMON,
|
||||
public ARCH_MULTITHREAD,
|
||||
public ARCH_NETWORK,
|
||||
public ARCH_SLEEP,
|
||||
public ARCH_STRING,
|
||||
public ArchString,
|
||||
public ARCH_TIME
|
||||
{
|
||||
public:
|
||||
|
||||
@ -5,9 +5,8 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "arch/IArchString.h"
|
||||
#include "arch/ArchString.h"
|
||||
#include "arch/Arch.h"
|
||||
#include "common/Common.h"
|
||||
|
||||
#include <climits>
|
||||
#include <cstdlib>
|
||||
@ -19,7 +18,7 @@ static ArchMutex s_mutex = nullptr;
|
||||
// use C library non-reentrant multibyte conversion with mutex
|
||||
//
|
||||
|
||||
IArchString::~IArchString()
|
||||
ArchString::~ArchString()
|
||||
{
|
||||
if (s_mutex != nullptr) {
|
||||
ARCH->closeMutex(s_mutex);
|
||||
@ -27,7 +26,7 @@ IArchString::~IArchString()
|
||||
}
|
||||
}
|
||||
|
||||
int IArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, bool *errors)
|
||||
int ArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, bool *errors) const
|
||||
{
|
||||
ptrdiff_t len = 0;
|
||||
|
||||
@ -81,7 +80,16 @@ int IArchString::convStringWCToMB(char *dst, const wchar_t *src, uint32_t n, boo
|
||||
return static_cast<int>(len);
|
||||
}
|
||||
|
||||
int IArchString::convStringMBToWC(wchar_t *dst, const char *src, uint32_t n, bool *errors)
|
||||
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
|
||||
{
|
||||
ptrdiff_t len = 0;
|
||||
wchar_t dummy;
|
||||
@ -18,16 +18,16 @@
|
||||
This interface defines the string operations required by
|
||||
deskflow. Each architecture must implement this interface.
|
||||
*/
|
||||
class IArchString : public IInterface
|
||||
class ArchString : public IInterface
|
||||
{
|
||||
public:
|
||||
IArchString() = default;
|
||||
IArchString(const IArchString &) = delete;
|
||||
IArchString(IArchString &&) = delete;
|
||||
~IArchString() override;
|
||||
ArchString() = default;
|
||||
ArchString(const ArchString &) = delete;
|
||||
ArchString(ArchString &&) = delete;
|
||||
~ArchString() override;
|
||||
|
||||
IArchString &operator=(const IArchString &) = delete;
|
||||
IArchString &operator=(IArchString &&) = delete;
|
||||
ArchString &operator=(const ArchString &) = delete;
|
||||
ArchString &operator=(ArchString &&) = delete;
|
||||
|
||||
//! Wide character encodings
|
||||
/*!
|
||||
@ -46,13 +46,13 @@ public:
|
||||
//@{
|
||||
|
||||
//! Convert multibyte string to wide character string
|
||||
virtual int convStringMBToWC(wchar_t *, const char *, uint32_t n, bool *errors);
|
||||
int convStringMBToWC(wchar_t *, const char *, uint32_t n, bool *errors) const;
|
||||
|
||||
//! Convert wide character string to multibyte string
|
||||
virtual int convStringWCToMB(char *, const wchar_t *, uint32_t n, bool *errors);
|
||||
int convStringWCToMB(char *, const wchar_t *, uint32_t n, bool *errors) const;
|
||||
|
||||
//! Return the architecture's native wide character encoding
|
||||
virtual EWideCharEncoding getWideCharEncoding() = 0;
|
||||
EWideCharEncoding getWideCharEncoding() const;
|
||||
|
||||
//@}
|
||||
};
|
||||
@ -18,8 +18,6 @@ if(WIN32)
|
||||
win32/ArchNetworkWinsock.h
|
||||
win32/ArchSleepWindows.cpp
|
||||
win32/ArchSleepWindows.h
|
||||
win32/ArchStringWindows.cpp
|
||||
win32/ArchStringWindows.h
|
||||
win32/ArchTimeWindows.cpp
|
||||
win32/ArchTimeWindows.h
|
||||
win32/XArchWindows.cpp
|
||||
@ -38,8 +36,6 @@ elseif(UNIX)
|
||||
unix/ArchNetworkBSD.h
|
||||
unix/ArchSleepUnix.cpp
|
||||
unix/ArchSleepUnix.h
|
||||
unix/ArchStringUnix.cpp
|
||||
unix/ArchStringUnix.h
|
||||
unix/ArchTimeUnix.cpp
|
||||
unix/ArchTimeUnix.h
|
||||
unix/XArchUnix.cpp
|
||||
@ -57,8 +53,8 @@ add_library(arch STATIC ${PLATFORM_CODE}
|
||||
IArchMultithread.h
|
||||
IArchNetwork.h
|
||||
IArchSleep.h
|
||||
IArchString.cpp
|
||||
IArchString.h
|
||||
ArchString.cpp
|
||||
ArchString.h
|
||||
IArchTime.h
|
||||
XArch.h
|
||||
)
|
||||
|
||||
@ -1,19 +0,0 @@
|
||||
/*
|
||||
* 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/unix/ArchStringUnix.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
//
|
||||
// ArchStringUnix
|
||||
//
|
||||
|
||||
IArchString::EWideCharEncoding ArchStringUnix::getWideCharEncoding()
|
||||
{
|
||||
return EWideCharEncoding::kUCS4;
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "arch/IArchString.h"
|
||||
|
||||
#define ARCH_STRING ArchStringUnix
|
||||
|
||||
//! Unix implementation of IArchString
|
||||
class ArchStringUnix : public IArchString
|
||||
{
|
||||
public:
|
||||
ArchStringUnix() = default;
|
||||
~ArchStringUnix() override = default;
|
||||
|
||||
// IArchString overrides
|
||||
EWideCharEncoding getWideCharEncoding() override;
|
||||
};
|
||||
@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Deskflow -- mouse and keyboard sharing utility
|
||||
* SPDX-FileCopyrightText: (C) 2025 Deskflow Developers
|
||||
* 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/win32/ArchStringWindows.h"
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <Windows.h>
|
||||
#include <stdio.h>
|
||||
|
||||
//
|
||||
// ArchStringWindows
|
||||
//
|
||||
|
||||
IArchString::EWideCharEncoding ArchStringWindows::getWideCharEncoding()
|
||||
{
|
||||
return EWideCharEncoding::kUTF16;
|
||||
}
|
||||
@ -1,23 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "arch/IArchString.h"
|
||||
|
||||
#define ARCH_STRING ArchStringWindows
|
||||
|
||||
//! Win32 implementation of IArchString
|
||||
class ArchStringWindows : public IArchString
|
||||
{
|
||||
public:
|
||||
ArchStringWindows() = default;
|
||||
~ArchStringWindows() override = default;
|
||||
|
||||
// IArchString overrides
|
||||
EWideCharEncoding getWideCharEncoding() override;
|
||||
};
|
||||
@ -8,7 +8,7 @@
|
||||
#include "base/Unicode.h"
|
||||
#include "arch/Arch.h"
|
||||
|
||||
using enum IArchString::EWideCharEncoding;
|
||||
using enum ArchString::EWideCharEncoding;
|
||||
//
|
||||
// local utility functions
|
||||
//
|
||||
@ -256,7 +256,7 @@ std::string Unicode::UTF32ToUTF8(const std::string_view &src, bool *errors)
|
||||
return doUTF32ToUTF8(reinterpret_cast<const uint8_t *>(src.data()), n, errors);
|
||||
}
|
||||
|
||||
std::string Unicode::textToUTF8(const std::string &src, bool *errors, IArchString::EWideCharEncoding encoding)
|
||||
std::string Unicode::textToUTF8(const std::string &src, bool *errors, ArchString::EWideCharEncoding encoding)
|
||||
{
|
||||
// default to success
|
||||
resetError(errors);
|
||||
@ -312,7 +312,7 @@ wchar_t *Unicode::UTF8ToWideChar(const std::string &src, uint32_t &size, bool *e
|
||||
}
|
||||
|
||||
std::string
|
||||
Unicode::wideCharToUTF8(const wchar_t *src, uint32_t size, bool *errors, IArchString::EWideCharEncoding encoding)
|
||||
Unicode::wideCharToUTF8(const wchar_t *src, uint32_t size, bool *errors, ArchString::EWideCharEncoding encoding)
|
||||
{
|
||||
if (encoding == kPlatformDetermined) {
|
||||
encoding = ARCH->getWideCharEncoding();
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "arch/IArchString.h"
|
||||
#include "arch/ArchString.h"
|
||||
#include "common/Common.h"
|
||||
#include <string>
|
||||
|
||||
@ -104,7 +104,7 @@ public:
|
||||
*/
|
||||
static std::string textToUTF8(
|
||||
const std::string &, bool *errors = nullptr,
|
||||
IArchString::EWideCharEncoding encoding = IArchString::EWideCharEncoding::kPlatformDetermined
|
||||
ArchString::EWideCharEncoding encoding = ArchString::EWideCharEncoding::kPlatformDetermined
|
||||
);
|
||||
|
||||
//@}
|
||||
@ -120,7 +120,7 @@ private:
|
||||
// encoding) to UTF8.
|
||||
static std::string wideCharToUTF8(
|
||||
const wchar_t *, uint32_t size, bool *errors,
|
||||
IArchString::EWideCharEncoding encoding = IArchString::EWideCharEncoding::kPlatformDetermined
|
||||
ArchString::EWideCharEncoding encoding = ArchString::EWideCharEncoding::kPlatformDetermined
|
||||
);
|
||||
|
||||
// internal conversion to UTF8
|
||||
|
||||
@ -5,19 +5,19 @@
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception
|
||||
*/
|
||||
|
||||
#include "IArchStringTests.h"
|
||||
#include "ArchStringTests.h"
|
||||
|
||||
#include "arch/IArchString.h"
|
||||
#include "arch/ArchString.h"
|
||||
|
||||
void IArchStringTests::initTestCase()
|
||||
void ArchStringTests::initTestCase()
|
||||
{
|
||||
m_arch.init();
|
||||
m_log.setFilter(kDEBUG2);
|
||||
}
|
||||
|
||||
void IArchStringTests::convertStringWCToMB_buffer()
|
||||
void ArchStringTests::convertStringWCToMB_buffer()
|
||||
{
|
||||
SampleIArchString as;
|
||||
ArchString as;
|
||||
char buff[20];
|
||||
bool errors;
|
||||
|
||||
@ -28,9 +28,9 @@ void IArchStringTests::convertStringWCToMB_buffer()
|
||||
QVERIFY(!errors);
|
||||
}
|
||||
|
||||
void IArchStringTests::convertStringWCToMB_noBuffer()
|
||||
void ArchStringTests::convertStringWCToMB_noBuffer()
|
||||
{
|
||||
SampleIArchString as;
|
||||
ArchString as;
|
||||
bool errors;
|
||||
|
||||
auto converted = as.convStringWCToMB(nullptr, L"Hello", 6, &errors);
|
||||
@ -39,9 +39,9 @@ void IArchStringTests::convertStringWCToMB_noBuffer()
|
||||
QVERIFY(!errors);
|
||||
}
|
||||
|
||||
void IArchStringTests::convertStringMBToWC()
|
||||
void ArchStringTests::convertStringMBToWC()
|
||||
{
|
||||
SampleIArchString as;
|
||||
ArchString as;
|
||||
wchar_t buff[20];
|
||||
bool errors;
|
||||
|
||||
@ -55,4 +55,4 @@ void IArchStringTests::convertStringMBToWC()
|
||||
QVERIFY(!errors);
|
||||
}
|
||||
|
||||
QTEST_MAIN(IArchStringTests)
|
||||
QTEST_MAIN(ArchStringTests)
|
||||
@ -8,16 +8,7 @@
|
||||
|
||||
#include <QTest>
|
||||
|
||||
class SampleIArchString : public IArchString
|
||||
{
|
||||
public:
|
||||
EWideCharEncoding getWideCharEncoding() override
|
||||
{
|
||||
return EWideCharEncoding::kUTF16;
|
||||
}
|
||||
};
|
||||
|
||||
class IArchStringTests : public QObject
|
||||
class ArchStringTests : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private slots:
|
||||
@ -6,9 +6,9 @@ if(WIN32)
|
||||
endif()
|
||||
|
||||
create_test(
|
||||
NAME IArchStringTests
|
||||
NAME ArchStringTests
|
||||
DEPENDS arch
|
||||
LIBS base ${extra_libs}
|
||||
SOURCE IArchStringTests.cpp
|
||||
SOURCE ArchStringTests.cpp
|
||||
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/src/lib/arch"
|
||||
)
|
||||
|
||||
@ -7,7 +7,7 @@
|
||||
|
||||
#include "UnicodeTests.h"
|
||||
|
||||
#include "arch/IArchString.h"
|
||||
#include "arch/ArchString.h"
|
||||
#include "base/Unicode.h"
|
||||
|
||||
void UnicodeTests::initTestCase()
|
||||
@ -37,7 +37,7 @@ void UnicodeTests::UTF16ToUTF8()
|
||||
void UnicodeTests::UCS2ToUTF8_kUCS2()
|
||||
{
|
||||
bool errors;
|
||||
auto result = Unicode::textToUTF8("hello", &errors, IArchString::EWideCharEncoding::kUCS2);
|
||||
auto result = Unicode::textToUTF8("hello", &errors, ArchString::EWideCharEncoding::kUCS2);
|
||||
|
||||
QVERIFY(!errors);
|
||||
#ifdef _WIN32
|
||||
|
||||
Reference in New Issue
Block a user