diff --git a/include/SFML/System/String.hpp b/include/SFML/System/String.hpp index dc200bfd..8a0bcf8d 100644 --- a/include/SFML/System/String.hpp +++ b/include/SFML/System/String.hpp @@ -264,6 +264,39 @@ public : //////////////////////////////////////////////////////////// std::wstring toWideString() const; + //////////////////////////////////////////////////////////// + /// \brief Convert the unicode string to a UTF-8 string + /// + /// \return Converted UTF-8 string + /// + /// \see toUtf16, toUtf32 + /// + //////////////////////////////////////////////////////////// + std::basic_string toUtf8() const; + + //////////////////////////////////////////////////////////// + /// \brief Convert the unicode string to a UTF-16 string + /// + /// \return Converted UTF-16 string + /// + /// \see toUtf8, toUtf32 + /// + //////////////////////////////////////////////////////////// + std::basic_string toUtf16() const; + + //////////////////////////////////////////////////////////// + /// \brief Convert the unicode string to a UTF-32 string + /// + /// This function doesn't perform any conversion, since the + /// string is already stored as UTF-32 internally. + /// + /// \return Converted UTF-32 string + /// + /// \see toUtf8, toUtf16 + /// + //////////////////////////////////////////////////////////// + std::basic_string toUtf32() const; + //////////////////////////////////////////////////////////// /// \brief Overload of assignment operator /// diff --git a/src/SFML/System/String.cpp b/src/SFML/System/String.cpp index b4ee1353..f20f6a41 100644 --- a/src/SFML/System/String.cpp +++ b/src/SFML/System/String.cpp @@ -174,6 +174,41 @@ std::wstring String::toWideString() const } +//////////////////////////////////////////////////////////// +std::basic_string String::toUtf8() const +{ + // Prepare the output string + std::basic_string output; + output.reserve(m_string.length()); + + // Convert + Utf32::toUtf8(m_string.begin(), m_string.end(), std::back_inserter(output)); + + return output; +} + + +//////////////////////////////////////////////////////////// +std::basic_string String::toUtf16() const +{ + // Prepare the output string + std::basic_string output; + output.reserve(m_string.length()); + + // Convert + Utf32::toUtf16(m_string.begin(), m_string.end(), std::back_inserter(output)); + + return output; +} + + +//////////////////////////////////////////////////////////// +std::basic_string String::toUtf32() const +{ + return m_string; +} + + //////////////////////////////////////////////////////////// String& String::operator =(const String& right) {