From 34a0f87395d9047d47d9355245f175481c7bea49 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Fri, 16 Mar 2018 18:56:01 +0100 Subject: [PATCH] Fixed the previous commit on Linux: The older GCC we are using on our Debian build server does not support C++11 , so the utf8 to utf16 conversion was replaced with Boost counterparts. --- xs/src/slic3r/Utils/ASCIIFolding.cpp | 18 ++++++++++++++---- xs/src/slic3r/Utils/ASCIIFolding.hpp | 1 + 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/xs/src/slic3r/Utils/ASCIIFolding.cpp b/xs/src/slic3r/Utils/ASCIIFolding.cpp index a923620fc..381a330a0 100644 --- a/xs/src/slic3r/Utils/ASCIIFolding.cpp +++ b/xs/src/slic3r/Utils/ASCIIFolding.cpp @@ -1,7 +1,7 @@ #include "ASCIIFolding.hpp" -#include #include +#include // Based on http://svn.apache.org/repos/asf/lucene/java/tags/lucene_solr_4_5_1/lucene/analysis/common/src/java/org/apache/lucene/analysis/miscellaneous/ASCIIFoldingFilter.java template @@ -1929,14 +1929,24 @@ namespace Slic3r { std::string fold_utf8_to_ascii(const std::string &src) { - std::wstring_convert> converter; - std::wstring wstr = converter.from_bytes(src); + std::wstring wstr = boost::locale::conv::utf_to_utf(src.c_str(), src.c_str() + src.size()); std::wstring dst; dst.reserve(wstr.size()); auto out = std::back_insert_iterator(dst); for (wchar_t c : wstr) fold_to_ascii(c, out); - return converter.to_bytes(dst); + return boost::locale::conv::utf_to_utf(dst.c_str(), dst.c_str() + dst.size()); +} + +std::string fold_utf8_to_ascii(const char *src) +{ + std::wstring wstr = boost::locale::conv::utf_to_utf(src, src + strlen(src)); + std::wstring dst; + dst.reserve(wstr.size()); + auto out = std::back_insert_iterator(dst); + for (wchar_t c : wstr) + fold_to_ascii(c, out); + return boost::locale::conv::utf_to_utf(dst.c_str(), dst.c_str() + dst.size()); } }; // namespace Slic3r diff --git a/xs/src/slic3r/Utils/ASCIIFolding.hpp b/xs/src/slic3r/Utils/ASCIIFolding.hpp index 723c511e8..55f56482d 100644 --- a/xs/src/slic3r/Utils/ASCIIFolding.hpp +++ b/xs/src/slic3r/Utils/ASCIIFolding.hpp @@ -7,6 +7,7 @@ namespace Slic3r { // If possible, remove accents from accented latin characters. // This function is useful for generating file names to be processed by legacy firmwares. +extern std::string fold_utf8_to_ascii(const char *src); extern std::string fold_utf8_to_ascii(const std::string &src); }; // namespace Slic3r