Page 2 of 2

Re: Ascii-Strings in Data

Posted: Thu Mar 23, 2017 5:29 pm
by skywalk
Cool, I should have caught the long also. :oops:

Re: Ascii-Strings in Data

Posted: Thu Mar 23, 2017 9:15 pm
by nco2k
i would prefer this syntax:

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
c ya,
nco2k

Re: Ascii-Strings in Data

Posted: Thu Mar 23, 2017 10:37 pm
by skywalk
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)

Re: Ascii-Strings in Data

Posted: Fri Mar 24, 2017 12:41 am
by bosker
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).

Re: Ascii-Strings in Data

Posted: Fri Mar 24, 2017 1:38 am
by Zebuddi123
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

Re: Ascii-Strings in Data

Posted: Fri Mar 24, 2017 2:43 am
by nco2k
not quite, we want purebasic to turn this:

Code: Select all

DataSection
  HelloUnicode:
    Data.p-unicode "Ћирилица"
  HelloUTF8:
    Data.p-utf8 "Ћирилица"
EndDataSection
into this:

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
at compile time, which is currently not possible. :)

c ya,
nco2k

Re: Ascii-Strings in Data

Posted: Fri Mar 24, 2017 3:35 am
by skywalk
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.

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)
Thanks Bosker for explaining the struct scan interprets the memory as integer 1st. I am easily tricked.

Re: Ascii-Strings in Data

Posted: Fri Mar 24, 2017 2:19 pm
by kenmo
I also did not know about this syntax!

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)
That is one step closer to what I imagined. Doesn't handle UTF-8 though :)