Encoding problem converting c4d String to std



  • On 30/07/2015 at 02:00, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:   R16 
    Platform:   Windows  ;   
    Language(s) :     C++  ;

    ---------
    Greetings !

    I use FileSelect to allow the user pick the save location.
    Even if he picks a non-english character path, it is printed as given with GePrint.

    To convert that tring to std string i use GetCString and STRINGENCODING_UTF8.
    But the non-english characters are not replaced correctly.
    I have also used STRINGENCODING_8BIT and i get the same problem.

    How can i convert C4D strings to std strings without getting trash characters ?

    thnx.



  • On 30/07/2015 at 11:52, xxxxxxxx wrote:

    For Unicode using the Standard Library, you should probably use std::wstring since the std::string, while it may allow Unicode (UTF-8) in the string, doesn't support it otherwise (in operations).  Your best bet is to do a conversion from C4D String to std::wstring and check that you are getting UTF-8-compliant values stored in the wstring.  C++ Unicode support is rather tenuous and I have seen suggestions of using a third-party library support for it instead of the std support.



  • On 30/07/2015 at 20:54, xxxxxxxx wrote:

    storing utf-8 encoded string in a std::wstring doesn't make much sense in my opinion, as utf-8 uses 8 bit code units. Storing utf-8 encoded data in a std::string should be perfectly fine. What you can store in an std::wstring depends on the platform, on windows this would be utf-16, on linux or osx it's utf-32 if i recall correctly.

    As said before std::string and std::wstring are both unicode agnostic (they're just a sequence of char/wchar_t). So if you store utf-8 or utf-16 encoded data (both variable length encodings) in a std::string or a std::wstring you shouldn't use the builtin string operations as these can invalidate the utf encoding. With utf-32 that shouldn't be a problem as that is a fixed length encoding.

    Now, what type of string you should be using really depends on what you're doing with the string. On windows a std::wstring with utf-16 encoded data is often a safe bet because the windows api uses utf-16.

    So if you're getting thrash characters it really depends on what are you actually doing with that string.
    To help you any further please post the code where you convert the string and the code where you're actually using it (e.g. to call some api function).



  • On 07/08/2015 at 08:59, xxxxxxxx wrote:

    Hello peterakos,

    was your question answered?

    Best wishes,
    Sebastian



  • On 11/08/2015 at 03:47, xxxxxxxx wrote:

    Greetings ! 
    Yes it was answered.
    Thnx.


Log in to reply