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