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

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

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

Post 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.
Last edited by c4s on Fri Sep 11, 2015 9:55 am, edited 1 time in total.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

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

Post 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?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

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

Post 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.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

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

Post 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...
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

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

Post 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.
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
WilliamL
Addict
Addict
Posts: 1252
Joined: Mon Aug 04, 2008 10:56 pm
Location: Seattle, USA

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

Post 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'.
MacBook Pro-M1 (2021), Sequoia 15.4, PB 6.20
Post Reply