chore: make IArchString::EWideCharEncoding a enum class
This commit is contained in:
parent
45090d6b85
commit
4224215991
7 changed files with 17 additions and 17 deletions
|
|
@ -33,7 +33,7 @@ public:
|
||||||
/*!
|
/*!
|
||||||
The known wide character encodings
|
The known wide character encodings
|
||||||
*/
|
*/
|
||||||
enum EWideCharEncoding
|
enum class EWideCharEncoding : uint8_t
|
||||||
{
|
{
|
||||||
kUCS2, //!< The UCS-2 encoding
|
kUCS2, //!< The UCS-2 encoding
|
||||||
kUCS4, //!< The UCS-4 encoding
|
kUCS4, //!< The UCS-4 encoding
|
||||||
|
|
|
||||||
|
|
@ -15,5 +15,5 @@
|
||||||
|
|
||||||
IArchString::EWideCharEncoding ArchStringUnix::getWideCharEncoding()
|
IArchString::EWideCharEncoding ArchStringUnix::getWideCharEncoding()
|
||||||
{
|
{
|
||||||
return kUCS4;
|
return EWideCharEncoding::kUCS4;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,5 +18,5 @@
|
||||||
|
|
||||||
IArchString::EWideCharEncoding ArchStringWindows::getWideCharEncoding()
|
IArchString::EWideCharEncoding ArchStringWindows::getWideCharEncoding()
|
||||||
{
|
{
|
||||||
return kUTF16;
|
return EWideCharEncoding::kUTF16;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@
|
||||||
#include "base/Unicode.h"
|
#include "base/Unicode.h"
|
||||||
#include "arch/Arch.h"
|
#include "arch/Arch.h"
|
||||||
|
|
||||||
|
using enum IArchString::EWideCharEncoding;
|
||||||
//
|
//
|
||||||
// local utility functions
|
// local utility functions
|
||||||
//
|
//
|
||||||
|
|
||||||
inline static uint16_t decode16(const uint8_t *n, bool byteSwapped)
|
inline static uint16_t decode16(const uint8_t *n, bool byteSwapped)
|
||||||
{
|
{
|
||||||
union x16
|
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
|
// convert to platform's wide character encoding
|
||||||
std::string tmp;
|
std::string tmp;
|
||||||
switch (ARCH->getWideCharEncoding()) {
|
switch (ARCH->getWideCharEncoding()) {
|
||||||
case IArchString::kUCS2:
|
case kUCS2:
|
||||||
tmp = UTF8ToUCS2(src, errors);
|
tmp = UTF8ToUCS2(src, errors);
|
||||||
size = (uint32_t)tmp.size() >> 1;
|
size = (uint32_t)tmp.size() >> 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IArchString::kUCS4:
|
case kUCS4:
|
||||||
tmp = UTF8ToUCS4(src, errors);
|
tmp = UTF8ToUCS4(src, errors);
|
||||||
size = (uint32_t)tmp.size() >> 2;
|
size = (uint32_t)tmp.size() >> 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IArchString::kUTF16:
|
case kUTF16:
|
||||||
tmp = UTF8ToUTF16(src, errors);
|
tmp = UTF8ToUTF16(src, errors);
|
||||||
size = (uint32_t)tmp.size() >> 1;
|
size = (uint32_t)tmp.size() >> 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case IArchString::kUTF32:
|
case kUTF32:
|
||||||
tmp = UTF8ToUTF32(src, errors);
|
tmp = UTF8ToUTF32(src, errors);
|
||||||
size = (uint32_t)tmp.size() >> 2;
|
size = (uint32_t)tmp.size() >> 2;
|
||||||
break;
|
break;
|
||||||
|
|
@ -314,23 +314,23 @@ wchar_t *Unicode::UTF8ToWideChar(const std::string &src, uint32_t &size, bool *e
|
||||||
std::string
|
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, IArchString::EWideCharEncoding encoding)
|
||||||
{
|
{
|
||||||
if (encoding == IArchString::kPlatformDetermined) {
|
if (encoding == kPlatformDetermined) {
|
||||||
encoding = ARCH->getWideCharEncoding();
|
encoding = ARCH->getWideCharEncoding();
|
||||||
}
|
}
|
||||||
// convert from platform's wide character encoding.
|
// convert from platform's wide character encoding.
|
||||||
// note -- this must include a wide nul character (independent of
|
// note -- this must include a wide nul character (independent of
|
||||||
// the String's nul character).
|
// the String's nul character).
|
||||||
switch (encoding) {
|
switch (encoding) {
|
||||||
case IArchString::kUCS2:
|
case kUCS2:
|
||||||
return doUCS2ToUTF8(reinterpret_cast<const uint8_t *>(src), size, errors);
|
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);
|
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);
|
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);
|
return doUTF32ToUTF8(reinterpret_cast<const uint8_t *>(src), size, errors);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@ public:
|
||||||
*/
|
*/
|
||||||
static std::string textToUTF8(
|
static std::string textToUTF8(
|
||||||
const std::string &, bool *errors = nullptr,
|
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.
|
// encoding) to UTF8.
|
||||||
static std::string wideCharToUTF8(
|
static std::string wideCharToUTF8(
|
||||||
const wchar_t *, uint32_t size, bool *errors,
|
const wchar_t *, uint32_t size, bool *errors,
|
||||||
IArchString::EWideCharEncoding encoding = IArchString::kPlatformDetermined
|
IArchString::EWideCharEncoding encoding = IArchString::EWideCharEncoding::kPlatformDetermined
|
||||||
);
|
);
|
||||||
|
|
||||||
// internal conversion to UTF8
|
// internal conversion to UTF8
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ class SampleIArchString : public IArchString
|
||||||
public:
|
public:
|
||||||
EWideCharEncoding getWideCharEncoding() override
|
EWideCharEncoding getWideCharEncoding() override
|
||||||
{
|
{
|
||||||
return kUTF16;
|
return EWideCharEncoding::kUTF16;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ void UnicodeTests::UTF16ToUTF8()
|
||||||
void UnicodeTests::UCS2ToUTF8_kUCS2()
|
void UnicodeTests::UCS2ToUTF8_kUCS2()
|
||||||
{
|
{
|
||||||
bool errors;
|
bool errors;
|
||||||
auto result = Unicode::textToUTF8("hello", &errors, IArchString::kUCS2);
|
auto result = Unicode::textToUTF8("hello", &errors, IArchString::EWideCharEncoding::kUCS2);
|
||||||
|
|
||||||
QVERIFY(!errors);
|
QVERIFY(!errors);
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue