# HG changeset patch # User Markus Mützel # Date 1530189586 -7200 # Node ID c63f67d87b4ac6150440f13ee5f02034eac6afb0 # Parent 7fb40efda31f345734a33300ad78522727d71581 Add C++ functions to convert between UTF-8 string and wstring (bug #49118). * lo-sysdep.[cc,h]: Add functions "u8_to_wstring" and "u8_from_wstring" for conversion between utf-8 strings and wide character strings. diff -r 7fb40efda31f -r c63f67d87b4a liboctave/system/lo-sysdep.cc --- a/liboctave/system/lo-sysdep.cc Wed Jun 27 21:01:58 2018 +0200 +++ b/liboctave/system/lo-sysdep.cc Thu Jun 28 14:39:46 2018 +0200 @@ -29,6 +29,7 @@ #include "file-ops.h" #include "lo-error.h" #include "lo-sysdep.h" +#include "uniconv-wrappers.h" #include "unistd-wrappers.h" namespace octave @@ -67,5 +68,39 @@ return octave_chdir_wrapper (path.c_str ()); } + + std::wstring + u8_to_wstring (const std::string& utf8_string) + { + wchar_t *wchar = nullptr; + + wchar = u8_to_wchar (utf8_string.c_str ()); + + std::wstring retval = L""; + if (wchar != nullptr) + { + retval = std::wstring (wchar); + free (static_cast (wchar)); + } + + return retval; + } + + std::string + u8_from_wstring (const std::wstring& wchar_string) + { + char *mbchar = nullptr; + + mbchar = u8_from_wchar (wchar_string.c_str ()); + + std::string retval = ""; + if (mbchar != nullptr) + { + retval = std::string (mbchar); + free (static_cast (mbchar)); + } + + return retval; + } } } diff -r 7fb40efda31f -r c63f67d87b4a liboctave/system/lo-sysdep.h --- a/liboctave/system/lo-sysdep.h Wed Jun 27 21:01:58 2018 +0200 +++ b/liboctave/system/lo-sysdep.h Thu Jun 28 14:39:46 2018 +0200 @@ -40,6 +40,10 @@ extern std::string getcwd (void); extern int chdir (const std::string&); + + extern std::wstring u8_to_wstring (const std::string&); + + extern std::string u8_from_wstring (const std::wstring&); } }