It's because it expects a Unicode string already. You supply it with an ASCII string, where each character is 1 byte. In UTF16, each character is at least 2 bytes, with surrogate pairs having 4 bytes.

You can write your own transform function easily, luckily all it takes is taking each character of your ASCII string and putting it into a 2 byte integer, and then supplying that to str_createw(). Here is an example (don't forget to free the string):

Code:
short *convert_ASCII_to_utf16(const char *string)
{
	size_t length = strlen(string);
	short *utf16 = malloc(length + 1 * sizeof(short));

	short *temp = utf16;
	while(*string)
		*temp ++ = *string ++;

	*temp ++ = 0; // 0 Terminate the string
	return utf16;
}



Of course it makes sense to wrap the above in a function like this:
Code:
STRING *str_createw_from_ASCII(const char *cstring)
{
	short *wstring = convert_ASCII_to_utf16(cstring);
	STRING *string = str_createw(wstring);
	free(wstring);

	return string;
}



Also, it gets more complicated once you go outside of the 7 bit ASCII range, but the first code page in Unicode is luckily identical, making the example above work.


Edit: If Lite-C is still unable to handle postfix increments correctly, you need to adapt the function above accordingly (and probably file some bug reports)

Last edited by JustSid; 01/17/14 13:39.

Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com