From 58632672cb2c7e97a6647bf428ee624649b241a0 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Wed, 9 Feb 2011 16:44:43 +0000 Subject: [PATCH] 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 --- include/SFML/System/Utf.hpp | 25 ++++------- include/SFML/System/Utf.inl | 11 +++++ src/SFML/System/CMakeLists.txt | 1 - src/SFML/System/Utf.cpp | 78 ---------------------------------- 4 files changed, 19 insertions(+), 96 deletions(-) delete mode 100644 src/SFML/System/Utf.cpp diff --git a/include/SFML/System/Utf.hpp b/include/SFML/System/Utf.hpp index bab27d67..5fe481b6 100644 --- a/include/SFML/System/Utf.hpp +++ b/include/SFML/System/Utf.hpp @@ -37,15 +37,6 @@ namespace sf { -//////////////////////////////////////////////////////////// -/// \ingroup system -/// \brief Get the default system locale -/// -/// \return Reference to the default system locale -/// -//////////////////////////////////////////////////////////// -SFML_API const std::locale& GetDefaultLocale(); - template class Utf; @@ -137,7 +128,7 @@ public : /// //////////////////////////////////////////////////////////// template - 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 @@ -182,7 +173,7 @@ public : /// //////////////////////////////////////////////////////////// template - 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 @@ -345,7 +336,7 @@ public : /// //////////////////////////////////////////////////////////// template - 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 @@ -390,7 +381,7 @@ public : /// //////////////////////////////////////////////////////////// template - 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 @@ -554,7 +545,7 @@ public : /// //////////////////////////////////////////////////////////// template - 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 @@ -599,7 +590,7 @@ public : /// //////////////////////////////////////////////////////////// template - 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 @@ -687,7 +678,7 @@ public : /// //////////////////////////////////////////////////////////// template - 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 @@ -720,7 +711,7 @@ public : /// //////////////////////////////////////////////////////////// template - 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 diff --git a/include/SFML/System/Utf.inl b/include/SFML/System/Utf.inl index 12b88603..b6078bbd 100644 --- a/include/SFML/System/Utf.inl +++ b/include/SFML/System/Utf.inl @@ -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 In Utf<8>::Decode(In begin, In end, Uint32& output, Uint32 replacement) diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index d9a4737c..e26f524d 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -30,7 +30,6 @@ set(SRC ${INCROOT}/ThreadLocal.hpp ${INCROOT}/ThreadLocalPtr.hpp ${INCROOT}/ThreadLocalPtr.inl - ${SRCROOT}/Utf.cpp ${INCROOT}/Utf.hpp ${INCROOT}/Utf.inl ${INCROOT}/Vector2.hpp diff --git a/src/SFML/System/Utf.cpp b/src/SFML/System/Utf.cpp deleted file mode 100644 index cbe2a453..00000000 --- a/src/SFML/System/Utf.cpp +++ /dev/null @@ -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 -#include - - -//////////////////////////////////////////////////////////// -// 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