# HG changeset patch # User Sebastien Jodogne # Date 1403604041 -7200 # Node ID 703bef350e8971d38f562d80315039541e50bca1 # Parent 816dccaeb7cf92b590803994271ec462391834ee Orthanc now relies entirely on boost::locale diff -r 816dccaeb7cf -r 703bef350e89 Core/Toolbox.cpp --- a/Core/Toolbox.cpp Mon Jun 16 15:39:16 2014 +0200 +++ b/Core/Toolbox.cpp Tue Jun 24 12:00:41 2014 +0200 @@ -60,11 +60,11 @@ #include #endif -#if BOOST_HAS_LOCALE == 1 +#if BOOST_HAS_LOCALE != 1 +#error Since version 0.7.6, Orthanc entirely relies on boost::locale +#endif + #include -#else -#include -#endif #include "../Resources/md5/md5.h" #include "../Resources/base64/base64.h" @@ -74,68 +74,11 @@ // Patch for the missing "_strtoll" symbol when compiling with Visual Studio extern "C" { -int64_t _strtoi64(const char *nptr, char **endptr, int base); -int64_t strtoll(const char *nptr, char **endptr, int base) -{ - return _strtoi64(nptr, endptr, base); -} -} -#endif - - -#if BOOST_HAS_LOCALE == 0 -namespace -{ - class IconvRabi + int64_t _strtoi64(const char *nptr, char **endptr, int base); + int64_t strtoll(const char *nptr, char **endptr, int base) { - private: - iconv_t context_; - - public: - IconvRabi(const char* tocode, const char* fromcode) - { - context_ = iconv_open(tocode, fromcode); - if (!context_) - { - throw Orthanc::OrthancException("Unknown code page"); - } - } - - ~IconvRabi() - { - iconv_close(context_); - } - - std::string Convert(const std::string& source) - { - if (source.size() == 0) - { - return ""; - } - - std::string result; - char* sourcePos = const_cast(&source[0]); - size_t sourceLeft = source.size(); - - std::vector storage(source.size() + 10); - - while (sourceLeft > 0) - { - char* tmp = &storage[0]; - size_t outputLeft = storage.size(); - size_t err = iconv(context_, &sourcePos, &sourceLeft, &tmp, &outputLeft); - if (err < 0) - { - throw Orthanc::OrthancException("Bad character in sequence"); - } - - size_t count = storage.size() - outputLeft; - result += std::string(&storage[0], count); - } - - return result; - } - }; + return _strtoi64(nptr, endptr, base); + } } #endif @@ -554,7 +497,6 @@ std::string Toolbox::ConvertToUtf8(const std::string& source, const char* fromEncoding) { -#if BOOST_HAS_LOCALE == 1 try { return boost::locale::conv::to_utf(source, fromEncoding); @@ -564,17 +506,6 @@ // Bad input string or bad encoding return ConvertToAscii(source); } -#else - IconvRabi iconv("UTF-8", fromEncoding); - try - { - return iconv.Convert(source); - } - catch (OrthancException) - { - return ConvertToAscii(source); - } -#endif } diff -r 816dccaeb7cf -r 703bef350e89 Resources/CMake/BoostConfiguration.cmake --- a/Resources/CMake/BoostConfiguration.cmake Mon Jun 16 15:39:16 2014 +0200 +++ b/Resources/CMake/BoostConfiguration.cmake Tue Jun 24 12:00:41 2014 +0200 @@ -8,7 +8,7 @@ #set(Boost_USE_STATIC_LIBS ON) find_package(Boost - COMPONENTS filesystem thread system date_time regex) + COMPONENTS filesystem thread system date_time regex locale) if (NOT Boost_FOUND) message(FATAL_ERROR "Unable to locate Boost on this system") @@ -121,6 +121,6 @@ source_group(ThirdParty\\Boost REGULAR_EXPRESSION ${BOOST_SOURCES_DIR}/.*) else() add_definitions( - -DBOOST_HAS_LOCALE=0 + -DBOOST_HAS_LOCALE=1 ) endif()