1 // Copyright (C) 2020 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include <Locale_Convert.h>
22 #include <boost/locale/encoding_utf.hpp>
24 ////// To support old types of GCC (less than 5.0), check the wide-string conversion is working
25 ////#if (__cplusplus >= 201103L || _MSVC_LANG >= 201103L) && \
26 //// (__cplusplus >= 201402L || !defined(__GLIBCXX__) || \
27 //// (defined(_GLIBCXX_RELEASE) && _GLIBCXX_RELEASE > 4))
28 ////#define HAVE_WORKING_WIDESTRING 1
30 ////#define HAVE_WORKING_WIDESTRING 0
33 ////#if HAVE_WORKING_WIDESTRING
34 ////#include <codecvt>
39 std::string Convert::toString(const std::wstring& theWStr)
41 ////#if HAVE_WORKING_WIDESTRING
42 //// static std::wstring_convert<std::codecvt_utf8<wchar_t> > aConvertor;
43 //// return aConvertor.to_bytes(theWStr);
45 //// char* aBuf = new char[2 * (theWStr.size() + 1)];
46 //// size_t aNbChars = std::wcstombs(aBuf, theWStr.c_str(), theWStr.size());
47 //// if (aNbChars != (size_t)-1)
48 //// aBuf[aNbChars] = '\0';
49 //// std::string aStr(aBuf);
53 return boost::locale::conv::utf_to_utf<char>(theWStr);
56 std::string Convert::toString(const char16_t* theExtStr)
58 return boost::locale::conv::utf_to_utf<char>(theExtStr);
61 std::wstring Convert::toWString(const std::string& theStr)
63 ////#if HAVE_WORKING_WIDESTRING
64 //// static std::wstring_convert<std::codecvt_utf8<wchar_t> > aConvertor;
65 //// return aConvertor.from_bytes(theStr);
67 //// wchar_t* aBuf = new wchar_t[theStr.size() + 1];
68 //// size_t aNbWChars = std::mbstowcs(aBuf, theStr.c_str(), theStr.size());
69 //// if (aNbWChars != (size_t)-1)
70 //// aBuf[aNbWChars] = L'\0';
71 //// std::wstring aWStr(aBuf);
75 return boost::locale::conv::utf_to_utf<wchar_t>(theStr);
78 std::wstring Convert::toWString(const char16_t* theExtStr)
80 return boost::locale::conv::utf_to_utf<wchar_t>(theExtStr);