Lots of work on unicode support

This commit is contained in:
2023-05-19 00:23:23 -04:00
parent a25213d259
commit 7e25be10a4
10 changed files with 249 additions and 228 deletions

View File

@@ -230,14 +230,15 @@ static void init_winsock() {
}
}
static void console_write(const CodepointString &cps) {
static void console_write(const std::u32string &cps) {
if (cps.size() == 0) return;
// Convert to wstring.
// Any character outside the range 0xFFFF is replaced with a box.
// Convert to wstring. Any character not representable as a single wchar_t
// is replaced with a box. It's not ideal, but it's pretty good.
std::wstring ws(cps.size(), 0);
for (int i = 0; i < int(cps.size()); i++) {
char32_t c = cps[i];
if ((c >= 0)&&(c <= 0xFFFF)) ws[i] = (wchar_t)c;
if (drvutil::is_single_wchar_t(c)) ws[i] = (wchar_t)c;
else ws[i] = 0x2610;
}
HANDLE hstdout = GetStdHandle(STD_OUTPUT_HANDLE);
@@ -253,7 +254,7 @@ static void console_write(const CodepointString &cps) {
}
}
static CodepointString console_read() {
static std::u32string console_read() {
HANDLE hstdin = GetStdHandle(STD_INPUT_HANDLE);
assert(hstdin != INVALID_HANDLE_VALUE);
INPUT_RECORD inrecords[512];
@@ -262,7 +263,7 @@ static CodepointString console_read() {
if (int(nevents) > 0) {
if (int(nevents) > 512) nevents = 512;
ReadConsoleInputW(hstdin, inrecords, nevents, &nread);
CodepointString result(nread, 0);
std::u32string result(nread, 0);
int len = 0;
for (int i = 0; i < int(nread); i++) {
const INPUT_RECORD &inr = inrecords[i];
@@ -274,7 +275,7 @@ static CodepointString console_read() {
return result.substr(0, len);
}
}
return CodepointString();
return std::u32string();
}
static void ssl_load_certificate_authorities(SSL_CTX *ctx) {