ifcplusplus icon indicating copy to clipboard operation
ifcplusplus copied to clipboard

wstring to string conversion

Open JMLX42 opened this issue 6 years ago • 2 comments

Hello,

I'm on Ubuntu 18.04 64 bit using gcc-8.

I need to convert std::wstring IfcObjectDefinition::m_Name->toString() to an actual UTF-8 std::string. I've made sure my input file is encoded using UTF-8. And it reads fine in my terminal which is using the en_us.UTF-8 locale.

If I use std::wstring_convert<std::codecvt_utf8<wchar_t>>().to_bytes(wstr) I get an std::range_error. If I use boost::locale::conv::utf_to_utf<char, wchar_t>(str);, some characters are missing.

What is the expected way to convert the std::wstring to std::string?

Regards,

JMLX42 avatar Dec 17 '18 15:12 JMLX42

Hi, with Qt, there is a method QString::fromStdWString(...), so I used only that one so far. Other GUI libraries might have a similar function.

ifcquery avatar Dec 17 '18 17:12 ifcquery

with Qt, there is a method QString::fromStdWString(...), so I used only that one so far.

In the Qt app I have bad results too: accentuated characters are corrupted. Which is the result I have too with boost::locale::conv::utf_to_utf<char, wchar_t>(str);.

JMLX42 avatar Dec 17 '18 20:12 JMLX42

solved meanwhile

ifcquery avatar Apr 30 '24 15:04 ifcquery