wstring

boost spirit parsing quote string fails

旧街凉风 提交于 2021-01-28 11:50:25
问题 This is my grammer unesc_char.add(L"\\a", L'\a')(L"\\b", L'\b')(L"\\f", L'\f')(L"\\n", L'\n') (L"\\r", L'\r')(L"\\t", L'\t')(L"\\v", L'\v')(L"\\\\", L'\\') (L"\\\'", L'\'')(L"\\\"", L'\"'); unesc_str = '\"' >> *((boost::spirit::standard_wide::char_ - '\"') | unesc_char) >> '\"'; with qi::rule<Iterator, std::wstring()> unesc_str; qi::symbols<wchar_t const, wchar_t const> unesc_char; Parsing fails on : "Hello\"" -> should return Hello" Parsing correct on : "Hello\\" -> should return Hello\

XMLCh to wchar_t and vice versa

懵懂的女人 提交于 2021-01-24 12:21:28
问题 My config: Compiler: gnu gcc 4.8.2 I compile with C++11 platform/OS: Linux 64bit Ubuntu 14.04.1 LTS I want to feed a method with wchar_t* and use it in many xecerces library methods that need XMLCh* but I don't know how to translate from one to another. It's easy if you use char* instead of wchar_t* but I need to use wide character. Under windows I could easily cast from one to another but it doesn't work in my linux machine. Somehow I have to manually translate wchar_t* to a XMLCh* I link

XMLCh to wchar_t and vice versa

限于喜欢 提交于 2021-01-24 12:21:18
问题 My config: Compiler: gnu gcc 4.8.2 I compile with C++11 platform/OS: Linux 64bit Ubuntu 14.04.1 LTS I want to feed a method with wchar_t* and use it in many xecerces library methods that need XMLCh* but I don't know how to translate from one to another. It's easy if you use char* instead of wchar_t* but I need to use wide character. Under windows I could easily cast from one to another but it doesn't work in my linux machine. Somehow I have to manually translate wchar_t* to a XMLCh* I link

XMLCh to wchar_t and vice versa

好久不见. 提交于 2021-01-24 12:20:36
问题 My config: Compiler: gnu gcc 4.8.2 I compile with C++11 platform/OS: Linux 64bit Ubuntu 14.04.1 LTS I want to feed a method with wchar_t* and use it in many xecerces library methods that need XMLCh* but I don't know how to translate from one to another. It's easy if you use char* instead of wchar_t* but I need to use wide character. Under windows I could easily cast from one to another but it doesn't work in my linux machine. Somehow I have to manually translate wchar_t* to a XMLCh* I link

How is const std::wstring encoded and how to change to UTF-16

不羁的心 提交于 2020-12-12 09:41:58
问题 I created this minimum working C++ example snippet to compare bytes (by their hex representation) in a std::string and a std::wstring when defining a string with german non-ASCII characters in either type. #include <iostream> #include <iomanip> #include <string> int main(int, char**) { std::wstring wstr = L"äöüß"; std::string str = "äöüß"; for ( unsigned char c : str ) { std::cout << std::setw(2) << std::setfill('0') << std::hex << static_cast<unsigned short>(c) << ' '; } std::cout << std:

How is const std::wstring encoded and how to change to UTF-16

泄露秘密 提交于 2020-12-12 09:38:07
问题 I created this minimum working C++ example snippet to compare bytes (by their hex representation) in a std::string and a std::wstring when defining a string with german non-ASCII characters in either type. #include <iostream> #include <iomanip> #include <string> int main(int, char**) { std::wstring wstr = L"äöüß"; std::string str = "äöüß"; for ( unsigned char c : str ) { std::cout << std::setw(2) << std::setfill('0') << std::hex << static_cast<unsigned short>(c) << ' '; } std::cout << std:

Convert Japanese wstring to std::string

坚强是说给别人听的谎言 提交于 2020-06-29 06:44:19
问题 Can anyone suggest a good method to convert a Japanese std::wstring to std::string ? I used the below code. Japanese strings are not converting properly on an English OS. std::string WstringTostring(std::wstring str) { size_t size = 0; _locale_t lc = _create_locale(LC_ALL, "ja.JP.utf8"); errno_t err = _wcstombs_s_l(&size, NULL, 0, &str[0], _TRUNCATE, lc); std::string ret = std::string(size, 0); err = _wcstombs_s_l(&size, &ret[0], size, &str[0], _TRUNCATE, lc); _free_locale(lc); ret.resize

What is the best way to output Unicode to console?

核能气质少年 提交于 2020-04-16 02:47:51
问题 The bounty expires in 6 days . Answers to this question are eligible for a +50 reputation bounty. Luismi98 is looking for a canonical answer . I am working with C++17 in Visual Studio 2019. I have read a fair bit about encodings but I am still not very comfortable with them. I want to output UNICODE characters to screen. For that, I am using the following code #include <iostream> #include <fcntl.h> #include <io.h> std::wstring symbol{ L"♚" }; _setmode(_fileno(stdout), _O_WTEXT); std::wcout <<

How to portably write std::wstring to file?

送分小仙女□ 提交于 2020-02-12 08:57:14
问题 I have a wstring declared as such: // random wstring std::wstring str = L"abcàdëefŸg€hhhhhhhµa"; The literal would be UTF-8 encoded, because my source file is. [EDIT: According to Mark Ransom this is not necessarily the case, the compiler will decide what encoding to use - let us instead assume that I read this string from a file encoded in e.g. UTF-8] I would very much like to get this into a file reading (when text editor is set to the correct encoding) abcàdëefŸg€hhhhhhhµa but ofstream is

C++ substring multi byte characters

别说谁变了你拦得住时间么 提交于 2020-01-24 06:29:36
问题 I am having this std::string which contains some characters that span multiple bytes. When I do a substring on this string, the output is not valid, because ofcourse, these characters are counted as 2 characters. In my opinion I should be using a wstring instead, because it will store these characters in as one element instead of more. So I decided to copy the string into a wstring, but ofcourse this does not make sense, because the characters remain split over 2 characters. This only makes