Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
alabuzhev committed Nov 19, 2024
1 parent dfef86f commit e730f2a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
21 changes: 13 additions & 8 deletions far/exception_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -956,18 +956,23 @@ static handler_result ExcConsole(bool const CanContinue, string const& ReportLoc

static string get_locale()
{
wchar_t NameBuffer[LOCALE_NAME_MAX_LENGTH];
string_view Name;

if (size_t const SizeWith0 = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, LOCALE_SNAME, NameBuffer, static_cast<int>(std::size(NameBuffer))))
Name = { NameBuffer, SizeWith0 - 1 };
else
Name = L"Unknown"sv;
string LocaleName;
if (!os::get_locale_value(LOCALE_SYSTEM_DEFAULT, LOCALE_SNAME, LocaleName))
{
string LangName, CountryName;
if (
os::get_locale_value(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO639LANGNAME, LangName) &&
os::get_locale_value(LOCALE_SYSTEM_DEFAULT, LOCALE_SISO3166CTRYNAME, CountryName)
)
LocaleName = concat(LangName, L'-', CountryName);
else
LocaleName = L"Unknown"sv;
}

const auto LocaleId = GetUserDefaultLCID();
const auto LanguageId = LANGIDFROMLCID(LocaleId);
return far::format(L"{} | LCID={:08X} (Lang={:04X} (Primary={:03X} Sub={:02X}) Sort={:X} SortVersion={:X}) | ANSI={} OEM={}"sv,
Name,
LocaleName,
LocaleId,
LanguageId,
PRIMARYLANGID(LanguageId),
Expand Down
15 changes: 4 additions & 11 deletions far/platform.clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,18 +463,11 @@ namespace os::clipboard

static unsigned get_locale_codepage(LCID const Locale)
{
unsigned Acp;
const int SizeInChars = sizeof(Acp) / sizeof(wchar_t);

if (GetLocaleInfo(
Locale,
LOCALE_IDEFAULTANSICODEPAGE |
LOCALE_RETURN_NUMBER,
std::bit_cast<wchar_t*>(&Acp),
SizeInChars
) != SizeInChars)
int Acp;

if (!get_locale_value(Locale, LOCALE_IDEFAULTANSICODEPAGE, Acp))
{
LOGWARNING(L"GetLocaleInfo(LOCALE_IDEFAULTANSICODEPAGE): {}"sv, last_error());
LOGWARNING(L"get_locale_value(LOCALE_IDEFAULTANSICODEPAGE): {}"sv, last_error());
return 0;
}

Expand Down

0 comments on commit e730f2a

Please sign in to comment.