Skip navigation
sameervijaykar
Currently Being Moderated

UTF-8 string from PMString

Feb 6, 2012 7:37 AM

Tags: #mac #utf-8 #pmstring

Hi,

 

I am trying to convert a PMString object into a UTF-8 char* object for use with POSIX functions on a Mac. The PMString object will contain multibyte characters like Chinese, Japanese etc. I receive this PMString object from a ScriptData object which only gives a PMString or a WideString.

 

Using PMString.GrabCString() causes the multibyte characters to appear as code values (<4E00>) in the char* strings. I've explored a couple of ways to convert a wide char* (wchar_t*) into a UTF-8 char* on a Mac. However, the basic problem seems to be that PMString internally stores the text in UTF-16 while wchar_t is 32 bit on Mac. As a result, when I call methods like GrabUTF16Buffer or GrabWString or even GetWChar_tString, I seem to be getting a corrupt wchar_t* string with UTF-16 characters stuffed into a 32 bit wide character array. I can't seem to form the same text back from the wchar_t* string using PMString(wchar_t*) or even explicit typecasting as PMString(UTF16Char*, numBytes).

 

To summarize, starting with a PMString, how do I get/convert it's contents into a valid UTF-8 char* string, knowing it will contain multibyte characters? Thank you for your time.

 
Replies
  • Currently Being Moderated
    Feb 6, 2012 7:39 AM   in reply to sameervijaykar

    Hi,

     

    did you try the function StringUtils::ConvertWideStringToUTF8?

     

    Markus

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 23, 2012 12:50 PM   in reply to sameervijaykar

    ScriptData has a GetFile() method. You should then use FileUtils and/or OSX services to extract the path.

    Btw be careful with UTF8 vs. OSX Posix file names, if there is a chance your environment may use NFS mounts etc.

     

    Apple's technote gives some details for driver developers, but the same problem also applies to us:

    https://developer.apple.com/library/mac/#qa/qa1173/_index.html

     

    Dirk

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points