Skip to content

Commit

Permalink
[Fix] mpt/string_transcode/transcode.hpp: Try to work-around Cygwin l…
Browse files Browse the repository at this point in the history
…ocale handling problems the same way we did in libopenmpt 0.5.x and earlier. See <https://cygwin.com/cgit/cygwin-packages/libopenmpt/tree/libopenmpt-0.7.12-1.src.patch?id=c4baa491e8a0975a1c7e0dfdf5ddf208d5b4ba6b>.

git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@22750 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
manxorist committed Jan 3, 2025
1 parent 4f81905 commit 036af51
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/mpt/string_transcode/transcode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "mpt/base/namespace.hpp"
#include "mpt/base/saturate_cast.hpp"
#include "mpt/detect/mfc.hpp"
#include "mpt/out_of_memory/out_of_memory.hpp"
#include "mpt/string/types.hpp"
#include "mpt/string/utility.hpp"

Expand Down Expand Up @@ -1694,10 +1695,60 @@ inline Tdststring encode(logical_encoding encoding, const mpt::widestring & src)
#elif !defined(MPT_COMPILER_QUIRK_NO_WCHAR)
switch (encoding) {
case logical_encoding::locale:
#if defined(MPT_LIBCXX_QUIRK_BROKEN_USER_LOCALE)
try {
return encode_locale<Tdststring>(std::locale(""), src);
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (...) {
// nothing
}
try {
return encode_locale<Tdststring>(std::locale(), src);
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (...) {
// nothing
}
try {
return encode_locale<Tdststring>(std::locale::classic(), src);
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (...) {
// nothing
}
return encode_ascii<Tdststring>(src);
#else
return encode_locale<Tdststring>(std::locale(""), src);
#endif
break;
case logical_encoding::active_locale:
#if defined(MPT_LIBCXX_QUIRK_BROKEN_ACTIVE_LOCALE)
try {
return encode_locale<Tdststring>(std::locale(), src);
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (...) {
// nothing
}
try {
return encode_locale<Tdststring>(std::locale(""), src);
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (...) {
// nothing
}
try {
return encode_locale<Tdststring>(std::locale::classic(), src);
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (...) {
// nothing
}
return encode_ascii<Tdststring>(src);
#else
return encode_locale<Tdststring>(std::locale(), src);
#endif
break;
}
throw std::domain_error("unsupported encoding");
Expand Down Expand Up @@ -1865,10 +1916,60 @@ inline mpt::widestring decode(logical_encoding encoding, const Tsrcstring & src)
#elif !defined(MPT_COMPILER_QUIRK_NO_WCHAR)
switch (encoding) {
case logical_encoding::locale:
#if defined(MPT_LIBCXX_QUIRK_BROKEN_USER_LOCALE)
try {
return decode_locale(std::locale(""), src);
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (...) {
// nothing
}
try {
return decode_locale(std::locale(), src);
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (...) {
// nothing
}
try {
return decode_locale(std::locale::classic(), src);
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (...) {
// nothing
}
return decode_ascii(src);
#else
return decode_locale(std::locale(""), src);
#endif
break;
case logical_encoding::active_locale:
#if defined(MPT_LIBCXX_QUIRK_BROKEN_USER_LOCALE)
try {
return decode_locale(std::locale(), src);
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (...) {
// nothing
}
try {
return decode_locale(std::locale(""), src);
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (...) {
// nothing
}
try {
return decode_locale(std::locale::classic(), src);
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (...) {
// nothing
}
return decode_ascii(src);
#else
return decode_locale(std::locale(), src);
#endif
break;
}
throw std::domain_error("unsupported encoding");
Expand Down

0 comments on commit 036af51

Please sign in to comment.