Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (vicknick, AndrewAMD), 1,292 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
file_str_write / str_stri not working with unicode?? #435915
01/16/14 08:45
01/16/14 08:45
Joined: Aug 2008
Posts: 394
Germany
Benni003 Offline OP
Senior Member
Benni003  Offline OP
Senior Member

Joined: Aug 2008
Posts: 394
Germany
Hi, I hope someone can help me with two problems..

1 - I use file_str_write() to write the string into a textfile, but it's not correct working. There is just one symbol. I think with unicode I have to do it in a different way, but how?

2 - I need to get the position of a word in a string. I use str_stri (STRING* content,STRING* search)
for that, but it's also not working with unicode.

I did it in two different ways:

* str content - unicode / str search - standard -> Sometimes working, sometimes crash with nexus too small..(but nexus is enough)
* str content - unicode / str search - unicode -> No crash, but search was not found in content.

I hope someone can help me smirk It's really important...

Re: file_str_write / str_stri not working with unicode?? [Re: Benni003] #436024
01/17/14 10:14
01/17/14 10:14
Joined: Aug 2008
Posts: 394
Germany
Benni003 Offline OP
Senior Member
Benni003  Offline OP
Senior Member

Joined: Aug 2008
Posts: 394
Germany
Is there anyone who knows how to do it? I really need it soon smirk
the first point is for writing a savegame name in unicode.
The second point is to paste a value into a text of a message box.
Example:
in the textfile: You have got |#VALUE#| points left.
in the game: You have got 12 points left.
- with str_stri() thats easy to do, but with unicode something is not working...
I need to do it in this way because the game will release in different languages. And the sentence constructions will be different.

Re: file_str_write / str_stri not working with unicode?? [Re: Benni003] #436027
01/17/14 10:31
01/17/14 10:31
Joined: Aug 2002
Posts: 3,258
Mainz
oliver2s Offline
Expert
oliver2s  Offline
Expert

Joined: Aug 2002
Posts: 3,258
Mainz
I can't directly solve your problems. But I've worked a lot with unicode strings. And you have to be always sure that the string content ist Unicode. I do it this way:

1. Create a TEXT with a Unicode font
Code:
FONT* arial15b_unicode_font="Arial#15b";
TEXT* txt_unicode_helper = { strings = 1; font = arial15b_unicode_font; }



2. Make a Unicode text file (for example "unicode_helper.txt"). The content of this file will be just 1 char (for example "#"). Make sure you save this file with Unicode encoding!
Code:
#



4. Load the external text file into the TEXT
Code:
txt_loadw(txt_unicode_helper ,"unicode_helper.txt");



5. Now on every string you want to use do the following:
Code:
str_cpy(myString,(txt_unicode_helper .pstring)[0]); //copy the unicode char '#' in the string to make it unicode
str_cat(myString,... //do with your string whatever you want
str_clip(myString,1);//remove the helper unicode char


Re: file_str_write / str_stri not working with unicode?? [Re: oliver2s] #436033
01/17/14 13:08
01/17/14 13:08
Joined: Aug 2008
Posts: 394
Germany
Benni003 Offline OP
Senior Member
Benni003  Offline OP
Senior Member

Joined: Aug 2008
Posts: 394
Germany
Thank you for your answer Oliver!
I remember that I did like this in a previous problem. Now its Working!!!
But one thing I can't understand... the string search I've created as this before:
str_search = str_createw("|#VALUE#|");
str_createw("") should create Unicode strings, but why this is not working? In the way you wrote before everything is fine.

Re: file_str_write / str_stri not working with unicode?? [Re: Benni003] #436035
01/17/14 13:27
01/17/14 13:27
Joined: Aug 2002
Posts: 3,258
Mainz
oliver2s Offline
Expert
oliver2s  Offline
Expert

Joined: Aug 2002
Posts: 3,258
Mainz
Originally Posted By: Benni003
str_createw("") should create Unicode strings, but why this is not working? In the way you wrote before everything is fine.


Yes I know, that's why I use the approach above. I also don't know why str_createw("") doesn't work. Maybe because it only works with non-empty strings (didn't tested it).

Re: file_str_write / str_stri not working with unicode?? [Re: oliver2s] #436036
01/17/14 13:34
01/17/14 13:34
Joined: Apr 2007
Posts: 3,751
Canada
WretchedSid Offline
Expert
WretchedSid  Offline
Expert

Joined: Apr 2007
Posts: 3,751
Canada
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
Re: file_str_write / str_stri not working with unicode?? [Re: WretchedSid] #436069
01/18/14 11:53
01/18/14 11:53
Joined: Aug 2008
Posts: 394
Germany
Benni003 Offline OP
Senior Member
Benni003  Offline OP
Senior Member

Joined: Aug 2008
Posts: 394
Germany
ok, Thank you for you answers. Now just one Problem is left. How to write an unicode String into a textfile?

Re: file_str_write / str_stri not working with unicode?? [Re: Benni003] #436198
01/21/14 14:21
01/21/14 14:21
Joined: Aug 2008
Posts: 394
Germany
Benni003 Offline OP
Senior Member
Benni003  Offline OP
Senior Member

Joined: Aug 2008
Posts: 394
Germany
Slowly it's getting really important for me to know how to write a unicode String into a textfile. I hope someone can help me. smirk

Re: file_str_write / str_stri not working with unicode?? [Re: Benni003] #436200
01/21/14 14:33
01/21/14 14:33
Joined: Aug 2002
Posts: 3,258
Mainz
oliver2s Offline
Expert
oliver2s  Offline
Expert

Joined: Aug 2002
Posts: 3,258
Mainz
Sorry, I just didn't see your answer. You have add 2 bytes (255 and 254) at the beginning of your unicode file for encoding. Then you can use file_str_write as usual

Here you go:
Code:
var file=file_open_write("unicodeFile.txt");
	
//add unicode encoding
file_asc_write(file,255); 
file_asc_write(file,254);
	
//writing unicode strings works with file_str_write
file_str_write(file,myUnicodeString);
	
file_close(file);


Re: file_str_write / str_stri not working with unicode?? [Re: oliver2s] #436204
01/21/14 14:58
01/21/14 14:58
Joined: Aug 2008
Posts: 394
Germany
Benni003 Offline OP
Senior Member
Benni003  Offline OP
Senior Member

Joined: Aug 2008
Posts: 394
Germany
ok, thank you Oliver! laugh


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1