use utfcpp on all platforms since codecvt has been deprecated in c++17, closes #197

This commit is contained in:
Thomas Fussell 2017-08-15 18:23:28 -04:00
parent b5e10a8dbe
commit 3257274057
2 changed files with 7 additions and 49 deletions

View File

@ -154,11 +154,7 @@ endif()
target_include_directories(xlnt PUBLIC ${XLNT_INCLUDE_DIR})
target_include_directories(xlnt PRIVATE ${XLNT_SOURCE_DIR})
target_include_directories(xlnt PRIVATE ${XLNT_SOURCE_DIR}/../third-party/libstudxml)
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "5.0.0")
target_compile_definitions(xlnt PRIVATE UTFCPP=1)
target_include_directories(xlnt PRIVATE ${XLNT_SOURCE_DIR}/../third-party/utfcpp)
endif()
target_include_directories(xlnt PRIVATE ${XLNT_SOURCE_DIR}/../third-party/utfcpp)
if(MSVC)
set_target_properties(xlnt PROPERTIES COMPILE_FLAGS "/wd\"4251\" /wd\"4275\" /wd\"4068\" /MP")

View File

@ -21,55 +21,18 @@
// @license: http://www.opensource.org/licenses/mit-license.php
// @author: see AUTHORS file
#include <locale>
#include <string>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated"
#pragma clang diagnostic ignored "-Wweak-vtables"
#pragma clang diagnostic ignored "-Wsign-conversion"
#include <utf8.h>
#pragma clang diagnostic pop
#include <detail/unicode.hpp>
#ifdef UTFCPP
#include <utf8.h>
#else
#include <codecvt>
#endif
namespace xlnt {
namespace detail {
#ifndef UTFCPP
#ifdef _MSC_VER
std::u16string utf8_to_utf16(const std::string &utf8_string)
{
// use wchar_t instead of char16_t on Windows because of a bug in MSVC
// error LNK2001: unresolved external symbol std::codecvt::id
// https://connect.microsoft.com/VisualStudio/Feedback/Details/1403302
auto converted = std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>{}.from_bytes(utf8_string);
return std::u16string(converted.begin(), converted.end());
}
std::string utf16_to_utf8(const std::u16string &utf16_string)
{
std::wstring utf16_wstring(utf16_string.begin(), utf16_string.end());
// use wchar_t instead of char16_t on Windows because of a bug in MSVC
// error LNK2001: unresolved external symbol std::codecvt::id
// https://connect.microsoft.com/VisualStudio/Feedback/Details/1403302
return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>,
wchar_t>{}.to_bytes(utf16_wstring);
}
#else
std::u16string utf8_to_utf16(const std::string &utf8_string)
{
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,
char16_t>{}.from_bytes(utf8_string);
}
std::string utf16_to_utf8(const std::u16string &utf16_string)
{
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,
char16_t>{}.to_bytes(utf16_string);
}
#endif
#else
std::u16string utf8_to_utf16(const std::string &utf8_string)
{
std::u16string result;
@ -85,7 +48,6 @@ std::string utf16_to_utf8(const std::u16string &utf16_string)
return result;
}
#endif
std::string latin1_to_utf8(const std::string &latin1)
{