Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Encoding problem converting c4d String to std

    SDK Help
    0
    5
    491
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Helper
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • H
        Helper
        last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • H
          Helper
          last edited by

          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).

          1 Reply Last reply Reply Quote 0
          • H
            Helper
            last edited by

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

            Hello peterakos,

            was your question answered?

            Best wishes,
            Sebastian

            1 Reply Last reply Reply Quote 0
            • H
              Helper
              last edited by

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

              Greetings ! 
              Yes it was answered.
              Thnx.

              1 Reply Last reply Reply Quote 0
              • First post
                Last post