From f94399f6846329fead4726b4b5c00fd8d9680349 Mon Sep 17 00:00:00 2001 From: qykth-git <14939671+qykth-git@users.noreply.github.com> Date: Tue, 17 Aug 2021 00:18:49 +0900 Subject: [PATCH] Use classic "C" locale if "C.UTF-8" locale is not supported by libc (#63) --- cli/pict.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cli/pict.cpp b/cli/pict.cpp index 2f759f3..0573652 100644 --- a/cli/pict.cpp +++ b/cli/pict.cpp @@ -6,6 +6,7 @@ #include <ctime> #include <cstring> #include <locale> +#include <stdexcept> using namespace std; #include "cmdline.h" @@ -129,8 +130,18 @@ int main IN char* args[] ) { - // Use UTF-8 for multi-byte character I/O everywhare - std::locale::global(std::locale("C.UTF-8")); + // Use "C.UTF-8" locale for multi-byte character I/O everywhare + // If "C.UTF-8" locale is not supported, use classic "C" locale as fallback. + std::locale loc; + try + { + loc = std::locale("C.UTF-8"); + } + catch ( std::runtime_error ) + { + loc = std::locale::classic(); + } + std::locale::global(loc); // convert all args to wchar_t's wchar_t** wargs = new wchar_t*[ argc ]; -- GitLab