Jump to content

wchar_t ro xchar2b?


Josh
 Share

Recommended Posts

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;

Link to comment
Share on other sites

UTF8 is capable of encoding all possible characters defined by Unicode, which is over one million characters.

https://en.wikipedia.org/wiki/UTF-8

 

If you just use UTF8 for ASCII text (0 to 127), it looks exactly the same. It uses a single byte for a single character. But, higher up, it uses 2 or 3 bytes per character.

  • Upvote 1

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

Link to comment
Share on other sites

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.

 Share

×
×
  • Create New...