diff --git a/src/core/include/mp-units/bits/text_tools.h b/src/core/include/mp-units/bits/text_tools.h index f14e0f7d7..4af3762f2 100644 --- a/src/core/include/mp-units/bits/text_tools.h +++ b/src/core/include/mp-units/bits/text_tools.h @@ -33,8 +33,11 @@ import std; #else #include -#endif -#endif +#if __cpp_lib_text_encoding +#include +#endif // __cpp_lib_text_encoding +#endif // MP_UNITS_IMPORT_STD +#endif // MP_UNITS_IN_MODULE_INTERFACE namespace mp_units::detail { @@ -102,6 +105,11 @@ constexpr Out copy(const symbol_text& txt, character_set char_set, Out out if constexpr (is_same_v) return ::mp_units::detail::copy(txt.utf8().begin(), txt.utf8().end(), out); else if constexpr (is_same_v) { +#if __cpp_lib_text_encoding + if (std::text_encoding::literal().mib() != std::text_encoding::id::UTF8) + // fallback to portable mode + return ::mp_units::detail::copy(txt.portable().begin(), txt.portable().end(), out); +#endif for (const char8_t ch : txt.utf8()) *out++ = static_cast(ch); return out; } else diff --git a/src/core/include/mp-units/framework/symbol_text.h b/src/core/include/mp-units/framework/symbol_text.h index 71fc98b02..260f7e029 100644 --- a/src/core/include/mp-units/framework/symbol_text.h +++ b/src/core/include/mp-units/framework/symbol_text.h @@ -38,19 +38,8 @@ import std; #include // IWYU pragma: export #include #include -#endif -#endif - -#if __cpp_lib_text_encoding -#ifndef MP_UNITS_IN_MODULE_INTERFACE -#ifdef MP_UNITS_IMPORT_STD -import std; -#else -#include -#endif -#endif -static_assert(std::text_encoding::literal().mib() == std::text_encoding::id::UTF8); -#endif +#endif // MP_UNITS_IMPORT_STD +#endif // MP_UNITS_IN_MODULE_INTERFACE namespace mp_units {