/* SPDX-License-Identifier: BSL-1.0 OR BSD-3-Clause */ #ifndef MPT_FORMAT_HELPERS_HPP #define MPT_FORMAT_HELPERS_HPP #include "mpt/base/detect.hpp" #include "mpt/base/namespace.hpp" #include "mpt/string/types.hpp" #include "mpt/string_transcode/transcode.hpp" #include #include namespace mpt { inline namespace MPT_INLINE_NS { template inline Tdststring convert_formatted_simple(const Tsrcstring & src) { if constexpr (std::is_same::value) { return src; } else { Tdststring dst; dst.reserve(src.length()); for (std::size_t i = 0; i < src.length(); ++i) { dst.push_back(mpt::unsafe_char_convert(src[i])); } return dst; } } template struct select_format_char_type { using type = char; }; #if !defined(MPT_COMPILER_QUIRK_NO_WCHAR) template <> struct select_format_char_type { using type = wchar_t; }; #if MPT_USTRING_MODE_WIDE #if MPT_CXX_AT_LEAST(20) template <> struct select_format_char_type { using type = wchar_t; }; #endif // C++20 template <> struct select_format_char_type { using type = wchar_t; }; template <> struct select_format_char_type { using type = wchar_t; }; #endif // MPT_USTRING_MODE_WIDE #endif // !MPT_COMPILER_QUIRK_NO_WCHAR template struct select_format_string_type { using type = mpt::ustring; }; template <> struct select_format_string_type { using type = std::string; }; #if !defined(MPT_COMPILER_QUIRK_NO_WCHAR) template <> struct select_format_string_type { using type = std::wstring; }; #endif // !MPT_COMPILER_QUIRK_NO_WCHAR #if MPT_CXX_AT_LEAST(20) template <> struct select_format_string_type { using type = std::u8string; }; #endif // C++20 template <> struct select_format_string_type { using type = std::u16string; }; template <> struct select_format_string_type { using type = std::u32string; }; } // namespace MPT_INLINE_NS } // namespace mpt #endif // MPT_FORMAT_HELPERS_HPP