i played with unicode a bit and must say, it sure is a great thing. thanks for Write- & ReadStringFormat() and the optional flags in Write- & ReadXYZ(), it makes our way of coding very flexible. and because of that, i am asking for two more functions to improve the flexibility even more:
Code: Select all
Procedure WriteStringNullByte(File, Format=-1);specifies the end of a string
If Format = -1
Select SizeOf(Character)
Case 1
Format = #PB_Ascii
Case 2
Format = #PB_UTF8
EndSelect
EndIf
Select Format
Case #PB_Ascii, #PB_UTF8
WriteByte(File, 0)
Case #PB_Unicode
WriteWord(File, 0)
EndSelect
EndProcedure
Procedure BOMSize(Format=-1);returns the size in byte of a BOM (Byte Order Mark)
If Format = -1
Select SizeOf(Character)
Case 1
Format = #PB_Ascii
Case 2
Format = #PB_UTF8
EndSelect
EndIf
Select Format
Case #PB_Ascii
Result = 0
Case #PB_Unicode
Result = 2
Case #PB_UTF8
Result = 3
EndSelect
ProcedureReturn Result
EndProcedure
FileName.s = "C:\Test.txt"
Format = #PB_Unicode
DeleteFile(FileName)
FileID = OpenFile(#PB_Any, FileName)
If FileID
WriteStringFormat(FileID, Format)
WriteString(FileID, "TestA", Format)
WriteStringNullByte(FileID, Format)
WriteString(FileID, "TestB", Format)
WriteStringNullByte(FileID, Format)
WriteString(FileID, "TestC", Format)
WriteStringNullByte(FileID, Format)
FileSeek(FileID, BOMSize(Format))
Debug ReadString(FileID, Format)
Debug ReadString(FileID, Format)
Debug ReadString(FileID, Format)
CloseFile(FileID)
EndIf
DeleteFile(FileName)

edit: added If Format = -1 in the BOMSize() procedure aswell.
c ya,
nco2k