sf::Utf functions now use the global locale by default instead of the system's one
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1794 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
b26215ef96
commit
58632672cb
@ -37,15 +37,6 @@
|
|||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \ingroup system
|
|
||||||
/// \brief Get the default system locale
|
|
||||||
///
|
|
||||||
/// \return Reference to the default system locale
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
SFML_API const std::locale& GetDefaultLocale();
|
|
||||||
|
|
||||||
template <unsigned int N>
|
template <unsigned int N>
|
||||||
class Utf;
|
class Utf;
|
||||||
|
|
||||||
@ -137,7 +128,7 @@ public :
|
|||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename In, typename Out>
|
template <typename In, typename Out>
|
||||||
static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = GetDefaultLocale());
|
static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale());
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Convert a wide characters range to UTF-8
|
/// \brief Convert a wide characters range to UTF-8
|
||||||
@ -182,7 +173,7 @@ public :
|
|||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename In, typename Out>
|
template <typename In, typename Out>
|
||||||
static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = GetDefaultLocale());
|
static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale());
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Convert an UTF-8 characters range to wide characters
|
/// \brief Convert an UTF-8 characters range to wide characters
|
||||||
@ -345,7 +336,7 @@ public :
|
|||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename In, typename Out>
|
template <typename In, typename Out>
|
||||||
static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = GetDefaultLocale());
|
static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale());
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Convert a wide characters range to UTF-16
|
/// \brief Convert a wide characters range to UTF-16
|
||||||
@ -390,7 +381,7 @@ public :
|
|||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename In, typename Out>
|
template <typename In, typename Out>
|
||||||
static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = GetDefaultLocale());
|
static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale());
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Convert an UTF-16 characters range to wide characters
|
/// \brief Convert an UTF-16 characters range to wide characters
|
||||||
@ -554,7 +545,7 @@ public :
|
|||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename In, typename Out>
|
template <typename In, typename Out>
|
||||||
static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = GetDefaultLocale());
|
static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale());
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Convert a wide characters range to UTF-32
|
/// \brief Convert a wide characters range to UTF-32
|
||||||
@ -599,7 +590,7 @@ public :
|
|||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename In, typename Out>
|
template <typename In, typename Out>
|
||||||
static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = GetDefaultLocale());
|
static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale());
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Convert an UTF-32 characters range to wide characters
|
/// \brief Convert an UTF-32 characters range to wide characters
|
||||||
@ -687,7 +678,7 @@ public :
|
|||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename In>
|
template <typename In>
|
||||||
static Uint32 DecodeAnsi(In input, const std::locale& locale = GetDefaultLocale());
|
static Uint32 DecodeAnsi(In input, const std::locale& locale = std::locale());
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Decode a single wide character to UTF-32
|
/// \brief Decode a single wide character to UTF-32
|
||||||
@ -720,7 +711,7 @@ public :
|
|||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename Out>
|
template <typename Out>
|
||||||
static Out EncodeAnsi(Uint32 codepoint, Out output, char replacement = 0, const std::locale& locale = GetDefaultLocale());
|
static Out EncodeAnsi(Uint32 codepoint, Out output, char replacement = 0, const std::locale& locale = std::locale());
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Encode a single UTF-32 character to wide
|
/// \brief Encode a single UTF-32 character to wide
|
||||||
|
@ -23,6 +23,17 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
// References :
|
||||||
|
//
|
||||||
|
// http://www.unicode.org/
|
||||||
|
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c
|
||||||
|
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.h
|
||||||
|
// http://people.w3.org/rishida/scripts/uniview/conversion
|
||||||
|
//
|
||||||
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
template <typename In>
|
template <typename In>
|
||||||
In Utf<8>::Decode(In begin, In end, Uint32& output, Uint32 replacement)
|
In Utf<8>::Decode(In begin, In end, Uint32& output, Uint32 replacement)
|
||||||
|
@ -30,7 +30,6 @@ set(SRC
|
|||||||
${INCROOT}/ThreadLocal.hpp
|
${INCROOT}/ThreadLocal.hpp
|
||||||
${INCROOT}/ThreadLocalPtr.hpp
|
${INCROOT}/ThreadLocalPtr.hpp
|
||||||
${INCROOT}/ThreadLocalPtr.inl
|
${INCROOT}/ThreadLocalPtr.inl
|
||||||
${SRCROOT}/Utf.cpp
|
|
||||||
${INCROOT}/Utf.hpp
|
${INCROOT}/Utf.hpp
|
||||||
${INCROOT}/Utf.inl
|
${INCROOT}/Utf.inl
|
||||||
${INCROOT}/Vector2.hpp
|
${INCROOT}/Vector2.hpp
|
||||||
|
@ -1,78 +0,0 @@
|
|||||||
////////////////////////////////////////////////////////////
|
|
||||||
//
|
|
||||||
// SFML - Simple and Fast Multimedia Library
|
|
||||||
// Copyright (C) 2007-2009 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.
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Headers
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
#include <SFML/System/Utf.hpp>
|
|
||||||
#include <exception>
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// References :
|
|
||||||
//
|
|
||||||
// http://www.unicode.org/
|
|
||||||
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c
|
|
||||||
// http://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.h
|
|
||||||
// http://people.w3.org/rishida/scripts/uniview/conversion
|
|
||||||
//
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
// Private data
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
namespace
|
|
||||||
{
|
|
||||||
// Get the current global locale
|
|
||||||
std::locale GetCurrentLocale()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
return std::locale("");
|
|
||||||
}
|
|
||||||
catch (std::exception&)
|
|
||||||
{
|
|
||||||
// It seems that some implementations don't know the "" locale (Mac OS X, MinGW)
|
|
||||||
return std::locale();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace sf
|
|
||||||
{
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Get the default system locale
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
const std::locale& GetDefaultLocale()
|
|
||||||
{
|
|
||||||
// It seems that getting the default locale is a very expensive operation,
|
|
||||||
// so we only do it once and then store the locale for reuse.
|
|
||||||
// Warning: this code won't be aware of any change of the default locale during runtime.
|
|
||||||
|
|
||||||
static std::locale locale = GetCurrentLocale();
|
|
||||||
|
|
||||||
return locale;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace sf
|
|
Loading…
Reference in New Issue
Block a user