Ascii-Strings in Data

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Ascii-Strings in Data

Post by skywalk »

Cool, I should have caught the long also. :oops:
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Ascii-Strings in Data

Post 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
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Ascii-Strings in Data

Post 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)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
bosker
Enthusiast
Enthusiast
Posts: 105
Joined: Fri Jan 08, 2010 11:04 pm
Location: Hampshire, UK

Re: Ascii-Strings in Data

Post 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).
User avatar
Zebuddi123
Enthusiast
Enthusiast
Posts: 794
Joined: Wed Feb 01, 2012 3:30 pm
Location: Nottinghamshire UK
Contact:

Re: Ascii-Strings in Data

Post 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
malleo, caput, bang. Ego, comprehendunt in tempore
User avatar
nco2k
Addict
Addict
Posts: 1344
Joined: Mon Sep 15, 2003 5:55 am

Re: Ascii-Strings in Data

Post 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
If OSVersion() = #PB_OS_Windows_ME : End : EndIf
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Ascii-Strings in Data

Post 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.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
User avatar
kenmo
Addict
Addict
Posts: 1967
Joined: Tue Dec 23, 2003 3:54 am

Re: Ascii-Strings in Data

Post 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 :)
Post Reply