Jump to content

Recommended Posts

Posted

Hi Josh! Maybe this will help:

 

Code from here: http://xopendisplay.hilltopia.ca/2009/Mar/

int utf8toXChar2b(XChar2b *output_r, int outsize, const char *input, int inlen){
int j, k;
for(j =0, k=0; j < inlen && k < outsize; j ++){
	unsigned char c = input[j];
	if (c < 128)  {
		output_r[k].byte1 = 0;
		output_r[k].byte2 = c; 
		k++;
	} else if (c < 0xC0) {
		/* we're inside a character we don't know  */
		continue;
	} else switch(c&0xF0){
	case 0xC0: case 0xD0: /* two bytes 5+6 = 11 bits */
		if (inlen < j+1){ return k; }
		output_r[k].byte1 = (c&0x1C) >> 2;
		j++;
		output_r[k].byte2 = ((c&0x3) << 6) + (input[j]&0x3F);
		k++;
		break;
	case 0xE0: /* three bytes 4+6+6 = 16 bits */ 
		if (inlen < j+2){ return k; }
		j++;
		output_r[k].byte1 = ((c&0xF) << 4) + ((input[j]&0x3C) >> 2);
		c = input[j];
		j++;
		output_r[k].byte2 = ((c&0x3) << 6) + (input[j]&0x3F);
		k++;
		break;
	case 0xFF:
		/* the character uses more than 16 bits */
		continue;
	}
}
return k;
}

 

And convert char* to wchar_t

 

wchar_t * filename= L"C:\\test";
char* c = (char*)filename;

Posted

You can still use it if you convert wchar_t to UTF8 first, then to XChar2b.

 

Note that the size of wchar_t is different on Windows/Linux OSes. 2 bytes for Windows, 4 bytes for Linux.

wchar_t is not portable friendly, which is why most people use UTF8.

Ultimate Unwrap 3D: http://www.unwrap3d.com

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...