unicode: add system charset detection
Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
parent
bffb48c87d
commit
fea0ed7754
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
SPDX-License-Identifier: MIT
|
SPDX-License-Identifier: MIT
|
||||||
Copyright © 2023 Amebis
|
Copyright © 2023 Amebis
|
||||||
*/
|
*/
|
||||||
@ -329,6 +329,32 @@ namespace stdex
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static charset_id system_charset()
|
||||||
|
{
|
||||||
|
#ifdef _WIN32
|
||||||
|
return static_cast<charset_id>(GetACP());
|
||||||
|
#else
|
||||||
|
const char* lctype = nl_langinfo(LC_CTYPE);
|
||||||
|
if (strcmp(lctype, "UTF-8") == 0) return charset_id::utf8;
|
||||||
|
if (strcmp(lctype, "UTF-16") == 0) return charset_id::utf16;
|
||||||
|
#if BYTE_ORDER == BIG_ENDIAN
|
||||||
|
if (strcmp(lctype, "UTF-16BE") == 0) return charset_id::utf16;
|
||||||
|
#else
|
||||||
|
if (strcmp(lctype, "UTF-16LE") == 0) return charset_id::utf16;
|
||||||
|
#endif
|
||||||
|
if (strcmp(lctype, "UTF-32") == 0) return charset_id::utf32;
|
||||||
|
#if BYTE_ORDER == BIG_ENDIAN
|
||||||
|
if (strcmp(lctype, "UTF-32BE") == 0) return charset_id::utf32;
|
||||||
|
#else
|
||||||
|
if (strcmp(lctype, "UTF-32LE") == 0) return charset_id::utf32;
|
||||||
|
#endif
|
||||||
|
if (strcmp(lctype, "CP1250") == 0) return charset_id::windows1250;
|
||||||
|
if (strcmp(lctype, "CP1251") == 0) return charset_id::windows1251;
|
||||||
|
if (strcmp(lctype, "CP1252") == 0) return charset_id::windows1252;
|
||||||
|
return charset_id::system;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
protected:
|
protected:
|
||||||
static UINT to_encoding(_In_ charset_id charset)
|
static UINT to_encoding(_In_ charset_id charset)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user