BOM and ReadString

Just starting out? Need help? Post your questions and find answers here.
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

BOM and ReadString

Post by IdeasVacuum »

File with a BOM prefix (Byte Order Mark)

If ReadString() is used to read a file line-by-line, all is well.

If however ReadString() is used to read the whole file, flagged #PB_File_IgnoreEOL, the BOM is included in the String, which is a pity.

Edit: The solution is to use ReadStringFormat() first, which will move the file pointer behind the BOM if one is detected.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: BOM and ReadString

Post by STARGÅTE »

No problem here:

Code: Select all

If ReadFile(1, "Test.txt")
	ReadStringFormat(1)
	Debug ReadString(1, #PB_File_IgnoreEOL)
	CloseFile(1)
EndIf
Test.txt wrote: %EF%BB%BFTest%0D%0ATest
Debugger wrote: TestTest
Edit: ok
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: BOM and ReadString

Post by IdeasVacuum »

...it's not that it's a problem, just that #PB_File_IgnoreEOL is inconsistent, given that without that flag, the BOM is ignored.

Edit: Related BOM issues:
http://www.purebasic.fr/english/viewtop ... 66#p433766
http://www.purebasic.fr/english/viewtop ... 13&t=55125
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply