Results 1 to 2 of 2
  1. #1

    Member Since
    Jan 16, 2013
    Cool C++ Character Encoding in Mac
    I'm developing a Cross Platform File Sync Application.In Mac OS X to get File System events, i read from /dev/fsevents system buffer and send it over unix sockets to another app. I'm not doing any character encoding until now.

    This is my Print in app which recieves the FS Events :
    ######## File Name ::: b123.rtf
    ######## File Name in WCHAR ::: b123.rtf

    code which i used to convert char to wchar

    int wCharLen1 = mbstowcs(NULL, fName, 0); // fName is the char which i recieved through unix socket
    WCHAR* fileName = new WCHAR[wCharLen1 + 1];
    memset(fileName,'\0',(wCharLen1 + 1) *sizeof(WCHAR));
    mbstowcs(fileName, fName, wCharLen1);

    I'm sending the file name to my Server and have printed the file name before DB Insert, which prints the exact file name :

    ######## Recieved File Name ::: b123.rtf

    But in DB it inserts the file Name as 'ébê123.rtf'

    I'm using the same code in Windows except i don't have to do wchar conversion, because the Windows Directory Monitoring itself gives the file name in wchar. I don't have any issues with the windows client and the file name is inserted correctly in the database as ' b123.rtf '. I suspect that i'm missing some encoding before converting char to wchar in Mac. I have tried encoding to UTF-8 , but the file Names have changed to
    ######### FileName ::: b123.rtf after Encoding TO UTF-8 ::: ébê123.rtf [MAC]

    Another Case :

    When uploading files from Windows with the above file name 'b123.rtf' , the file gets downloaded in Mac with the correct file name. But when the file is uploaded from Mac , then the file name seems to be downloaded correctly in Windows, but as soon as i change anything in that file, the file name is sent as 'e%cc%81be%cc%82123.rtf' to Server,then to Mac. But if i originally create the file 'b123.rtf' in Windows, then it is sent correctly.

    I suspect i have to encode the file name in mac to UTF-8 string before converting char to wchar in Mac. But i have tried some open source code like the one below :
      void latin1_to_utf8(unsigned char *in, unsigned char *out)
        while (*in)
          if (*in<128)
        *out = '\0';

    But it didn't worked. Now i'm looking for a library or some code to convert the string to utf-8 string in C++ in Mac.Of Course this function works when the file name is recieved from Windows to Mac. Any ideas ..?

  2. #2

    vansmith's Avatar
    Member Since
    Oct 19, 2008
    Early 2015 13" rMBP
    Moved to more appropriate forum - this is a development question.
    Important Links: Community Guidelines : Use the reputation system if you've been helped.
    M-F Blog :: Write for the blog
    Writing a Quality Post

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Changing Mac Character Code (Glyphs)
    By Ubereinkunft in forum macOS - Development and Darwin
    Replies: 3
    Last Post: 02-02-2012, 11:35 PM
  2. Windows media encoding on a mac for streaming
    By hansonc8 in forum Music, Audio, and Podcasting
    Replies: 1
    Last Post: 01-09-2010, 11:28 AM
  3. Mac OS X Terminal Program-Insert character
    By IT@MYRONL.COM in forum macOS - Apps and Games
    Replies: 4
    Last Post: 07-27-2006, 11:25 PM
  4. Mac PVR Question: Hardware or Software Encoding?
    By Books in forum Other Hardware and Peripherals
    Replies: 0
    Last Post: 04-21-2006, 01:23 AM
  5. Mac as Character Generator...?
    By stickball in forum Movies and Video
    Replies: 2
    Last Post: 01-21-2006, 08:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts