Saving Unicode Files

BlitzMax Forums/BlitzMax Programming/Saving Unicode Files

Grey Alien(Posted 2009) [#1]
Hi, so I discovered that WriteSteam saves as ANSI by default and that I can do this to save in UTF-8:

WriteStream("utf8::" + filename)


But how do I save as UTF-16? If I do:

WriteStream("utf16::" + filename)


I get an unhandled memory exception.

Thanks for any help.

I'm also about to encounter the issue where users can enter non-ASCII chars in their name and my game will crash when it tries to save their profile using those chars as the filename. I was wondering if BMax V1.32 has Unicode IO support yet (Mark mentioned Unicode improvements)? Anyone know? Thanks.


SebHoll(Posted 2009) [#2]
Have you had a look at the SaveText$() command?


Grey Alien(Posted 2009) [#3]
Yeah just found it! Thanks anyway. What is particularly dumb is that I was using LoadText anyway!


Brucey(Posted 2009) [#4]
I was wondering if BMax V1.32 has Unicode IO support yet

I hope so!!


Grey Alien(Posted 2009) [#5]
Perfect timing as I'm about to release a Japanese version of Unwell Mel and the player names will contain Unicode chars and will need to write files containing those chars in the FILENAME (or was that supported already in V1.30?).

However, there may be some other issues with 1.32 to do with jerkiness in Windowed mode that may prevent me using this version (see the Fixed Rate Logic thread http://www.blitzbasic.com/Community/posts.php?topic=83511#948261 ).

But then again if the OpenAL memory leak has been fixed properly I'm tempted...


Brucey(Posted 2009) [#6]
or was that supported already in V1.30?

No. 1.30 doesn't support non-ascii characters in filenames.


degac(Posted 2009) [#7]

Hi, so I discovered that WriteSteam saves as ANSI by default and that I can do this to save in UTF-8:
WriteStream("utf8::" + filename)



Interesting, where do you find this 'proto definition'?
I just opened TextStream.bmx and I found these one (nowhere in my documentation v1.32b v1.32 - I don't know if the latest release is updated...)

		Case "latin1"
			encoding=TTextStream.LATIN1
		Case "utf8"
			encoding=TTextStream.UTF8
		Case "utf16be"
			encoding=TTextStream.UTF16BE
		Case "utf16le"
			encoding=TTextStream.UTF16LE
		End Select


So I suppose UFT16BE / LE must be used based on the platform (x86/PowerPC) - and are managed automatically by Blitmax?

Can SaveText use these proto (LATIN1:: UTF8:: UTF16:: )? LoadText should read it automatically? (Yes I know the answer - try it... but here is early morning and I'm still in Orfeo's world...)