Page 1 of 1

Automatically Read/Write Format for Read/Open/CreateFile()

Posted: Fri Sep 04, 2015 6:39 pm
by c4s
Fred wrote:

Code: Select all

- Added: #PB_Ascii, #PB_UTF8 and #PB_Unicode support to Create/Open/ReadFile() to set the default write/read mode
Inspired by this new feature introduced in PB5.40b3 I thought a similar new "intuitive" option that automatically reads/writes the default string format would be handy.

Example for ReadFile() (or OpenFile()):

Code: Select all

; Normal way:
If ReadFile(0, File)
	Format = ReadStringFormat(0)
	
	String = ReadString(0, Format)
EndIf

; More intuitive:
If ReadFile(0, File, #PB_File_AutoStringFormat)
	String = ReadString(0)
EndIf
Example for CreateFile():

Code: Select all

; Old way:
Format = #PB_UTF8
If CreateFile(0, File)
	WriteStringFormat(0, Format)
	
	WriteStringN(0, String, Format)
EndIf

; New way (PB5.40b3):
Format = #PB_UTF8
If CreateFile(0, File, Format)
	WriteStringFormat(0, Format)
	
	WriteStringN(0, String)
EndIf

; Even better:
If CreateFile(0, File, #PB_UTF8 | #PB_File_AutoStringFormat)
	WriteStringN(0, String)
EndIf
Edit:
#PB_File_AutoStringFormat isn't official. It's my proposal for a new flag.

Re: Automatically Read/Write Format for Read/Open/CreateFile

Posted: Fri Sep 04, 2015 6:55 pm
by ts-soft
What is, when you use #PB_UTF8 without a BOM? WriteStringFormat is only to write a BOM,
so a automated BOM is not always recommend. Or i understand it false?

Re: Automatically Read/Write Format for Read/Open/CreateFile

Posted: Fri Sep 04, 2015 8:05 pm
by c4s
The shown "new way" for CreateFile() is already implemented. So if you don't want the string format to be automatically written you simply wouldn't use the proposed #PB_File_AutoStringFormat flag.

Re: Automatically Read/Write Format for Read/Open/CreateFile

Posted: Thu Sep 10, 2015 11:04 pm
by WilliamL

Code: Select all

Result = CreateFile(#File, Filename$ [, Flags])
A new flag was added ( #PB_File_AutoStringFormat ) to the CreateFile(#file,filename$,#PB_File_AutoStringFormat)? How about CreateFile(#File, Filename$,#PB_Ascii or #PB_UTF8 or #PB_Unicode) ? If you use the #PB_File_AutoStringFormat flag (or either of the other three flags) do you need to write the WriteStringFormat()? And I'm assuming that the WriteStringFormat() is automatically added if the saving is in the default unicode compiler mode?

I'm finding that it doesn't seem to matter if the file being read is in ascii if I'm in the unicode mode. (It DOES matter if I try to read a unicode file in ascii mode).

Right now I'm checking the bom=ReadStringFormat() then reading using ReadString(#File,bom).

Maybe I'm over-thinking this...

Re: Automatically Read/Write Format for Read/Open/CreateFile

Posted: Fri Sep 11, 2015 9:53 am
by c4s
WilliamL wrote:[...] If you use the #PB_File_AutoStringFormat flag (or either of the other three flags) do you need to write the WriteStringFormat()? And I'm assuming that the WriteStringFormat() is automatically added if the saving is in the default unicode compiler mode?
I'm not sure if you're confusing something here... #PB_File_AutoStringFormat is not official, it's my proposal. And no, Read/WriteStringFormat() isn't used automatically (e.g. see Fred's reply here). Again, that's what this feature request is for.

Re: Automatically Read/Write Format for Read/Open/CreateFile

Posted: Fri Sep 11, 2015 3:27 pm
by WilliamL

Code: Select all

Added: #PB_Ascii, #PB_UTF8 and #PB_Unicode support to Create/Open/ReadFile() to set the default write/read mode
Here Fred seems to be saying he has made a change and that was what I was asking about but it is not explained in 'Help'.