Page 5 of 15

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 9:42 am
by Lebostein
What about reading binary files? I have many structures like that:

http://wiki.multimedia.cx/index.php?tit ... tive_Voice

Code: Select all

Structure voc_file

  header.s{19} ; "Creative Voice File"
  printing.b
  totelsize.w
  version.w
  validity.w
  ;...

EndStructure

test.voc_file

ReadData(file, @test, SizeOf(voc_file))
How I convert this to unicode? Now be 38 bytes read for the header string?

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 9:58 am
by Danilo

Code: Select all

Structure voc_file

  header.a[19]
  [...]

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 10:00 am
by Lebostein
Yes, but I need extra operations to compare this byte array. I see a lot of work to convert my sources, includes and so on.... :cry:

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 10:26 am
by Danilo
Lebostein wrote:Yes, but I need extra operations to compare this byte array. I see a lot of work to convert my sources, includes and so on.... :cry:
Don't blame me. It is same if you incorrectly code 32bit only and move to 64bit.
You assume the type .s contains always ASCII data, and that's a wrong assumption. Sorry.

To be honest, the PB team had also some problems converting the IDE to Unicode. Transition is not always
that easy as it may sound at first, and can lead to bugs, if you didn't have Unicode in mind when writing codes.

Good thing is, you have time to make your stuff Unicode compatible. No need to do everything today,
as PB 5.4x is still many month away. That's why the PB team is talking about it now, to prevent surprises,
and give developers enough time to make the transition.

Maybe somebody should make a transition guide, or we collect important stuff here or in a new (sticky) topic.

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 10:43 am
by Lebostein
That could work:

Code: Select all

;==============================================================================
; Convert ASCII-Array to UNICODE-String
;==============================================================================

Procedure.s ATS(*pointer.Ascii, length): Protected unicode.s, i

  For i = 1 To length: unicode + Chr(*pointer\a): *pointer + 1: Next i
  ProcedureReturn unicode

EndProcedure

;==============================================================================
; Convert UNICODE-String to ASCII-Array
;==============================================================================

Procedure STA(*pointer.Ascii, unicode.s): Protected *zeiger.Unicode = @unicode

  While *zeiger\u: *pointer\a = *zeiger\u: *pointer + 1: *zeiger + SizeOf(Unicode): Wend

EndProcedure

;==============================================================================

Structure SC_HEAD

  name.a[4]
  size.l

EndStructure

test.SC_HEAD

STA(@test\name, "TeSt")
Debug ATS(@test\name, 4)

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 10:49 am
by Fred
You could use PeekS/PokeS as well, no ?

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 11:16 am
by luis
Danilo wrote:That's why the PB team is talking about it now, to prevent surprises,
and give developers enough time to make the transition.
I thought it was to decide whether to do it or not.

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 11:16 am
by Fred
It's not decided for now

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 11:39 am
by DK_PETER
I got no problem with going unicode. I got the unicode switch on all the time anyways.

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 11:49 am
by Lebostein
Fred wrote:You could use PeekS/PokeS as well, no ?
Yes! It works. It don't work without the #PB_String_NoZero flag. Without #PB_String_NoZero I get -5120. The NULL string overwrites the size.w

Code: Select all

Macro ATS(pointer, length) ; Convert ASCII-Array to UNICODE-String
  PeekS(pointer, length, #PB_Ascii)
EndMacro

Macro STA(pointer, string) ; Convert UNICODE-String to ASCII-Array
  PokeS(pointer, string, -1, #PB_Ascii | #PB_String_NoZero)
EndMacro

Structure fileheader
  name.a[4]
  size.w
EndStructure

test.fileheader

test\size = -5000
STA(@test\name, "TeSt")

Debug ATS(@test\name, 4)
Debug test\size

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 12:48 pm
by Didelphodon
As PokeS has already been mentioned a couple of times - and I use it frequently - what about the (optional) "Length" parameter? Is it really (as the documentation says) treated in terms of "characters" or does it mean effective bytes? I hope it's a mistake in the documentation as it wouldn't really make sense to restrict that operation by the means of "characters" in the presence of Unicode and UTF-8 as it's mainly focused on preventing the memory block from overflowing, imho.

UPDATE: Just read the description of the return value - so, actually it really means "characters". Well in terms of securing the underlying memory buffer I definitely have to keep this fact in mind. 8-O

UPDATE 2: However, I think I have to become good friends with StringByteLength()

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 3:07 pm
by juror
While "modernizing" why not eliminate 32 bit also?

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 3:16 pm
by Fred
juror wrote:While "modernizing" why not eliminate 32 bit also?
Will be one day, as 16bit dev is gone since a long time. But it's a bit too soon for that, as many users still have a 32-bit Windows :)

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 3:19 pm
by marroh
juror wrote:While "modernizing" why not eliminate 32 bit also?
:lol: :wink:

[Sarcasm On]
And also stop Mac and Linux support! Has only 6.62% (Mac) and 1.68% (Linux) desktop market share.
Source OS desktop market share
[Sarcasm Off]

Not intended for discussion, only to read. ;)

Re: Removing 'ASCII' switch from PureBasic

Posted: Thu Aug 07, 2014 3:27 pm
by wilbert
@Marroh,
Mac is so modern that one single 64 bit unicode version would probably be good enough for most Mac users :D