[FarGroup/FarManager] master: Use 'real' OEM and ANSI codepages in UTF-8 systems where appropriate (cb237d36f)

0 views
Skip to first unread message

farg...@farmanager.com

unread,
Jun 16, 2026, 5:15:59 PM (yesterday) Jun 16
to farco...@googlegroups.com
Repository : https://github.com/FarGroup/FarManager
On branch : master
Link : https://github.com/FarGroup/FarManager/commit/cb237d36f9b7cdce05a1107d810c68b6131c082d

>---------------------------------------------------------------

commit cb237d36f9b7cdce05a1107d810c68b6131c082d
Author: Alex Alabuzhev <alab...@gmail.com>
Date: Tue Jun 16 22:10:46 2026 +0100

Use 'real' OEM and ANSI codepages in UTF-8 systems where appropriate


>---------------------------------------------------------------

cb237d36f9b7cdce05a1107d810c68b6131c082d
far/PluginA.cpp | 24 ++++++++++++------------
far/codepage.cpp | 42 +++++++++++++++++++++++++++++++++++++-----
far/codepage.hpp | 7 +++++++
far/codepage_selection.cpp | 40 +++++++++++-----------------------------
far/config.cpp | 4 ++--
far/dizlist.cpp | 6 +++---
far/encoding.cpp | 6 +++---
far/exception_handler.cpp | 7 ++++---
far/fileedit.cpp | 2 +-
far/filestr.cpp | 2 +-
far/findfile.cpp | 18 +++---------------
far/fnparse.cpp | 4 ++--
far/language.cpp | 4 ++--
far/locale.cpp | 4 ++--
far/map_file.cpp | 2 +-
far/platform.cpp | 4 ++++
far/strmix.cpp | 4 ++--
far/usermenu.cpp | 4 ++--
far/viewer.cpp | 2 +-
19 files changed, 100 insertions(+), 86 deletions(-)

diff --git a/far/PluginA.cpp b/far/PluginA.cpp
index 02fd636b6..166311142 100644
--- a/far/PluginA.cpp
+++ b/far/PluginA.cpp
@@ -1418,7 +1418,7 @@ static uintptr_t GetEditorCodePageA()
CPINFO cpi;

if (!GetCPInfo(static_cast<unsigned>(CodePage), &cpi) || cpi.MaxCharSize > 1)
- CodePage = encoding::codepage::ansi();
+ CodePage = encoding::codepage::real_ansi();

return CodePage;
}
@@ -1427,10 +1427,10 @@ static int GetEditorCodePageFavA()
{
const auto CodePage = GetEditorCodePageA();

- if (encoding::codepage::oem() == CodePage)
+ if (CodePage == encoding::codepage::real_oem())
return 0;

- if (encoding::codepage::ansi() == CodePage)
+ if (CodePage == encoding::codepage::real_ansi())
return 1;

auto result = -(static_cast<int>(CodePage) + 2);
@@ -1474,11 +1474,11 @@ static uintptr_t ConvertCharTableToCodePage(int Command)
switch (Command)
{
case 0:
- nCP = encoding::codepage::oem();
+ nCP = encoding::codepage::real_oem();
break;

case 1:
- nCP = encoding::codepage::ansi();
+ nCP = encoding::codepage::real_ansi();
break;

default:
@@ -4065,8 +4065,8 @@ static int WINAPI FarEditorControlA(oldfar::EDITOR_CONTROL_COMMANDS OldCommand,
const auto ect = static_cast<const oldfar::EditorConvertText*>(Param);
const auto CodePage = GetEditorCodePageA();
MultiByteRecode(
- OldCommand == oldfar::ECTL_OEMTOEDITOR? encoding::codepage::oem() : CodePage,
- OldCommand == oldfar::ECTL_OEMTOEDITOR? CodePage : encoding::codepage::oem(),
+ OldCommand == oldfar::ECTL_OEMTOEDITOR? encoding::codepage::real_oem() : CodePage,
+ OldCommand == oldfar::ECTL_OEMTOEDITOR? CodePage : encoding::codepage::real_oem(),
{ ect->Text, static_cast<size_t>(ect->TextLength) });
return TRUE;
}
@@ -4196,10 +4196,10 @@ static int WINAPI FarEditorControlA(oldfar::EDITOR_CONTROL_COMMANDS OldCommand,
switch (oldsp->iParam)
{
case 1:
- newsp.iParam = encoding::codepage::oem();
+ newsp.iParam = encoding::codepage::real_oem();
break;
case 2:
- newsp.iParam = encoding::codepage::ansi();
+ newsp.iParam = encoding::codepage::real_ansi();
break;
default:
newsp.iParam=oldsp->iParam;
@@ -4456,7 +4456,7 @@ static int WINAPI FarViewerControlA(int Command, void* Param) noexcept
viA->TabSize = viW.TabSize;
viA->CurMode.UseDecodeTable = 0;
viA->CurMode.TableNum = 0;
- viA->CurMode.AnsiMode = viW.CurMode.CodePage == encoding::codepage::ansi();
+ viA->CurMode.AnsiMode = viW.CurMode.CodePage == encoding::codepage::real_ansi();
viA->CurMode.Unicode = IsUtf16CodePage(viW.CurMode.CodePage);
viA->CurMode.Wrap = (viW.CurMode.Flags&VMF_WRAP)?1:0;
viA->CurMode.WordWrap = (viW.CurMode.Flags&VMF_WORDWRAP)?1:0;
@@ -4585,8 +4585,8 @@ static int WINAPI FarCharTableA(int Command, char *Buffer, int BufferSize) noexc
inplace::upper({ us.get(), std::size(TableSet.DecodeTable) });
(void)encoding::get_bytes(nCP, { us.get(), std::size(TableSet.DecodeTable) }, { std::bit_cast<char*>(&TableSet.UpperTable), std::size(TableSet.DecodeTable) });

- MultiByteRecode(nCP, encoding::codepage::oem(), { std::bit_cast<char*>(&TableSet.DecodeTable), std::size(TableSet.DecodeTable) });
- MultiByteRecode(encoding::codepage::oem(), nCP, { std::bit_cast<char*>(&TableSet.EncodeTable), std::size(TableSet.EncodeTable) });
+ MultiByteRecode(nCP, encoding::codepage::real_oem(), { std::bit_cast<char*>(&TableSet.DecodeTable), std::size(TableSet.DecodeTable) });
+ MultiByteRecode(encoding::codepage::real_oem(), nCP, { std::bit_cast<char*>(&TableSet.EncodeTable), std::size(TableSet.EncodeTable) });
return Command;
}
return -1;
diff --git a/far/codepage.cpp b/far/codepage.cpp
index 4a1447da9..8b161a01f 100644
--- a/far/codepage.cpp
+++ b/far/codepage.cpp
@@ -56,12 +56,44 @@ uintptr_t encoding::codepage::detail::utf8::id()

uintptr_t encoding::codepage::detail::ansi::id()
{
- return GetACP();
+ static const auto Result = GetACP();
+ return Result;
}

uintptr_t encoding::codepage::detail::oem::id()
{
- return GetOEMCP();
+ static const auto Result = GetOEMCP();
+ return Result;
+}
+
+uintptr_t encoding::codepage::is_system_utf8()
+{
+ static const auto Result = ansi() == utf8() && oem() == utf8();
+ return Result;
+}
+
+uintptr_t encoding::codepage::real_ansi()
+{
+ static const auto Result = []
+ {
+ if (is_system_utf8())
+ if (int Value; os::get_locale_value(LOCALE_USER_DEFAULT, LOCALE_IUSEUTF8LEGACYACP, Value))
+ return static_cast<uintptr_t>(Value);
+ return ansi();
+ }();
+ return Result;
+}
+
+uintptr_t encoding::codepage::real_oem()
+{
+ static const auto Result = []
+ {
+ if (is_system_utf8())
+ if (int Value; os::get_locale_value(LOCALE_USER_DEFAULT, LOCALE_IUSEUTF8LEGACYOEMCP, Value))
+ return static_cast<uintptr_t>(Value);
+ return oem();
+ }();
+ return Result;
}

uintptr_t encoding::codepage::normalise(uintptr_t const Codepage)
@@ -209,7 +241,7 @@ bool IsUtf16CodePage(uintptr_t cp)

bool IsStandardCodePage(uintptr_t cp)
{
- return IsUtfCodePage(cp) || cp == encoding::codepage::ansi() || cp == encoding::codepage::oem();
+ return IsUtfCodePage(cp) || cp == encoding::codepage::real_ansi() || cp == encoding::codepage::real_oem();
}

bool IsUtfCodePage(uintptr_t cp)
@@ -226,8 +258,8 @@ string ShortReadableCodepageName(uintptr_t cp)
case CP_UTF16LE: return L"U16LE"s;
case CP_UTF16BE: return L"U16BE"s;
default: return
- cp == encoding::codepage::ansi()? L"ANSI"s :
- cp == encoding::codepage::oem()? L"OEM"s :
+ cp == encoding::codepage::real_ansi()? L"ANSI"s :
+ cp == encoding::codepage::real_oem()? L"OEM"s :
str(cp);
}
}
diff --git a/far/codepage.hpp b/far/codepage.hpp
index d53ab4fb7..991737826 100644
--- a/far/codepage.hpp
+++ b/far/codepage.hpp
@@ -55,6 +55,13 @@ namespace encoding::codepage
[[nodiscard]] inline uintptr_t ansi() { return detail::ansi::id(); }
[[nodiscard]] inline uintptr_t oem() { return detail::oem::id(); }

+ [[nodiscard]] inline uintptr_t is_system_utf8();
+
+ // Rule of thumb: everywhere a codepage is exposed to the user, use real_ansi() and real_oem() instead of ansi() and oem().
+ // Everywhere a codepage is used internally, e.g. for communication with the OS, plugins etc., use encoding::ansi::get_* and encoding::oem::get_* functions.
+ [[nodiscard]] inline uintptr_t real_ansi();
+ [[nodiscard]] inline uintptr_t real_oem();
+
[[nodiscard]] uintptr_t normalise(uintptr_t Codepage);
}

diff --git a/far/codepage_selection.cpp b/far/codepage_selection.cpp
index a3aa3d575..698fae138 100644
--- a/far/codepage_selection.cpp
+++ b/far/codepage_selection.cpp
@@ -345,31 +345,13 @@ void codepages::AddCodePages(DWORD codePages)
return concat(SystemName, L" - "sv, Info->Name);
};

- const auto AnsiCp = encoding::codepage::ansi();
+ AddSeparator(msg(lng::MGetCodePageSystem));

- bool SeparatorAdded = false;
- const auto AddSeparatorIfNeeded = [&]
- {
- if (SeparatorAdded)
- return;
-
- AddSeparator(msg(lng::MGetCodePageSystem));
- SeparatorAdded = true;
- };
-
- // Windows 10-specific madness
- if (AnsiCp != CP_UTF8)
- {
- AddSeparatorIfNeeded();
- AddStandardCodePage(GetSystemCodepageName(AnsiCp, L"ANSI"sv), AnsiCp);
- }
+ const auto AnsiCp = encoding::codepage::real_ansi();
+ AddStandardCodePage(GetSystemCodepageName(AnsiCp, L"ANSI"sv), AnsiCp);

- const auto OemCp = encoding::codepage::oem();
- if (OemCp != AnsiCp && OemCp != CP_UTF8)
- {
- AddSeparatorIfNeeded();
- AddStandardCodePage(GetSystemCodepageName(OemCp, L"OEM"sv), OemCp);
- }
+ const auto OemCp = encoding::codepage::real_oem();
+ AddStandardCodePage(GetSystemCodepageName(OemCp, L"OEM"sv), OemCp);
}

// unicode codepages
@@ -922,9 +904,9 @@ F8CP::F8CP(bool viewer):

uintptr_t cp;
if (equal_icase(i, L"ansi"sv) || equal_icase(i, L"acp"sv) || equal_icase(i, L"win"sv))
- cp = encoding::codepage::ansi();
+ cp = encoding::codepage::real_ansi();
else if (equal_icase(i, L"oem"sv) || equal_icase(i, L"oemcp"sv) || equal_icase(i, L"dos"sv))
- cp = encoding::codepage::oem();
+ cp = encoding::codepage::real_oem();
else if (equal_icase(i, L"utf8"sv) || equal_icase(i, L"utf-8"sv))
cp = CP_UTF8;
else if (equal_icase(i, L"default"sv))
@@ -944,8 +926,8 @@ F8CP::F8CP(bool viewer):
}
if (m_F8CpOrder.empty())
{
- const uintptr_t acp = encoding::codepage::ansi();
- const uintptr_t oemcp = encoding::codepage::oem();
+ const auto acp = encoding::codepage::real_ansi();
+ const auto oemcp = encoding::codepage::real_oem();

if (cps != L"-1"sv)
defcp = acp;
@@ -966,10 +948,10 @@ uintptr_t F8CP::NextCP(uintptr_t cp) const
string F8CP::NextCPname(uintptr_t cp) const
{
const auto next_cp = NextCP(cp);
- if (next_cp == encoding::codepage::ansi())
+ if (next_cp == encoding::codepage::real_ansi())
return m_AcpName;

- if (next_cp == encoding::codepage::oem())
+ if (next_cp == encoding::codepage::real_oem())
return m_OemName;

if (next_cp == CP_UTF8)
diff --git a/far/config.cpp b/far/config.cpp
index d2ccda6a1..c0dd18570 100644
--- a/far/config.cpp
+++ b/far/config.cpp
@@ -1984,7 +1984,7 @@ void Options::InitConfigsData()
{FSSF_PRIVATE, NKeyEditor, L"AutoIndent"sv, EdOpt.AutoIndent, false},
{FSSF_PRIVATE, NKeyEditor, L"BSLikeDel"sv, EdOpt.BSLikeDel, true},
{FSSF_PRIVATE, NKeyEditor, L"CharCodeBase"sv, EdOpt.CharCodeBase, 1},
- {FSSF_PRIVATE, NKeyEditor, L"DefaultCodePage"sv, EdOpt.DefaultCodePage, encoding::codepage::ansi()},
+ {FSSF_PRIVATE, NKeyEditor, L"DefaultCodePage"sv, EdOpt.DefaultCodePage, CP_DEFAULT},
{FSSF_PRIVATE, NKeyEditor, L"F8CPs"sv, EdOpt.strF8CPs, L""sv},
{FSSF_PRIVATE, NKeyEditor, L"DelRemovesBlocks"sv, EdOpt.DelRemovesBlocks, true},
{FSSF_PRIVATE, NKeyEditor, L"EditOpenedForWrite"sv, EdOpt.EditOpenedForWrite, true},
@@ -2224,7 +2224,7 @@ void Options::InitConfigsData()
{FSSF_PRIVATE, NKeySystemExecutor, L"ComspecCondition"sv, Exec.ComspecCondition, L""sv},
{FSSF_PRIVATE, NKeySystemExecutor, L"UseAssociations"sv, Exec.UseAssociations, false},
{FSSF_PRIVATE, NKeyViewer, L"AutoDetectCodePage"sv, ViOpt.AutoDetectCodePage, true},
- {FSSF_PRIVATE, NKeyViewer, L"DefaultCodePage"sv, ViOpt.DefaultCodePage, encoding::codepage::ansi()},
+ {FSSF_PRIVATE, NKeyViewer, L"DefaultCodePage"sv, ViOpt.DefaultCodePage, CP_DEFAULT},
{FSSF_PRIVATE, NKeyViewer, L"DetectDumpMode"sv, ViOpt.DetectDumpMode, true},
{FSSF_PRIVATE, NKeyViewer, L"ExternalViewerName"sv, strExternalViewer, L""sv},
{FSSF_PRIVATE, NKeyViewer, L"F8CPs"sv, ViOpt.strF8CPs, L""sv},
diff --git a/far/dizlist.cpp b/far/dizlist.cpp
index 1ec2b1c5e..940879e91 100644
--- a/far/dizlist.cpp
+++ b/far/dizlist.cpp
@@ -89,7 +89,7 @@ void DizList::Read(string_view const Path, const string* DizName)

const time_check TimeCheck;

- const auto CodePage = GetFileCodepage(DizFile, Global->Opt->Diz.AnsiByDefault? encoding::codepage::ansi() : encoding::codepage::oem(), nullptr, false);
+ const auto CodePage = GetFileCodepage(DizFile, Global->Opt->Diz.AnsiByDefault? encoding::codepage::real_ansi() : encoding::codepage::real_oem(), nullptr, false);

auto LastAdded = m_DizData.end();
string DizText;
@@ -355,8 +355,8 @@ bool DizList::Flush(string_view const Path, const string* DizName)
Global->Opt->Diz.SaveInUTF?
CP_UTF8 :
Global->Opt->Diz.AnsiByDefault?
- encoding::codepage::ansi() :
- encoding::codepage::oem();
+ encoding::codepage::real_ansi() :
+ encoding::codepage::real_oem();
}

// Encoding could fail, so we need to prepare the data before touching the file
diff --git a/far/encoding.cpp b/far/encoding.cpp
index 606be3905..929563cdb 100644
--- a/far/encoding.cpp
+++ b/far/encoding.cpp
@@ -610,7 +610,7 @@ size_t encoding::get_chars_count(uintptr_t const Codepage, bytes_view const Str,
string encoding::utf8_or_ansi::get_chars(std::string_view const Str, diagnostics* const Diagnostics)
{
const auto Utf8 = codepage::utf8();
- const auto Ansi = codepage::ansi();
+ const auto Ansi = codepage::real_ansi();

const auto Encoding = Utf8 == Ansi || is_valid_utf8(Str, false) == is_utf8::yes?
Utf8 :
@@ -1556,8 +1556,8 @@ TEST_CASE("encoding.basic")
std::array const Codepages
{
encoding::codepage::utf8(),
- encoding::codepage::ansi(),
- encoding::codepage::oem()
+ encoding::codepage::real_ansi(),
+ encoding::codepage::real_oem()
};

for (const auto& Codepage: Codepages)
diff --git a/far/exception_handler.cpp b/far/exception_handler.cpp
index 228d333c9..510ef4223 100644
--- a/far/exception_handler.cpp
+++ b/far/exception_handler.cpp
@@ -984,7 +984,7 @@ static string get_locale()

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,
+ return far::format(L"{} | LCID={:08X} (Lang={:04X} (Primary={:03X} Sub={:02X}) Sort={:X} SortVersion={:X}) | ANSI={} OEM={}{}"sv,
LocaleName,
LocaleId,
LanguageId,
@@ -992,8 +992,9 @@ static string get_locale()
SUBLANGID(LanguageId),
SORTIDFROMLCID(LocaleId),
SORTVERSIONFROMLCID(LocaleId),
- encoding::codepage::ansi(),
- encoding::codepage::oem()
+ encoding::codepage::real_ansi(),
+ encoding::codepage::real_oem(),
+ encoding::codepage::is_system_utf8()? L" UTF-8"sv : L""sv
);
}

diff --git a/far/fileedit.cpp b/far/fileedit.cpp
index e7b5aaf99..7eccc34fd 100644
--- a/far/fileedit.cpp
+++ b/far/fileedit.cpp
@@ -2760,7 +2760,7 @@ uintptr_t FileEditor::GetDefaultCodePage()
{
const auto cp = encoding::codepage::normalise(Global->Opt->EdOpt.DefaultCodePage);
return cp == CP_DEFAULT || !IsCodePageSupported(cp)?
- encoding::codepage::ansi() :
+ encoding::codepage::ansi() : // NOT real_ansi. If the user set the whole system to UTF-8, he probably wants it by default everywhere, including the editor.
cp;
}

diff --git a/far/filestr.cpp b/far/filestr.cpp
index 66fc7443c..c04ac9966 100644
--- a/far/filestr.cpp
+++ b/far/filestr.cpp
@@ -550,7 +550,7 @@ uintptr_t GetFileCodepage(const os::fs::file& File, uintptr_t DefaultCodepage, b

Codepage =
(NotUTF8 && DefaultCodepage == CP_UTF8) || (NotUTF16 && IsUtf16CodePage(DefaultCodepage))?
- encoding::codepage::ansi() :
+ encoding::codepage::real_ansi() :
DefaultCodepage;
}

diff --git a/far/findfile.cpp b/far/findfile.cpp
index 3e7fcac02..53dabb633 100644
--- a/far/findfile.cpp
+++ b/far/findfile.cpp
@@ -530,20 +530,8 @@ void background_searcher::InitInFileSearch()
else
{
// system codepages
-
- // Windows 10-specific madness
- const auto AnsiCp = encoding::codepage::ansi();
- if (AnsiCp != CP_UTF8)
- {
- m_CodePages.emplace_back(AnsiCp);
- }
-
- const auto OemCp = encoding::codepage::oem();
- if (OemCp != AnsiCp && OemCp != CP_UTF8)
- {
- m_CodePages.emplace_back(OemCp);
- }
-
+ m_CodePages.emplace_back(encoding::codepage::real_ansi());
+ m_CodePages.emplace_back(encoding::codepage::real_oem());
m_CodePages.emplace_back(CP_UTF8);
m_CodePages.emplace_back(CP_UTF16LE);
m_CodePages.emplace_back(CP_UTF16BE);
@@ -1023,7 +1011,7 @@ bool background_searcher::LookForString(string_view const FileName)

if (m_Autodetection)
{
- m_CodePages.front().CodePage = GetFileCodepage(File, encoding::codepage::ansi());
+ m_CodePages.front().CodePage = GetFileCodepage(File, encoding::codepage::real_ansi());
m_CodePages.front().initialize();
m_MaxCharSize = m_CodePages.front().MaxCharSize;
}
diff --git a/far/fnparse.cpp b/far/fnparse.cpp
index 9b24838af..3490e766d 100644
--- a/far/fnparse.cpp
+++ b/far/fnparse.cpp
@@ -300,7 +300,7 @@ static size_t SkipInputToken(string_view const Str, subst_strings* const Strings

static void MakeListFile(panel_ptr const& Panel, string& ListFileName, bool const ShortNames, string_view const Modifers)
{
- auto CodePage = encoding::codepage::oem();
+ auto CodePage = encoding::codepage::real_oem();
bool UseFullPaths{}, QuotePaths{}, UseForwardSlash{};

for (const auto& i: Modifers)
@@ -308,7 +308,7 @@ static void MakeListFile(panel_ptr const& Panel, string& ListFileName, bool cons
switch (i)
{
case L'A':
- CodePage = encoding::codepage::ansi();
+ CodePage = encoding::codepage::real_ansi();
break;

case L'U':
diff --git a/far/language.cpp b/far/language.cpp
index 735c5fd4e..97cfb35ac 100644
--- a/far/language.cpp
+++ b/far/language.cpp
@@ -74,7 +74,7 @@ static lang_file open_impl(string_view const FileName, bool const IsHelp)
if (!Result.File.Open(FileName, FILE_READ_DATA, os::fs::file_share_read, nullptr, OPEN_EXISTING, IsHelp? FILE_FLAG_RANDOM_ACCESS : FILE_FLAG_SEQUENTIAL_SCAN))
return {};

- Result.Codepage = GetFileCodepage(Result.File, encoding::codepage::oem(), nullptr, false);
+ Result.Codepage = GetFileCodepage(Result.File, encoding::codepage::real_oem(), nullptr, false);
Result.TryUtf8 = !IsUtfCodePage(Result.Codepage);

string Language;
@@ -337,7 +337,7 @@ static void LoadCustomStrings(string_view const FileName, unordered_string_map<s
if (!CustomFile)
return;

- const auto CustomFileCodepage = GetFileCodepage(CustomFile, encoding::codepage::oem(), nullptr, false);
+ const auto CustomFileCodepage = GetFileCodepage(CustomFile, encoding::codepage::real_oem(), nullptr, false);
auto TryUtf8 = !IsUtfCodePage(CustomFileCodepage);

string SavedLabel;
diff --git a/far/locale.cpp b/far/locale.cpp
index c46c03cdf..c234ccd62 100644
--- a/far/locale.cpp
+++ b/far/locale.cpp
@@ -74,8 +74,8 @@ static auto get_is_cjk()
{
return
any_of(extract_integer<BYTE, 0>(GetUserDefaultLCID()), LANG_CHINESE, LANG_JAPANESE, LANG_KOREAN) ||
- is_cjk_codepage(encoding::codepage::oem()) ||
- is_cjk_codepage(encoding::codepage::ansi()) ||
+ is_cjk_codepage(encoding::codepage::real_oem()) ||
+ is_cjk_codepage(encoding::codepage::real_ansi()) ||
is_cjk_codepage(console.GetOutputCodepage());
}

diff --git a/far/map_file.cpp b/far/map_file.cpp
index 1cca19a60..a1d8e0676 100644
--- a/far/map_file.cpp
+++ b/far/map_file.cpp
@@ -234,7 +234,7 @@ static void read_vc(std::istream& Stream, map_file::data& Data)

uintptr_t BaseAddress{};

- for (const auto& i: enum_lines(Stream, encoding::codepage::ansi()))
+ for (const auto& i: enum_lines(Stream, encoding::codepage::real_ansi()))
{
if (i.Str.empty())
continue;
diff --git a/far/platform.cpp b/far/platform.cpp
index 24893a0ac..d5286590d 100644
--- a/far/platform.cpp
+++ b/far/platform.cpp
@@ -522,6 +522,10 @@ string GetPrivateProfileString(string_view const AppName, string_view const KeyN
}))
return {};

+ // If the system is in UTF-8 mode it's either already good or broken beyond repair
+ if (encoding::codepage::is_system_utf8())
+ return Value;
+
// GetPrivateProfileStringW doesn't work with UTF-8 and interprets it as ANSI.
// We try to re-convert if possible.

diff --git a/far/strmix.cpp b/far/strmix.cpp
index 546baeebe..8404b3ec0 100644
--- a/far/strmix.cpp
+++ b/far/strmix.cpp
@@ -1393,7 +1393,7 @@ string ExtractHexString(string_view const HexString)

string ConvertHexString(string_view const From, uintptr_t Codepage, bool FromHex)
{
- const auto CompatibleCp = IsVirtualCodePage(Codepage)? encoding::codepage::ansi() : Codepage;
+ const auto CompatibleCp = IsVirtualCodePage(Codepage)? encoding::codepage::real_ansi() : Codepage;
if (FromHex)
{
const auto Blob = HexStringToBlob(ExtractHexString(From), 0);
@@ -1408,7 +1408,7 @@ string ConvertHexString(string_view const From, uintptr_t Codepage, bool FromHex

string BytesToString(bytes_view const Bytes, uintptr_t const Codepage)
{
- return encoding::get_chars(IsVirtualCodePage(Codepage)? encoding::codepage::ansi() : Codepage, Bytes);
+ return encoding::get_chars(IsVirtualCodePage(Codepage)? encoding::codepage::real_ansi() : Codepage, Bytes);
}

string HexMask(size_t ByteCount)
diff --git a/far/usermenu.cpp b/far/usermenu.cpp
index 3206ec2d3..f05fe86c4 100644
--- a/far/usermenu.cpp
+++ b/far/usermenu.cpp
@@ -258,14 +258,14 @@ static void ParseMenu(UserMenu::menu_container& Menu, std::ranges::subrange<enum

static void DeserializeMenu(UserMenu::menu_container& Menu, const os::fs::file& File, uintptr_t& Codepage)
{
- Codepage = GetFileCodepage(File, encoding::codepage::oem());
+ Codepage = GetFileCodepage(File, encoding::codepage::real_oem());

os::fs::filebuf StreamBuffer(File, std::ios::in);
std::istream Stream(&StreamBuffer);
Stream.exceptions(Stream.badbit | Stream.failbit);

enum_lines EnumFileLines(Stream, Codepage);
- ParseMenu(Menu, EnumFileLines, Codepage == encoding::codepage::oem());
+ ParseMenu(Menu, EnumFileLines, Codepage == encoding::codepage::real_oem());

if (!IsUtfCodePage(Codepage))
{
diff --git a/far/viewer.cpp b/far/viewer.cpp
index c506510c6..0b5c0a476 100644
--- a/far/viewer.cpp
+++ b/far/viewer.cpp
@@ -4165,7 +4165,7 @@ uintptr_t Viewer::GetDefaultCodePage()
{
const auto cp = encoding::codepage::normalise(Global->Opt->ViOpt.DefaultCodePage);
return cp == CP_DEFAULT || !is_code_page_supported_in_viewer(cp)?
- encoding::codepage::ansi() :
+ encoding::codepage::ansi() : // NOT real_ansi. If the user set the whole system to UTF-8, he probably wants it by default everywhere, including the viewer.
cp;
}



Reply all
Reply to author
Forward
0 new messages