New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

C++ Character Encoding in Mac


Post Reply New Thread Subscribe

 
Thread Tools
manis

 
Member Since: Jan 16, 2013
Posts: 1
manis is on a distinguished road

manis is offline
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 :
Code:
  void latin1_to_utf8(unsigned char *in, unsigned char *out)
  {
    while (*in)
    {
      if (*in<128)
      {
        *out++=*in++;
      }
      else 
      {
        *out++=0xc2+(*in>0xbf);
        *out++=(*in++&0x3f)+0x80;
      }
    }
    *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 ..?
QUOTE Thanks
vansmith

 
vansmith's Avatar
 
Member Since: Oct 19, 2008
Location: Toronto
Posts: 17,685
vansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond reputevansmith has a reputation beyond repute
Mac Specs: 2012 13" MBP (2.5 i5, 8GB)

vansmith is offline
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
Personal Twitter
QUOTE Thanks

Post Reply New Thread Subscribe


« AppleScript - I get a {} when trying to separate items into categories. | RABCDAsm and Yogda Alternatives »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Running Windows on a Mac: A Switcher's Guide cwa107 Running Windows (or anything else) on your Mac 283 03-13-2014 04:15 PM
OS 10.7 Lion feature/rumour roundup the8thark Apple Rumors and Reports 44 08-17-2011 02:03 PM
Five ways Apple can improve the Mac App Store OneMoreThing... Apple Rumors and Reports 0 07-16-2011 08:42 PM
Is Apple ready to play cat and mouse with malware developers? OneMoreThing... Apple Rumors and Reports 3 06-04-2011 10:10 PM
The conversations you should get into with anti Mac folk 6string Schweb's Lounge 13 05-12-2011 04:28 PM

All times are GMT -4. The time now is 08:36 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?