mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Added String::fromUtf8/16/32 functions (#196)
This commit is contained in:
parent
de0401a02e
commit
a89874f733
@ -155,6 +155,52 @@ public :
|
||||
////////////////////////////////////////////////////////////
|
||||
String(const String& copy);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new sf::String from a UTF-8 encoded string
|
||||
///
|
||||
/// \param begin Forward iterator to the begining of the UTF-8 sequence
|
||||
/// \param end Forward iterator to the end of the UTF-8 sequence
|
||||
///
|
||||
/// \return A sf::String containing the source string
|
||||
///
|
||||
/// \see fromUtf16, fromUtf32
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
static String fromUtf8(T begin, T end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new sf::String from a UTF-16 encoded string
|
||||
///
|
||||
/// \param begin Forward iterator to the begining of the UTF-16 sequence
|
||||
/// \param end Forward iterator to the end of the UTF-16 sequence
|
||||
///
|
||||
/// \return A sf::String containing the source string
|
||||
///
|
||||
/// \see fromUtf8, fromUtf32
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
static String fromUtf16(T begin, T end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Create a new sf::String from a UTF-32 encoded string
|
||||
///
|
||||
/// This function is provided for consistency, it is equivalent to
|
||||
/// using the constructors that takes a const sf::Uint32* or
|
||||
/// a std::basic_string<sf::Uint32>.
|
||||
///
|
||||
/// \param begin Forward iterator to the begining of the UTF-32 sequence
|
||||
/// \param end Forward iterator to the end of the UTF-32 sequence
|
||||
///
|
||||
/// \return A sf::String containing the source string
|
||||
///
|
||||
/// \see fromUtf8, fromUtf16
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
static String fromUtf32(T begin, T end);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Implicit cast operator to std::string (ANSI string)
|
||||
///
|
||||
@ -487,6 +533,8 @@ SFML_SYSTEM_API bool operator >=(const String& left, const String& right);
|
||||
////////////////////////////////////////////////////////////
|
||||
SFML_SYSTEM_API String operator +(const String& left, const String& right);
|
||||
|
||||
#include <SFML/System/String.inl>
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
|
53
include/SFML/System/String.inl
Normal file
53
include/SFML/System/String.inl
Normal file
@ -0,0 +1,53 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2012 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
static String String::fromUtf8(T begin, T end)
|
||||
{
|
||||
String string;
|
||||
Utf8::toUtf32(begin, end, std::back_inserter(string.m_string));
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
static String String::fromUtf16(T begin, T end)
|
||||
{
|
||||
String string;
|
||||
Utf16::toUtf32(begin, end, std::back_inserter(string.m_string));
|
||||
return string;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
static String String::fromUtf32(T begin, T end)
|
||||
{
|
||||
String string;
|
||||
string.m_string.assign(begin, end);
|
||||
return string;
|
||||
}
|
@ -19,6 +19,7 @@ set(SRC
|
||||
${INCROOT}/Sleep.hpp
|
||||
${SRCROOT}/String.cpp
|
||||
${INCROOT}/String.hpp
|
||||
${INCROOT}/String.inl
|
||||
${SRCROOT}/Thread.cpp
|
||||
${INCROOT}/Thread.hpp
|
||||
${INCROOT}/Thread.inl
|
||||
|
Loading…
Reference in New Issue
Block a user