Ascii-Strings in Data
Re: Ascii-Strings in Data
Cool, I should have caught the long also.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Ascii-Strings in Data
i would prefer this syntax:
c ya,
nco2k
Code: Select all
Debug PeekS(?HelloAscii, -1, #PB_Ascii)
Debug PeekS(?HelloUnicode, -1, #PB_Unicode)
Debug PeekS(?HelloUTF8, -1, #PB_UTF8)
DataSection
HelloAscii:
Data.p-ascii "Hello Ascii!"
HelloUnicode:
Data.p-unicode "Hello Unicode!"
HelloUTF8:
Data.p-utf8 "Hello UTF8!"
EndDataSection
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Re: Ascii-Strings in Data
Wow, I did not know PB converts the string data? So, you can store Ascii in DataSections but UTF8 may not be real. Retrieval requires the length of each String to traverse. The boundless structured pointer fails with an IMA?
Code: Select all
Structure Scan
i.i[0]
EndStructure
DataSection
IsAscii:
Data.a "Ascii 1", "Ascii 2", "Ascii 3"
IsUnicode:
Data.c "Unicode 1", "Unicode 2"
IsUTF8:
Data.a "UTF8 1", "UTF8 2"
EndDataSection
ShowMemoryViewer(?IsAscii, 32)
Define.s s$
Define *scan.Scan = ?IsAscii
Debug "--Using PeekS(*scan)--"
Debug PeekS(*scan, -1, #PB_Ascii) ; OK
Debug PeekS(*scan+Len("Ascii 1")+1, -1, #PB_Ascii) ; OK
Debug PeekS(*scan+Len("Ascii 1")+1+Len("Ascii 2")+1, -1, #PB_Ascii) ; OK
;Debug PeekS(*scan\i[0], -1, #PB_Ascii) ;<-- IMA?
Restore IsUnicode
Read.s s$
Debug "--Using Read.s--"
Debug s$
Debug "--Using PeekS(label)--"
Debug PeekS(?IsAscii, -1, #PB_Ascii)
Debug PeekS(?IsUnicode, -1, #PB_Unicode)
Debug PeekS(?IsUTF8, -1, #PB_UTF8)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Ascii-Strings in Data
Well, I didn't know PB would create strings in Data with .a and .c. So I learned something new today.
I don't suppose this is documented anywhere. (Or is it?)
Incidentally, the IMA occurs because *scan is pointing at the string data for "Ascii 1".
Using *scan\i[0] interprets the string characters as an integer (address).
I don't suppose this is documented anywhere. (Or is it?)
Incidentally, the IMA occurs because *scan is pointing at the string data for "Ascii 1".
Using *scan\i[0] interprets the string characters as an integer (address).
- Zebuddi123
- Enthusiast
- Posts: 794
- Joined: Wed Feb 01, 2012 3:30 pm
- Location: Nottinghamshire UK
- Contact:
Re: Ascii-Strings in Data
Hi To All As a Macro
Code: Select all
Define a.s
Macro _ReadAscii( MemoryAddress, VarName)
Read.s VarName
MemoryAddress = Ascii(VarName)
VarName = PeekS(MemoryAddress, Len(VarName), #PB_Ascii)
EndMacro
Restore ty
For i = 1 To 4
_ReadAscii( buffer.i, myinfo.s)
Debug myinfo
ShowMemoryViewer(buffer, Len(myinfo))
Delay(1500)
Next
DataSection
ty:
Data.s "Hello World !"
Data.s "This is my "
Data.s "little macro"
Data.s "Effort!!!!"
EndDataSection
malleo, caput, bang. Ego, comprehendunt in tempore
Re: Ascii-Strings in Data
not quite, we want purebasic to turn this:
into this:
at compile time, which is currently not possible.
c ya,
nco2k
Code: Select all
DataSection
HelloUnicode:
Data.p-unicode "Ћирилица"
HelloUTF8:
Data.p-utf8 "Ћирилица"
EndDataSection
Code: Select all
DataSection
HelloUnicode:
Data.b $0B, $04, $38, $04, $40, $04, $38, $04, $3B, $04, $38, $04, $46, $04, $30, $04, $00, $00
HelloUTF8:
Data.b $D0, $8B, $D0, $B8, $D1, $80, $D0, $B8, $D0, $BB, $D0, $B8, $D1, $86, $D0, $B0, $00
EndDataSection
c ya,
nco2k
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
Re: Ascii-Strings in Data
Yes, you are missing UTF-8 which is not always 1 or 2bytes/char. Especially with the characters you posted. But, the Unicode is stored as you ask.
Thanks Bosker for explaining the struct scan interprets the memory as integer 1st. I am easily tricked.
Code: Select all
DataSection
IsUnicodeC:
Data.c "Ћирилица", "Ћирилица2", "Ћирилица3"
IsUnicodeS:
Data.s "Ћирилица", "Ћирилица2", "Ћирилица3"
EndDataSection
ShowMemoryViewer(?IsUnicodeS, 64)
Restore IsUnicodeS
Read.s s$
Debug "--Using Read.s--"
Debug s$
Restore IsUnicodeC
Read.s s$
Debug "--Using Read.s--"
Debug s$
Debug "--Using PeekS(label)--"
Debug PeekS(?IsUnicodeC, -1, #PB_Unicode)
Debug PeekS(?IsUnicodeS, -1, #PB_Unicode)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
Re: Ascii-Strings in Data
I also did not know about this syntax!
That is one step closer to what I imagined. Doesn't handle UTF-8 though
Code: Select all
DataSection
AsciiData:
Data.a "Hello!" : Data.a #NUL
UnicodeData:
Data.u "Hello!" : Data.u #NUL
EndDataSection
Debug PeekS(?AsciiData, -1, #PB_Ascii)
Debug PeekS(?UnicodeData, -1, #PB_Unicode)