Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

GS::UniString Does not support Chinese? I have encountered an issue with garbled Chinese characters.

luna
Contributor

I have encountered an issue with garbled Chinese characters.

 

I have tried many methods but have not been successful, and the Chinese characters will become '?' Or some strange symbols.

 

ac.pngac2.png

 

Please provide me with some ideas, thank you!

2 ACCEPTED SOLUTIONS

Accepted Solutions
Solution
Miklos Vegh
Graphisoft
Graphisoft

Hi,
Of course UniString supports chinese and other languages also. I think that the problem here is the conversion between utf16 and char types.

I suggest using std::wstring instead of std::string in the code.

UniString can be constructed from utf16 character array with the UniString (const UniChar::Layout* uStr) constructor, so you can convert std::wstring to UniString easily.

UniString supports the 8-bit utf8 characters also if needed.

View solution in original post

Solution
Miklos Vegh
Graphisoft
Graphisoft

Or if you have utf8 characters in a file for example, you can construct UniString with this constructor:

char* utf8Chars;

GS::UniString uStr (utf8Chars, CC_UTF8);

View solution in original post

6 REPLIES 6
Solution
Miklos Vegh
Graphisoft
Graphisoft

Hi,
Of course UniString supports chinese and other languages also. I think that the problem here is the conversion between utf16 and char types.

I suggest using std::wstring instead of std::string in the code.

UniString can be constructed from utf16 character array with the UniString (const UniChar::Layout* uStr) constructor, so you can convert std::wstring to UniString easily.

UniString supports the 8-bit utf8 characters also if needed.

Hi, can you provide an example 🙂

std::string str = "D:/ACFiles/中文测试(Chinese Test)";

such as, how to convert 'str' in the above code to GS:: UniString without garbled characters.

 

After trying to convert to wstring, it still doesn't work, just starting from ' Transformed into some strange symbols.

Miklos Vegh
Graphisoft
Graphisoft

I did not compile this code, but I think something like this:

std::wstring wStr = L("中文测试");
GS::UniString uStr (wStr.c_str());

The L() macro forces those characters to compile as utf16.

Solution
Miklos Vegh
Graphisoft
Graphisoft

Or if you have utf8 characters in a file for example, you can construct UniString with this constructor:

char* utf8Chars;

GS::UniString uStr (utf8Chars, CC_UTF8);

Thank you! 

 

I succeeded 🙂

 

I always thought it was an issue with GS:: UniString, but the problem was that I had previously switched between std:: string and std:: wstring multiple times. xD

 

Miklos Vegh
Graphisoft
Graphisoft

🙂

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!