xsharp.eu • Implementing missing VFP functions - Page 4
Page 4 of 4

Implementing missing VFP functions

Posted: Sun Mar 28, 2021 7:37 pm
by Chris
Robert,
robert wrote:Chris,
Chris wrote:
No you're right, there's an issue here. The Binary type itself is a STRUCTURE (so it's being passed by value), but it holds its data internally in a byte array (so a reference type) and when you convert the Binary value into a BYTE array in your first local assignment, then the conversion returns that exact internal array. Maybe the best way is to return a new copy of the array instead, will log an incident on that to be looked at.
Given the fact that the binary type is a value type it indeed makes sense to return a copy of the byte array as well (in other words, to make it a really immutable type).
Agreed, I made the change. Not sure if also the constructor that accepts a byte array needs to use a cloned buffer as well. If this constructor is supposed to be called only from the compiler emitted code for literals and from within the class code, then there's no point I think.

Btw, I think you accidentally increased the assembly version (not only the file version) of the runtime to 2.8.0.0 instead of 2.6.0.0.

Implementing missing VFP functions

Posted: Wed Mar 31, 2021 7:52 am
by Karl-Heinz
Guys

there are a few options to create a Binary

Code: Select all

    VAR bArr := BYTE[]{5}
    
    bArr[1] := 104  // "h"
    bArr[2] := 111  // "o"
    bArr[3] := 117  // "u"
    bArr[4] := 115  // "s"
    bArr[5] := 101  // "e"

    
    ? 0h686F757365
    ? (BINARY) bArr 
    ? (BINARY) "house"  
    ? BINARY { bArr }  
//  ? BINARY { "house" } // that´s not possible 

Now the question: If such a string constructor would be part of the Binary implementation, something like Binary { "House" } works, right ?

Code: Select all

CONSTRUCTOR (c as STRING )
	IF String.IsNullOrEmpty ( c )
		THROW NullError()
	ENDIF
	self:_value := RuntimeState.WinEncoding:GetBytes(c)

regards
Karl-Heinz

Implementing missing VFP functions

Posted: Wed Mar 31, 2021 8:35 am
by robert
Karl Heinz,
Adding such a constructor is no problem at all. In fact I'll map the implicit converter to call the same constructor to keep the logic in one place.
Important to realize is that the mapping between characters and bytes only works for lower ascii characters. Accented characters and characters from other character sets will not map like that. They will be replace with a question mark when translated.

Robert

Implementing missing VFP functions

Posted: Wed Mar 31, 2021 11:00 am
by Karl-Heinz
Hi Robert,

yes, i´m aware of the problems. If e.g. Chris creates a byte array with some special greece chars included i won´t be able to see on my machine the correct string presentation if i simply use RuntimeState.WinEncoding:GetString( bArr).

i asked about the string constructor because it´s possible to do this:

Code: Select all

VAR binExpression := (BINARY) "äöüß" 

Code: Select all


? (STRING) binExpression  // äöüß 

? RuntimeState.WinEncoding:GetString( binExpression:Value  ) // äöüß
regards
Karl-Heinz

Implementing missing VFP functions

Posted: Wed Mar 31, 2021 5:29 pm
by Karl-Heinz
Hi Robert,

forgot to mention, but maybe it´s already known ?.

What´s missing is the IsBinary() function.

regards
Karl-Heinz

Implementing missing VFP functions

Posted: Thu Apr 01, 2021 6:36 am
by robert
Karl-Heinz ,

I have added that function as well.

Robert

Implementing missing VFP functions

Posted: Wed Apr 07, 2021 12:43 pm
by atlopes
Going back to Chris's question, here is a list of common VFP functions that I think would signify an advancement if implemented from scratch or recreated to match VFP's behavior closer:
  • EMPTY() and EVL() (I'm not forgetting this, Matt)
  • ISNULL()
  • ALINES()
  • TRANSFORM() (verify formats) and TTOC()
  • TEXTMERGE()
  • STREXTRACT()
  • XMLTOCURSOR() and CURSORTOXML()
  • AERROR(), at least to support SQL* functions
  • GETFILE(), PUTFILE() and LOCFILE()
Because of how this thread evolved, I worked on the BIT* functions. I will propose them in a separate thread.