chore: make IArchString::EWideCharEncoding a enum class

This commit is contained in:
sithlord48 2025-05-22 16:33:32 -04:00 committed by Nick Bolton
parent 45090d6b85
commit 4224215991
7 changed files with 17 additions and 17 deletions

View file

@ -33,7 +33,7 @@ public:
/*!
The known wide character encodings
*/
enum EWideCharEncoding
enum class EWideCharEncoding : uint8_t
{
kUCS2, //!< The UCS-2 encoding
kUCS4, //!< The UCS-4 encoding

View file

@ -15,5 +15,5 @@
IArchString::EWideCharEncoding ArchStringUnix::getWideCharEncoding()
{
return kUCS4;
return EWideCharEncoding::kUCS4;
}

View file

@ -18,5 +18,5 @@
IArchString::EWideCharEncoding ArchStringWindows::getWideCharEncoding()
{
return kUTF16;
return EWideCharEncoding::kUTF16;
}

View file

@ -8,10 +8,10 @@
#include "base/Unicode.h"
#include "arch/Arch.h"
using enum IArchString::EWideCharEncoding;
//
// local utility functions
//
inline static uint16_t decode16(const uint8_t *n, bool byteSwapped)
{
union x16
@ -281,22 +281,22 @@ wchar_t *Unicode::UTF8ToWideChar(const std::string &src, uint32_t &size, bool *e
// convert to platform's wide character encoding
std::string tmp;
switch (ARCH->getWideCharEncoding()) {
case IArchString::kUCS2:
case kUCS2:
tmp = UTF8ToUCS2(src, errors);
size = (uint32_t)tmp.size() >> 1;
break;
case IArchString::kUCS4:
case kUCS4:
tmp = UTF8ToUCS4(src, errors);
size = (uint32_t)tmp.size() >> 2;
break;
case IArchString::kUTF16:
case kUTF16:
tmp = UTF8ToUTF16(src, errors);
size = (uint32_t)tmp.size() >> 1;
break;
case IArchString::kUTF32:
case kUTF32:
tmp = UTF8ToUTF32(src, errors);
size = (uint32_t)tmp.size() >> 2;
break;
@ -314,23 +314,23 @@ 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)
{
if (encoding == IArchString::kPlatformDetermined) {
if (encoding == kPlatformDetermined) {
encoding = ARCH->getWideCharEncoding();
}
// convert from platform's wide character encoding.
// note -- this must include a wide nul character (independent of
// the String's nul character).
switch (encoding) {
case IArchString::kUCS2:
case kUCS2:
return doUCS2ToUTF8(reinterpret_cast<const uint8_t *>(src), size, errors);
case IArchString::kUCS4:
case kUCS4:
return doUCS4ToUTF8(reinterpret_cast<const uint8_t *>(src), size, errors);
case IArchString::kUTF16:
case kUTF16:
return doUTF16ToUTF8(reinterpret_cast<const uint8_t *>(src), size, errors);
case IArchString::kUTF32:
case kUTF32:
return doUTF32ToUTF8(reinterpret_cast<const uint8_t *>(src), size, errors);
default:

View file

@ -104,7 +104,7 @@ public:
*/
static std::string textToUTF8(
const std::string &, bool *errors = nullptr,
IArchString::EWideCharEncoding encoding = IArchString::kPlatformDetermined
IArchString::EWideCharEncoding encoding = IArchString::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::kPlatformDetermined
IArchString::EWideCharEncoding encoding = IArchString::EWideCharEncoding::kPlatformDetermined
);
// internal conversion to UTF8

View file

@ -13,7 +13,7 @@ class SampleIArchString : public IArchString
public:
EWideCharEncoding getWideCharEncoding() override
{
return kUTF16;
return EWideCharEncoding::kUTF16;
}
};

View file

@ -37,7 +37,7 @@ void UnicodeTests::UTF16ToUTF8()
void UnicodeTests::UCS2ToUTF8_kUCS2()
{
bool errors;
auto result = Unicode::textToUTF8("hello", &errors, IArchString::kUCS2);
auto result = Unicode::textToUTF8("hello", &errors, IArchString::EWideCharEncoding::kUCS2);
QVERIFY(!errors);
#ifdef _WIN32