diff --git a/include/SFML/System/Utf.hpp b/include/SFML/System/Utf.hpp index f4a9931ae..130680bd6 100644 --- a/include/SFML/System/Utf.hpp +++ b/include/SFML/System/Utf.hpp @@ -44,698 +44,684 @@ template OutputIt copy(InputIt first, InputIt last, OutputIt dFirst); } -template -class Utf; - //////////////////////////////////////////////////////////// -/// \brief Specialization of the Utf template for UTF-8 +/// \brief UTF-8 string conversion functions /// //////////////////////////////////////////////////////////// -template <> -class Utf<8> +namespace Utf8 { -public: - //////////////////////////////////////////////////////////// - /// \brief Decode a single UTF-8 character - /// - /// Decoding a character means finding its unique 32-bits - /// code (called the codepoint) in the Unicode standard. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Codepoint of the decoded UTF-8 character - /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static In decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-8 character - /// - /// Encoding a character means converting a unique 32-bits - /// code (called the codepoint) in the target encoding, UTF-8. - /// - /// \param input Codepoint to encode as UTF-8 - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to UTF-8 (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out encode(std::uint32_t input, Out output, std::uint8_t replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Advance to the next UTF-8 character - /// - /// This function is necessary for multi-elements encodings, as - /// a single character may use more than 1 storage element. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static In next(In begin, In end); - - //////////////////////////////////////////////////////////// - /// \brief Count the number of characters of a UTF-8 sequence - /// - /// This function is necessary for multi-elements encodings, as - /// a single character may use more than 1 storage element, thus the - /// total size can be different from (begin - end). - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static std::size_t count(In begin, In end); - - //////////////////////////////////////////////////////////// - /// \brief Convert an ANSI characters range to UTF-8 - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = {}); - - //////////////////////////////////////////////////////////// - /// \brief Convert a wide characters range to UTF-8 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out fromWide(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-8 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out fromLatin1(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-8 characters range to ANSI characters - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = {}); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-8 characters range to wide characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toWide(In begin, In end, Out output, wchar_t replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toLatin1(In begin, In end, Out output, char replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-8 characters range to UTF-8 - /// - /// This functions does nothing more than a direct copy; - /// it is defined only to provide the same interface as other - /// specializations of the sf::Utf<> template, and allow - /// generic code to be written on top of it. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toUtf8(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-8 characters range to UTF-16 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toUtf16(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-8 characters range to UTF-32 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toUtf32(In begin, In end, Out output); -}; - //////////////////////////////////////////////////////////// -/// \brief Specialization of the Utf template for UTF-16 +/// \brief Decode a single UTF-8 character +/// +/// Decoding a character means finding its unique 32-bits +/// code (called the codepoint) in the Unicode standard. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Codepoint of the decoded UTF-8 character +/// \param replacement Replacement character to use in case the UTF-8 sequence is invalid +/// +/// \return Iterator pointing to one past the last read element of the input sequence /// //////////////////////////////////////////////////////////// -template <> -class Utf<16> -{ -public: - //////////////////////////////////////////////////////////// - /// \brief Decode a single UTF-16 character - /// - /// Decoding a character means finding its unique 32-bits - /// code (called the codepoint) in the Unicode standard. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Codepoint of the decoded UTF-16 character - /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static In decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-16 character - /// - /// Encoding a character means converting a unique 32-bits - /// code (called the codepoint) in the target encoding, UTF-16. - /// - /// \param input Codepoint to encode as UTF-16 - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to UTF-16 (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out encode(std::uint32_t input, Out output, std::uint16_t replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Advance to the next UTF-16 character - /// - /// This function is necessary for multi-elements encodings, as - /// a single character may use more than 1 storage element. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static In next(In begin, In end); - - //////////////////////////////////////////////////////////// - /// \brief Count the number of characters of a UTF-16 sequence - /// - /// This function is necessary for multi-elements encodings, as - /// a single character may use more than 1 storage element, thus the - /// total size can be different from (begin - end). - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static std::size_t count(In begin, In end); - - //////////////////////////////////////////////////////////// - /// \brief Convert an ANSI characters range to UTF-16 - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = {}); - - //////////////////////////////////////////////////////////// - /// \brief Convert a wide characters range to UTF-16 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out fromWide(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-16 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out fromLatin1(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-16 characters range to ANSI characters - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = {}); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-16 characters range to wide characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toWide(In begin, In end, Out output, wchar_t replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toLatin1(In begin, In end, Out output, char replacement = 0); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-16 characters range to UTF-8 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toUtf8(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-16 characters range to UTF-16 - /// - /// This functions does nothing more than a direct copy; - /// it is defined only to provide the same interface as other - /// specializations of the sf::Utf<> template, and allow - /// generic code to be written on top of it. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toUtf16(In begin, In end, Out output); - - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-16 characters range to UTF-32 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toUtf32(In begin, In end, Out output); -}; +template +In decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement = 0); //////////////////////////////////////////////////////////// -/// \brief Specialization of the Utf template for UTF-32 +/// \brief Encode a single UTF-8 character +/// +/// Encoding a character means converting a unique 32-bits +/// code (called the codepoint) in the target encoding, UTF-8. +/// +/// \param input Codepoint to encode as UTF-8 +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement for characters not convertible to UTF-8 (use 0 to skip them) +/// +/// \return Iterator to the end of the output sequence which has been written /// //////////////////////////////////////////////////////////// -template <> -class Utf<32> +template +Out encode(std::uint32_t input, Out output, std::uint8_t replacement = 0); + +//////////////////////////////////////////////////////////// +/// \brief Advance to the next UTF-8 character +/// +/// This function is necessary for multi-elements encodings, as +/// a single character may use more than 1 storage element. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// +/// \return Iterator pointing to one past the last read element of the input sequence +/// +//////////////////////////////////////////////////////////// +template +In next(In begin, In end); + +//////////////////////////////////////////////////////////// +/// \brief Count the number of characters of a UTF-8 sequence +/// +/// This function is necessary for multi-elements encodings, as +/// a single character may use more than 1 storage element, thus the +/// total size can be different from (begin - end). +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// +/// \return Iterator pointing to one past the last read element of the input sequence +/// +//////////////////////////////////////////////////////////// +template +std::size_t count(In begin, In end); + +//////////////////////////////////////////////////////////// +/// \brief Convert an ANSI characters range to UTF-8 +/// +/// The current global locale will be used by default, unless you +/// pass a custom one in the \a locale parameter. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param locale Locale to use for conversion +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out fromAnsi(In begin, In end, Out output, const std::locale& locale = {}); + +//////////////////////////////////////////////////////////// +/// \brief Convert a wide characters range to UTF-8 +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out fromWide(In begin, In end, Out output); + +//////////////////////////////////////////////////////////// +/// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-8 +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out fromLatin1(In begin, In end, Out output); + +//////////////////////////////////////////////////////////// +/// \brief Convert an UTF-8 characters range to ANSI characters +/// +/// The current global locale will be used by default, unless you +/// pass a custom one in the \a locale parameter. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) +/// \param locale Locale to use for conversion +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = {}); + +//////////////////////////////////////////////////////////// +/// \brief Convert an UTF-8 characters range to wide characters +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toWide(In begin, In end, Out output, wchar_t replacement = 0); + +//////////////////////////////////////////////////////////// +/// \brief Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toLatin1(In begin, In end, Out output, char replacement = 0); + +//////////////////////////////////////////////////////////// +/// \brief Convert a UTF-8 characters range to UTF-8 +/// +/// This functions does nothing more than a direct copy; +/// it is defined only to provide the same interface as other +/// specializations of the sf::Utf<> template, and allow +/// generic code to be written on top of it. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toUtf8(In begin, In end, Out output); + +//////////////////////////////////////////////////////////// +/// \brief Convert a UTF-8 characters range to UTF-16 +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toUtf16(In begin, In end, Out output); + +//////////////////////////////////////////////////////////// +/// \brief Convert a UTF-8 characters range to UTF-32 +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toUtf32(In begin, In end, Out output); +} // namespace Utf8 + +//////////////////////////////////////////////////////////// +/// \brief UTF-16 string conversion functions +/// +//////////////////////////////////////////////////////////// +namespace Utf16 { -public: - //////////////////////////////////////////////////////////// - /// \brief Decode a single UTF-32 character - /// - /// Decoding a character means finding its unique 32-bits - /// code (called the codepoint) in the Unicode standard. - /// For UTF-32, the character value is the same as the codepoint. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Codepoint of the decoded UTF-32 character - /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static In decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement = 0); +//////////////////////////////////////////////////////////// +/// \brief Decode a single UTF-16 character +/// +/// Decoding a character means finding its unique 32-bits +/// code (called the codepoint) in the Unicode standard. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Codepoint of the decoded UTF-16 character +/// \param replacement Replacement character to use in case the UTF-8 sequence is invalid +/// +/// \return Iterator pointing to one past the last read element of the input sequence +/// +//////////////////////////////////////////////////////////// +template +In decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-32 character - /// - /// Encoding a character means converting a unique 32-bits - /// code (called the codepoint) in the target encoding, UTF-32. - /// For UTF-32, the codepoint is the same as the character value. - /// - /// \param input Codepoint to encode as UTF-32 - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to UTF-32 (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out encode(std::uint32_t input, Out output, std::uint32_t replacement = 0); +//////////////////////////////////////////////////////////// +/// \brief Encode a single UTF-16 character +/// +/// Encoding a character means converting a unique 32-bits +/// code (called the codepoint) in the target encoding, UTF-16. +/// +/// \param input Codepoint to encode as UTF-16 +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement for characters not convertible to UTF-16 (use 0 to skip them) +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out encode(std::uint32_t input, Out output, std::uint16_t replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Advance to the next UTF-32 character - /// - /// This function is trivial for UTF-32, which can store - /// every character in a single storage element. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static In next(In begin, In end); +//////////////////////////////////////////////////////////// +/// \brief Advance to the next UTF-16 character +/// +/// This function is necessary for multi-elements encodings, as +/// a single character may use more than 1 storage element. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// +/// \return Iterator pointing to one past the last read element of the input sequence +/// +//////////////////////////////////////////////////////////// +template +In next(In begin, In end); - //////////////////////////////////////////////////////////// - /// \brief Count the number of characters of a UTF-32 sequence - /// - /// This function is trivial for UTF-32, which can store - /// every character in a single storage element. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// - /// \return Iterator pointing to one past the last read element of the input sequence - /// - //////////////////////////////////////////////////////////// - template - static std::size_t count(In begin, In end); +//////////////////////////////////////////////////////////// +/// \brief Count the number of characters of a UTF-16 sequence +/// +/// This function is necessary for multi-elements encodings, as +/// a single character may use more than 1 storage element, thus the +/// total size can be different from (begin - end). +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// +/// \return Iterator pointing to one past the last read element of the input sequence +/// +//////////////////////////////////////////////////////////// +template +std::size_t count(In begin, In end); - //////////////////////////////////////////////////////////// - /// \brief Convert an ANSI characters range to UTF-32 - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out fromAnsi(In begin, In end, Out output, const std::locale& locale = {}); +//////////////////////////////////////////////////////////// +/// \brief Convert an ANSI characters range to UTF-16 +/// +/// The current global locale will be used by default, unless you +/// pass a custom one in the \a locale parameter. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param locale Locale to use for conversion +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out fromAnsi(In begin, In end, Out output, const std::locale& locale = {}); - //////////////////////////////////////////////////////////// - /// \brief Convert a wide characters range to UTF-32 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out fromWide(In begin, In end, Out output); +//////////////////////////////////////////////////////////// +/// \brief Convert a wide characters range to UTF-16 +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out fromWide(In begin, In end, Out output); - //////////////////////////////////////////////////////////// - /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-32 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out fromLatin1(In begin, In end, Out output); +//////////////////////////////////////////////////////////// +/// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-16 +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out fromLatin1(In begin, In end, Out output); - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-32 characters range to ANSI characters - /// - /// The current global locale will be used by default, unless you - /// pass a custom one in the \a locale parameter. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = {}); +//////////////////////////////////////////////////////////// +/// \brief Convert an UTF-16 characters range to ANSI characters +/// +/// The current global locale will be used by default, unless you +/// pass a custom one in the \a locale parameter. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) +/// \param locale Locale to use for conversion +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = {}); - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-32 characters range to wide characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toWide(In begin, In end, Out output, wchar_t replacement = 0); +//////////////////////////////////////////////////////////// +/// \brief Convert an UTF-16 characters range to wide characters +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toWide(In begin, In end, Out output, wchar_t replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toLatin1(In begin, In end, Out output, char replacement = 0); +//////////////////////////////////////////////////////////// +/// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toLatin1(In begin, In end, Out output, char replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-32 characters range to UTF-8 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toUtf8(In begin, In end, Out output); +//////////////////////////////////////////////////////////// +/// \brief Convert a UTF-16 characters range to UTF-8 +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toUtf8(In begin, In end, Out output); - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-32 characters range to UTF-16 - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toUtf16(In begin, In end, Out output); +//////////////////////////////////////////////////////////// +/// \brief Convert a UTF-16 characters range to UTF-16 +/// +/// This functions does nothing more than a direct copy; +/// it is defined only to provide the same interface as other +/// specializations of the sf::Utf<> template, and allow +/// generic code to be written on top of it. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toUtf16(In begin, In end, Out output); - //////////////////////////////////////////////////////////// - /// \brief Convert a UTF-32 characters range to UTF-32 - /// - /// This functions does nothing more than a direct copy; - /// it is defined only to provide the same interface as other - /// specializations of the sf::Utf<> template, and allow - /// generic code to be written on top of it. - /// - /// \param begin Iterator pointing to the beginning of the input sequence - /// \param end Iterator pointing to the end of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out toUtf32(In begin, In end, Out output); +//////////////////////////////////////////////////////////// +/// \brief Convert a UTF-16 characters range to UTF-32 +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toUtf32(In begin, In end, Out output); +}; // namespace Utf16 - //////////////////////////////////////////////////////////// - /// \brief Decode a single ANSI character to UTF-32 - /// - /// This function does not exist in other specializations - /// of sf::Utf<>, it is defined for convenience (it is used by - /// several other conversion functions). - /// - /// \param input Input ANSI character - /// \param locale Locale to use for conversion - /// - /// \return Converted character - /// - //////////////////////////////////////////////////////////// - template - static std::uint32_t decodeAnsi(In input, const std::locale& locale = {}); +//////////////////////////////////////////////////////////// +/// \brief UTF-32 string conversion functions +/// +//////////////////////////////////////////////////////////// +namespace Utf32 +{ +//////////////////////////////////////////////////////////// +/// \brief Decode a single UTF-32 character +/// +/// Decoding a character means finding its unique 32-bits +/// code (called the codepoint) in the Unicode standard. +/// For UTF-32, the character value is the same as the codepoint. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Codepoint of the decoded UTF-32 character +/// \param replacement Replacement character to use in case the UTF-8 sequence is invalid +/// +/// \return Iterator pointing to one past the last read element of the input sequence +/// +//////////////////////////////////////////////////////////// +template +In decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Decode a single wide character to UTF-32 - /// - /// This function does not exist in other specializations - /// of sf::Utf<>, it is defined for convenience (it is used by - /// several other conversion functions). - /// - /// \param input Input wide character - /// - /// \return Converted character - /// - //////////////////////////////////////////////////////////// - template - static std::uint32_t decodeWide(In input); +//////////////////////////////////////////////////////////// +/// \brief Encode a single UTF-32 character +/// +/// Encoding a character means converting a unique 32-bits +/// code (called the codepoint) in the target encoding, UTF-32. +/// For UTF-32, the codepoint is the same as the character value. +/// +/// \param input Codepoint to encode as UTF-32 +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement for characters not convertible to UTF-32 (use 0 to skip them) +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out encode(std::uint32_t input, Out output, std::uint32_t replacement = 0); - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-32 character to ANSI - /// - /// This function does not exist in other specializations - /// of sf::Utf<>, it is defined for convenience (it is used by - /// several other conversion functions). - /// - /// \param codepoint Iterator pointing to the beginning of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement if the input character is not convertible to ANSI (use 0 to skip it) - /// \param locale Locale to use for conversion - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out encodeAnsi(std::uint32_t codepoint, Out output, char replacement = 0, const std::locale& locale = {}); +//////////////////////////////////////////////////////////// +/// \brief Advance to the next UTF-32 character +/// +/// This function is trivial for UTF-32, which can store +/// every character in a single storage element. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// +/// \return Iterator pointing to one past the last read element of the input sequence +/// +//////////////////////////////////////////////////////////// +template +In next(In begin, In end); - //////////////////////////////////////////////////////////// - /// \brief Encode a single UTF-32 character to wide - /// - /// This function does not exist in other specializations - /// of sf::Utf<>, it is defined for convenience (it is used by - /// several other conversion functions). - /// - /// \param codepoint Iterator pointing to the beginning of the input sequence - /// \param output Iterator pointing to the beginning of the output sequence - /// \param replacement Replacement if the input character is not convertible to wide (use 0 to skip it) - /// - /// \return Iterator to the end of the output sequence which has been written - /// - //////////////////////////////////////////////////////////// - template - static Out encodeWide(std::uint32_t codepoint, Out output, wchar_t replacement = 0); -}; +//////////////////////////////////////////////////////////// +/// \brief Count the number of characters of a UTF-32 sequence +/// +/// This function is trivial for UTF-32, which can store +/// every character in a single storage element. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// +/// \return Iterator pointing to one past the last read element of the input sequence +/// +//////////////////////////////////////////////////////////// +template +std::size_t count(In begin, In end); -// Make type aliases to get rid of the template syntax -using Utf8 = Utf<8>; -using Utf16 = Utf<16>; -using Utf32 = Utf<32>; +//////////////////////////////////////////////////////////// +/// \brief Convert an ANSI characters range to UTF-32 +/// +/// The current global locale will be used by default, unless you +/// pass a custom one in the \a locale parameter. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param locale Locale to use for conversion +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out fromAnsi(In begin, In end, Out output, const std::locale& locale = {}); + +//////////////////////////////////////////////////////////// +/// \brief Convert a wide characters range to UTF-32 +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out fromWide(In begin, In end, Out output); + +//////////////////////////////////////////////////////////// +/// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-32 +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out fromLatin1(In begin, In end, Out output); + +//////////////////////////////////////////////////////////// +/// \brief Convert an UTF-32 characters range to ANSI characters +/// +/// The current global locale will be used by default, unless you +/// pass a custom one in the \a locale parameter. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) +/// \param locale Locale to use for conversion +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = {}); + +//////////////////////////////////////////////////////////// +/// \brief Convert an UTF-32 characters range to wide characters +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toWide(In begin, In end, Out output, wchar_t replacement = 0); + +//////////////////////////////////////////////////////////// +/// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toLatin1(In begin, In end, Out output, char replacement = 0); + +//////////////////////////////////////////////////////////// +/// \brief Convert a UTF-32 characters range to UTF-8 +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toUtf8(In begin, In end, Out output); + +//////////////////////////////////////////////////////////// +/// \brief Convert a UTF-32 characters range to UTF-16 +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toUtf16(In begin, In end, Out output); + +//////////////////////////////////////////////////////////// +/// \brief Convert a UTF-32 characters range to UTF-32 +/// +/// This functions does nothing more than a direct copy; +/// it is defined only to provide the same interface as other +/// specializations of the sf::Utf<> template, and allow +/// generic code to be written on top of it. +/// +/// \param begin Iterator pointing to the beginning of the input sequence +/// \param end Iterator pointing to the end of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out toUtf32(In begin, In end, Out output); + +//////////////////////////////////////////////////////////// +/// \brief Decode a single ANSI character to UTF-32 +/// +/// This function does not exist in other specializations +/// of sf::Utf<>, it is defined for convenience (it is used by +/// several other conversion functions). +/// +/// \param input Input ANSI character +/// \param locale Locale to use for conversion +/// +/// \return Converted character +/// +//////////////////////////////////////////////////////////// +template +std::uint32_t decodeAnsi(In input, const std::locale& locale = {}); + +//////////////////////////////////////////////////////////// +/// \brief Decode a single wide character to UTF-32 +/// +/// This function does not exist in other specializations +/// of sf::Utf<>, it is defined for convenience (it is used by +/// several other conversion functions). +/// +/// \param input Input wide character +/// +/// \return Converted character +/// +//////////////////////////////////////////////////////////// +template +std::uint32_t decodeWide(In input); + +//////////////////////////////////////////////////////////// +/// \brief Encode a single UTF-32 character to ANSI +/// +/// This function does not exist in other specializations +/// of sf::Utf<>, it is defined for convenience (it is used by +/// several other conversion functions). +/// +/// \param codepoint Iterator pointing to the beginning of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement if the input character is not convertible to ANSI (use 0 to skip it) +/// \param locale Locale to use for conversion +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out encodeAnsi(std::uint32_t codepoint, Out output, char replacement = 0, const std::locale& locale = {}); + +//////////////////////////////////////////////////////////// +/// \brief Encode a single UTF-32 character to wide +/// +/// This function does not exist in other specializations +/// of sf::Utf<>, it is defined for convenience (it is used by +/// several other conversion functions). +/// +/// \param codepoint Iterator pointing to the beginning of the input sequence +/// \param output Iterator pointing to the beginning of the output sequence +/// \param replacement Replacement if the input character is not convertible to wide (use 0 to skip it) +/// +/// \return Iterator to the end of the output sequence which has been written +/// +//////////////////////////////////////////////////////////// +template +Out encodeWide(std::uint32_t codepoint, Out output, wchar_t replacement = 0); +}; // namespace Utf32 } // namespace sf @@ -743,22 +729,18 @@ using Utf32 = Utf<32>; //////////////////////////////////////////////////////////// -/// \class sf::Utf +/// \namespace sf::Utf8 +/// \namespace sf::Utf16 +/// \namespace sf::Utf32 /// \ingroup system /// /// Utility class providing generic functions for UTF conversions. /// -/// sf::Utf is a low-level, generic interface for counting, iterating, +/// This is a low-level, generic interface for counting, iterating, /// encoding and decoding Unicode characters and strings. It is able /// to handle ANSI, wide, latin-1, UTF-8, UTF-16 and UTF-32 encodings. /// -/// sf::Utf functions are all static, these classes are not meant to -/// be instantiated. All the functions are template, so that you -/// can use any character / string type for a given encoding. -/// -/// It has 3 specializations: -/// \li sf::Utf<8> (with sf::Utf8 type alias) -/// \li sf::Utf<16> (with sf::Utf16 type alias) -/// \li sf::Utf<32> (with sf::Utf32 type alias) +/// All the functions are template, so that you can use any character +/// or string type for a given encoding. /// //////////////////////////////////////////////////////////// diff --git a/include/SFML/System/Utf.inl b/include/SFML/System/Utf.inl index 4bdf48632..93a601e14 100644 --- a/include/SFML/System/Utf.inl +++ b/include/SFML/System/Utf.inl @@ -52,7 +52,7 @@ OutputIt priv::copy(InputIt first, InputIt last, OutputIt dFirst) } template -In Utf<8>::decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement) +In Utf8::decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement) { // clang-format off // Some useful precomputed data @@ -107,7 +107,7 @@ In Utf<8>::decode(In begin, In end, std::uint32_t& output, std::uint32_t replace //////////////////////////////////////////////////////////// template -Out Utf<8>::encode(std::uint32_t input, Out output, std::uint8_t replacement) +Out Utf8::encode(std::uint32_t input, Out output, std::uint8_t replacement) { // Some useful precomputed data static constexpr std::array firstBytes = {0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC}; @@ -156,7 +156,7 @@ Out Utf<8>::encode(std::uint32_t input, Out output, std::uint8_t replacement) //////////////////////////////////////////////////////////// template -In Utf<8>::next(In begin, In end) +In Utf8::next(In begin, In end) { std::uint32_t codepoint = 0; return decode(begin, end, codepoint); @@ -165,7 +165,7 @@ In Utf<8>::next(In begin, In end) //////////////////////////////////////////////////////////// template -std::size_t Utf<8>::count(In begin, In end) +std::size_t Utf8::count(In begin, In end) { std::size_t length = 0; while (begin < end) @@ -180,11 +180,11 @@ std::size_t Utf<8>::count(In begin, In end) //////////////////////////////////////////////////////////// template -Out Utf<8>::fromAnsi(In begin, In end, Out output, const std::locale& locale) +Out Utf8::fromAnsi(In begin, In end, Out output, const std::locale& locale) { while (begin < end) { - const std::uint32_t codepoint = Utf<32>::decodeAnsi(*begin++, locale); + const std::uint32_t codepoint = Utf32::decodeAnsi(*begin++, locale); output = encode(codepoint, output); } @@ -194,11 +194,11 @@ Out Utf<8>::fromAnsi(In begin, In end, Out output, const std::locale& locale) //////////////////////////////////////////////////////////// template -Out Utf<8>::fromWide(In begin, In end, Out output) +Out Utf8::fromWide(In begin, In end, Out output) { while (begin < end) { - std::uint32_t codepoint = Utf<32>::decodeWide(*begin++); + std::uint32_t codepoint = Utf32::decodeWide(*begin++); output = encode(codepoint, output); } @@ -208,7 +208,7 @@ Out Utf<8>::fromWide(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -Out Utf<8>::fromLatin1(In begin, In end, Out output) +Out Utf8::fromLatin1(In begin, In end, Out output) { // Latin-1 is directly compatible with Unicode encodings, // and can thus be treated as (a sub-range of) UTF-32 @@ -221,13 +221,13 @@ Out Utf<8>::fromLatin1(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -Out Utf<8>::toAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) +Out Utf8::toAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) { while (begin < end) { std::uint32_t codepoint = 0; begin = decode(begin, end, codepoint); - output = Utf<32>::encodeAnsi(codepoint, output, replacement, locale); + output = Utf32::encodeAnsi(codepoint, output, replacement, locale); } return output; @@ -236,13 +236,13 @@ Out Utf<8>::toAnsi(In begin, In end, Out output, char replacement, const std::lo //////////////////////////////////////////////////////////// template -Out Utf<8>::toWide(In begin, In end, Out output, wchar_t replacement) +Out Utf8::toWide(In begin, In end, Out output, wchar_t replacement) { while (begin < end) { std::uint32_t codepoint = 0; begin = decode(begin, end, codepoint); - output = Utf<32>::encodeWide(codepoint, output, replacement); + output = Utf32::encodeWide(codepoint, output, replacement); } return output; @@ -251,7 +251,7 @@ Out Utf<8>::toWide(In begin, In end, Out output, wchar_t replacement) //////////////////////////////////////////////////////////// template -Out Utf<8>::toLatin1(In begin, In end, Out output, char replacement) +Out Utf8::toLatin1(In begin, In end, Out output, char replacement) { // Latin-1 is directly compatible with Unicode encodings, // and can thus be treated as (a sub-range of) UTF-32 @@ -268,7 +268,7 @@ Out Utf<8>::toLatin1(In begin, In end, Out output, char replacement) //////////////////////////////////////////////////////////// template -Out Utf<8>::toUtf8(In begin, In end, Out output) +Out Utf8::toUtf8(In begin, In end, Out output) { return priv::copy(begin, end, output); } @@ -276,13 +276,13 @@ Out Utf<8>::toUtf8(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -Out Utf<8>::toUtf16(In begin, In end, Out output) +Out Utf8::toUtf16(In begin, In end, Out output) { while (begin < end) { std::uint32_t codepoint = 0; begin = decode(begin, end, codepoint); - output = Utf<16>::encode(codepoint, output); + output = Utf16::encode(codepoint, output); } return output; @@ -291,7 +291,7 @@ Out Utf<8>::toUtf16(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -Out Utf<8>::toUtf32(In begin, In end, Out output) +Out Utf8::toUtf32(In begin, In end, Out output) { while (begin < end) { @@ -306,7 +306,7 @@ Out Utf<8>::toUtf32(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -In Utf<16>::decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement) +In Utf16::decode(In begin, In end, std::uint32_t& output, std::uint32_t replacement) { const std::uint16_t first = *begin++; @@ -346,7 +346,7 @@ In Utf<16>::decode(In begin, In end, std::uint32_t& output, std::uint32_t replac //////////////////////////////////////////////////////////// template -Out Utf<16>::encode(std::uint32_t input, Out output, std::uint16_t replacement) +Out Utf16::encode(std::uint32_t input, Out output, std::uint16_t replacement) { if (input <= 0xFFFF) { @@ -383,7 +383,7 @@ Out Utf<16>::encode(std::uint32_t input, Out output, std::uint16_t replacement) //////////////////////////////////////////////////////////// template -In Utf<16>::next(In begin, In end) +In Utf16::next(In begin, In end) { std::uint32_t codepoint = 0; return decode(begin, end, codepoint); @@ -392,7 +392,7 @@ In Utf<16>::next(In begin, In end) //////////////////////////////////////////////////////////// template -std::size_t Utf<16>::count(In begin, In end) +std::size_t Utf16::count(In begin, In end) { std::size_t length = 0; while (begin < end) @@ -407,11 +407,11 @@ std::size_t Utf<16>::count(In begin, In end) //////////////////////////////////////////////////////////// template -Out Utf<16>::fromAnsi(In begin, In end, Out output, const std::locale& locale) +Out Utf16::fromAnsi(In begin, In end, Out output, const std::locale& locale) { while (begin < end) { - std::uint32_t codepoint = Utf<32>::decodeAnsi(*begin++, locale); + std::uint32_t codepoint = Utf32::decodeAnsi(*begin++, locale); output = encode(codepoint, output); } @@ -421,11 +421,11 @@ Out Utf<16>::fromAnsi(In begin, In end, Out output, const std::locale& locale) //////////////////////////////////////////////////////////// template -Out Utf<16>::fromWide(In begin, In end, Out output) +Out Utf16::fromWide(In begin, In end, Out output) { while (begin < end) { - std::uint32_t codepoint = Utf<32>::decodeWide(*begin++); + std::uint32_t codepoint = Utf32::decodeWide(*begin++); output = encode(codepoint, output); } @@ -435,7 +435,7 @@ Out Utf<16>::fromWide(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -Out Utf<16>::fromLatin1(In begin, In end, Out output) +Out Utf16::fromLatin1(In begin, In end, Out output) { // Latin-1 is directly compatible with Unicode encodings, // and can thus be treated as (a sub-range of) UTF-32 @@ -445,13 +445,13 @@ Out Utf<16>::fromLatin1(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -Out Utf<16>::toAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) +Out Utf16::toAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) { while (begin < end) { std::uint32_t codepoint = 0; begin = decode(begin, end, codepoint); - output = Utf<32>::encodeAnsi(codepoint, output, replacement, locale); + output = Utf32::encodeAnsi(codepoint, output, replacement, locale); } return output; @@ -460,13 +460,13 @@ Out Utf<16>::toAnsi(In begin, In end, Out output, char replacement, const std::l //////////////////////////////////////////////////////////// template -Out Utf<16>::toWide(In begin, In end, Out output, wchar_t replacement) +Out Utf16::toWide(In begin, In end, Out output, wchar_t replacement) { while (begin < end) { std::uint32_t codepoint = 0; begin = decode(begin, end, codepoint); - output = Utf<32>::encodeWide(codepoint, output, replacement); + output = Utf32::encodeWide(codepoint, output, replacement); } return output; @@ -475,7 +475,7 @@ Out Utf<16>::toWide(In begin, In end, Out output, wchar_t replacement) //////////////////////////////////////////////////////////// template -Out Utf<16>::toLatin1(In begin, In end, Out output, char replacement) +Out Utf16::toLatin1(In begin, In end, Out output, char replacement) { // Latin-1 is directly compatible with Unicode encodings, // and can thus be treated as (a sub-range of) UTF-32 @@ -491,13 +491,13 @@ Out Utf<16>::toLatin1(In begin, In end, Out output, char replacement) //////////////////////////////////////////////////////////// template -Out Utf<16>::toUtf8(In begin, In end, Out output) +Out Utf16::toUtf8(In begin, In end, Out output) { while (begin < end) { std::uint32_t codepoint = 0; begin = decode(begin, end, codepoint); - output = Utf<8>::encode(codepoint, output); + output = Utf8::encode(codepoint, output); } return output; @@ -506,7 +506,7 @@ Out Utf<16>::toUtf8(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -Out Utf<16>::toUtf16(In begin, In end, Out output) +Out Utf16::toUtf16(In begin, In end, Out output) { return priv::copy(begin, end, output); } @@ -514,7 +514,7 @@ Out Utf<16>::toUtf16(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -Out Utf<16>::toUtf32(In begin, In end, Out output) +Out Utf16::toUtf32(In begin, In end, Out output) { while (begin < end) { @@ -529,7 +529,7 @@ Out Utf<16>::toUtf32(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -In Utf<32>::decode(In begin, In /*end*/, std::uint32_t& output, std::uint32_t /*replacement*/) +In Utf32::decode(In begin, In /*end*/, std::uint32_t& output, std::uint32_t /*replacement*/) { output = *begin++; return begin; @@ -538,7 +538,7 @@ In Utf<32>::decode(In begin, In /*end*/, std::uint32_t& output, std::uint32_t /* //////////////////////////////////////////////////////////// template -Out Utf<32>::encode(std::uint32_t input, Out output, std::uint32_t /*replacement*/) +Out Utf32::encode(std::uint32_t input, Out output, std::uint32_t /*replacement*/) { *output++ = input; return output; @@ -547,7 +547,7 @@ Out Utf<32>::encode(std::uint32_t input, Out output, std::uint32_t /*replacement //////////////////////////////////////////////////////////// template -In Utf<32>::next(In begin, In /*end*/) +In Utf32::next(In begin, In /*end*/) { return ++begin; } @@ -555,7 +555,7 @@ In Utf<32>::next(In begin, In /*end*/) //////////////////////////////////////////////////////////// template -std::size_t Utf<32>::count(In begin, In end) +std::size_t Utf32::count(In begin, In end) { return begin - end; } @@ -563,7 +563,7 @@ std::size_t Utf<32>::count(In begin, In end) //////////////////////////////////////////////////////////// template -Out Utf<32>::fromAnsi(In begin, In end, Out output, const std::locale& locale) +Out Utf32::fromAnsi(In begin, In end, Out output, const std::locale& locale) { while (begin < end) *output++ = decodeAnsi(*begin++, locale); @@ -574,7 +574,7 @@ Out Utf<32>::fromAnsi(In begin, In end, Out output, const std::locale& locale) //////////////////////////////////////////////////////////// template -Out Utf<32>::fromWide(In begin, In end, Out output) +Out Utf32::fromWide(In begin, In end, Out output) { while (begin < end) *output++ = decodeWide(*begin++); @@ -585,7 +585,7 @@ Out Utf<32>::fromWide(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -Out Utf<32>::fromLatin1(In begin, In end, Out output) +Out Utf32::fromLatin1(In begin, In end, Out output) { // Latin-1 is directly compatible with Unicode encodings, // and can thus be treated as (a sub-range of) UTF-32 @@ -595,7 +595,7 @@ Out Utf<32>::fromLatin1(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -Out Utf<32>::toAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) +Out Utf32::toAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) { while (begin < end) output = encodeAnsi(*begin++, output, replacement, locale); @@ -606,7 +606,7 @@ Out Utf<32>::toAnsi(In begin, In end, Out output, char replacement, const std::l //////////////////////////////////////////////////////////// template -Out Utf<32>::toWide(In begin, In end, Out output, wchar_t replacement) +Out Utf32::toWide(In begin, In end, Out output, wchar_t replacement) { while (begin < end) output = encodeWide(*begin++, output, replacement); @@ -617,7 +617,7 @@ Out Utf<32>::toWide(In begin, In end, Out output, wchar_t replacement) //////////////////////////////////////////////////////////// template -Out Utf<32>::toLatin1(In begin, In end, Out output, char replacement) +Out Utf32::toLatin1(In begin, In end, Out output, char replacement) { // Latin-1 is directly compatible with Unicode encodings, // and can thus be treated as (a sub-range of) UTF-32 @@ -633,20 +633,20 @@ Out Utf<32>::toLatin1(In begin, In end, Out output, char replacement) //////////////////////////////////////////////////////////// template -Out Utf<32>::toUtf8(In begin, In end, Out output) +Out Utf32::toUtf8(In begin, In end, Out output) { while (begin < end) - output = Utf<8>::encode(*begin++, output); + output = Utf8::encode(*begin++, output); return output; } //////////////////////////////////////////////////////////// template -Out Utf<32>::toUtf16(In begin, In end, Out output) +Out Utf32::toUtf16(In begin, In end, Out output) { while (begin < end) - output = Utf<16>::encode(*begin++, output); + output = Utf16::encode(*begin++, output); return output; } @@ -654,7 +654,7 @@ Out Utf<32>::toUtf16(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -Out Utf<32>::toUtf32(In begin, In end, Out output) +Out Utf32::toUtf32(In begin, In end, Out output) { return priv::copy(begin, end, output); } @@ -662,7 +662,7 @@ Out Utf<32>::toUtf32(In begin, In end, Out output) //////////////////////////////////////////////////////////// template -std::uint32_t Utf<32>::decodeAnsi(In input, [[maybe_unused]] const std::locale& locale) +std::uint32_t Utf32::decodeAnsi(In input, [[maybe_unused]] const std::locale& locale) { // Get the facet of the locale which deals with character conversion const auto& facet = std::use_facet>(locale); @@ -674,7 +674,7 @@ std::uint32_t Utf<32>::decodeAnsi(In input, [[maybe_unused]] const std::locale& //////////////////////////////////////////////////////////// template -std::uint32_t Utf<32>::decodeWide(In input) +std::uint32_t Utf32::decodeWide(In input) { // The encoding of wide characters is not well defined and is left to the system; // however we can safely assume that it is UCS-2 on Windows and @@ -688,7 +688,7 @@ std::uint32_t Utf<32>::decodeWide(In input) //////////////////////////////////////////////////////////// template -Out Utf<32>::encodeAnsi(std::uint32_t codepoint, Out output, char replacement, [[maybe_unused]] const std::locale& locale) +Out Utf32::encodeAnsi(std::uint32_t codepoint, Out output, char replacement, [[maybe_unused]] const std::locale& locale) { // Get the facet of the locale which deals with character conversion const auto& facet = std::use_facet>(locale); @@ -702,7 +702,7 @@ Out Utf<32>::encodeAnsi(std::uint32_t codepoint, Out output, char replacement, [ //////////////////////////////////////////////////////////// template -Out Utf<32>::encodeWide(std::uint32_t codepoint, Out output, wchar_t replacement) +Out Utf32::encodeWide(std::uint32_t codepoint, Out output, wchar_t replacement) { // The encoding of wide characters is not well defined and is left to the system; // however we can safely assume that it is UCS-2 on Windows and