Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Use maxon::StringDecodings::Utf8()

    Cinema 4D SDK
    c++ r20
    2
    3
    655
    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.
    • O
      Ogers
      last edited by r_gigante

      std::string SceneParser::GetIDString(BaseList2D* node){
      Int memsize=0;
      const Char* mem;
      node->FindUniqueID(MAXON_CREATOR_ID, mem,  memsize);
      String ID_STR;
      ID_STR.SetCString(mem,memsize);
      std::string result=StringToStdString(ID_STR);
      return result;
      

      }

      Hello. I have this function but when I try the debugger it breaks showing this

       DebugStop("Undefined encoding. Use maxon::StringDecodings::Utf8()");
      

      The Debugger Stops in this line "ID_STR.SetCString(mem,memsize);" which is a function of c4d_string.h from the framework.
      I understand what the error is but I am not finding the proper way to use "maxon::StringDecodings::Utf8()" so the function will work properly later. Is there any way I can fix this problem.
      Thank you in advance!

      1 Reply Last reply Reply Quote 0
      • r_giganteR
        r_gigante
        last edited by

        Hi Ogers, thanks for reaching us.

        With regard to your request, it's enough to pass the STRINGENCODING::UTF8 but I warmly suggest you to move from old string and use the maxon::String since the old implemetation just relies on the maxon::StringInterface::SetCString() method.

        Last but not least consider that you can initialize both a String or maxon::String directly by passing a Char* (see respectively here and here)

        For the sake of completeness, please find below a short snippet showing how to properly use SetCString()

        #include "maxon/stringencoding.h"
        
        maxon::Result<void> TestOnCString(BaseDocument *doc)
        {
        	iferr_scope;
        	
        	if (!doc)
        		return maxon::IllegalArgumentError(MAXON_SOURCE_LOCATION);
        	
        	Int memsize = 0;
        	const Char* mem;
        	
        	// try to find something meaningful
        	if (doc->FindUniqueID(MAXON_CREATOR_ID, mem,  memsize))
        	{
        		String c4dStr;
        		c4dStr.SetCString(mem, memsize, STRINGENCODING::UTF8);
        		DiagnosticOutput("c4dStr: @", maxon::String(c4dStr));
        	}
        
        	// add a more meaningful string
        	const Int mysize = 5;
        	const Char chars[mysize] = "MyID";
        	const Int myID = 12345;
        	doc->AddUniqueID(myID, chars, mysize);
        	if (doc->FindUniqueID(012345, mem,  memsize))
        	{
        		maxon::String maxonStr;
        		const maxon::StringDecodingRef& stringDecoding = maxon::StringDecodings::Utf8();
        		maxonStr.SetCString(mem, memsize, stringDecoding) iferr_return;
        		DiagnosticOutput("maxonStr: @", maxonStr);
        	}
        	
        	return maxon::OK;
        
        }
        

        Best, Riccardo

        1 Reply Last reply Reply Quote 2
        • O
          Ogers
          last edited by

          @r_gigante Thank you for your help. I used the maxon::String and it works fine.

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