BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fastcode Non-Nil Zero Length String Validation
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM
View previous topic :: View next topic  
Author Message
Dennis
Guest





PostPosted: Sat Mar 10, 2007 10:15 pm    Post subject: Fastcode Non-Nil Zero Length String Validation Reply with quote



Hi

The poll

http://tech.groups.yahoo.com/group/fastcodeproject/surveys?id=12528539

will close in 3 days.

If the result becomes that we should support Non-Nil Zero Length Strings,
then we need to agree on some validation functions.

This validation creates a non nil string, sets the length field to zero,
adds a zero terminator at S[1] and validates that the empty string is
trimmed to an empty string. I think we all agree that this validation is
valid.

var
GlobalStrValidate16: AnsiString;

function TMainForm.Validate16 : Boolean;
var
S : string;
const
VALIDATENO : Cardinal = 16;

begin
Result := True;
GlobalStrValidate16 := #0;
PInteger(Integer(GlobalStrValidate16)-4)^ := 0; //Set Length to 0
S := TrimFunction(GlobalStrValidate16);
if S <> '' then
begin
ErrorTrap(VALIDATENO, GlobalStrValidate16);
Result := False;
Exit;
end;
end;

Best regards
Dennis Kjaer Christensen
Back to top
Dennis
Guest





PostPosted: Sat Mar 10, 2007 10:18 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote



Hi

This validation creates a string = A#0, but with the length field set to
zero. The result of a Trim should be an empty string because the string is
length zero = empty. The current RTL Trim function passes the validation.

The question is whether this in general is a proper validation function for
Non-Nil Zero Length Strings.

var
GlobalStrValidate11: AnsiString;

function TMainForm.Validate11 : Boolean;
var
S : string;
const
VALIDATENO : Cardinal = 11;

begin
Result := True;
GlobalStrValidate11 := 'A';
PInteger(Integer(GlobalStrValidate11)-4)^ := 0; //Set Length to 0
S := TrimFunction(GlobalStrValidate11);
if S <> '' then
begin
ErrorTrap(VALIDATENO, GlobalStrValidate11);
Result := False;
Exit;
end;
end;

Best regards
Dennis Kjaer Christensen
Back to top
Dennis
Guest





PostPosted: Sat Mar 10, 2007 10:23 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote



Hi

My personal opinion is that the validation is proper. I do not expect all
non-nil zero length strings to be zero terminated at index 1. These strings
are very non standard in the first place and I would be surprised if all
libraries creating them would put a zero terminator in the proper place. I
think we should validate against all kinds of non nil zero length strings
that the corresponding RTL function handles. I would like our functions to
behave as the RTL function they are meant to replace.

Best regards
Dennis Kjaer Christensen
Back to top
Dennis
Guest





PostPosted: Sat Mar 10, 2007 10:23 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote

Hi

I need some help to formulate a proper poll question.

Best regards
Dennis Kjaer Christensen
Back to top
Dennis
Guest





PostPosted: Sun Mar 18, 2007 3:51 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote

Hi

I have created a poll

http://tech.groups.yahoo.com/group/fastcodeproject/surveys?id=12540587

Best regards
Dennis Kjaer Christensen
Back to top
Davy Landman
Guest





PostPosted: Sun Mar 18, 2007 4:38 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote

Hi,

I voted No because this validate functions doesn't check what the RTL
function does, it just checks if it returns an empty string ;)

Kind Regards,
Davy Landman
Back to top
Dennis
Guest





PostPosted: Sun Mar 18, 2007 10:14 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote

Hi Davy

Quote:
I voted No because this validate functions doesn't check what the RTL
function does, it just checks if it returns an empty string Wink

I do not understand this. Can you explain further?

Best regards
Dennis Kjaer Christensen
Back to top
Davy Landman
Guest





PostPosted: Sun Mar 18, 2007 10:18 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote

Quote:
I do not understand this. Can you explain further?
Offcourse, the function you purpose is:


function TMainForm.Validate11 : Boolean;
var
S : string;
const
VALIDATENO : Cardinal = 11;

begin
Result := True;
GlobalStrValidate11 := 'A';
PInteger(Integer(GlobalStrValidate11)-4)^ := 0; //Set Length to 0
S := TrimFunction(GlobalStrValidate11);
if S <> '' then
begin
ErrorTrap(VALIDATENO, GlobalStrValidate11);
Result := False;
Exit;
end;
end;

The rule say's "The rule above implies that functions must support
non-nil-zero-length strings only if the RTL function does."

Note the part "only if the RTL function does".
I would suggest changing
if S <> '' then
to:
if S <> Trim(GlobalStrValidate11) then

So that's it's obvious that it does exactly the same as the RTL function (no
checking needed beforehand on what the RTL does, just compare it with that
function).

Regards,
Davy Landman
Back to top
Dennis
Guest





PostPosted: Sun Mar 18, 2007 10:28 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote

Hi Davy

We know that the Trim RTL function supports non nil .... strings and so must
our Trim functions. The validation simply tests this.

Run the validation and see the RTL function pass.

Conclusion: Your suggestion is valid, but not needed.

The real point of the discussion is what we discussed earlier. John said
that we should only validate against one Non-Nil Zero Length String - one
that is zero terminated at S[1].

I think we should valida against all Non-Nil Zero Length Strings that the
RTL function supports.

Best regards
Dennis Kjaer Christensen
Back to top
Dennis
Guest





PostPosted: Sun Mar 18, 2007 10:30 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote

Hi

This Non-Nil Zero Length String validation is the only one that John finds
proper.

var
GlobalStrValidate16: AnsiString;

function TMainForm.Validate16 : Boolean;
var
S : string;
const
VALIDATENO : Cardinal = 16;

begin
Result := True;
GlobalStrValidate16 := #0;
PInteger(Integer(GlobalStrValidate16)-4)^ := 0; //Set Length to 0
S := TrimFunction(GlobalStrValidate16);
if S <> '' then
begin
ErrorTrap(VALIDATENO, GlobalStrValidate16);
Result := False;
Exit;
end;
end;

Best regards
Dennis Kjaer Christensen
Back to top
Davy Landman
Guest





PostPosted: Sun Mar 18, 2007 11:50 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote

Ow, in that case, I'm waiting on arguments about that subject...

I misunderstood the question then..

Regards,
Davy
Back to top
Aleksandr
Guest





PostPosted: Mon Mar 19, 2007 3:43 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote

Hi Dennis,

I try to continue Smile
My function creates an integer number=0 and calls Trim with @number+4.
The result of a Trim should be an empty string because the numbet=0.
The current RTL Trim function passes the validation. :-)

I think Validate11 is incorrect because it uses incorrect data.

--
regards,
Aleksandr

procedure TForm1.Button1Click(Sender: TObject);
var
i: integer;
p: pInteger;
s, t: string;
begin
i:=0;
p:=@i;
inc(p);
pointer(s):=p;
t:=Trim(s);
ShowMessage('*'+t+'*');
end;
Back to top
Dennis
Guest





PostPosted: Mon Mar 19, 2007 10:13 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote

Hi Aleksandr

Quote:
I try to continue Smile

Yes please ;-)

Quote:
My function creates an integer number=0 and calls Trim with @number+4.
The result of a Trim should be an empty string because the numbet=0.
The current RTL Trim function passes the validation. Smile

I fail to follow you. Your example looks very weird to me ;-)

Quote:
I think Validate11 is incorrect because it uses incorrect data.

Of course it uses incorrect data !
Non-Nil Zero Length Strings are invalid AnsiStrings.

But the RTL Trim passes Validate11 and I argue that so should our functions.
I do not want to see a Fastcode Trim function in the RTL that behaves
differently that the RTL function.

"Functions must behave exactly as the RTL functions do.
The rule above implies that functions must support non-nil-zero-length
strings only if the RTL function does."

http://fastcode.sourceforge.net/challenge_content/Rules.html

Best regards
Dennis Kjaer Christensen
Back to top
Aleksandr Sharahov
Guest





PostPosted: Mon Mar 19, 2007 11:04 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote

Hi Dennis,



Quote:
Non-Nil Zero Length Strings are invalid AnsiStrings.

I dont think so.
AnsiString is valid if it has reference count, length
and zero terminator following it's *length* characters.



Quote:
"Functions must behave exactly as the RTL functions do.
The rule above implies that functions must support non-nil-zero-length
strings only if the RTL function does."

Yes. But here we meen *valid* non-nil-zero-length strings.



Quote:
But the RTL Trim passes Validate11 and I argue that so should our functions.

No. This is passing incorrect validation.



Quote:
I fail to follow you. Your example looks very weird to me Wink

We know Trim is string function, but I have constructed the example
which validates Trim on integers RTL Trim passes this "validation".
What do you think about our functions?

--
regards,
Aleksandr
Back to top
Dennis
Guest





PostPosted: Mon Mar 19, 2007 11:27 pm    Post subject: Re: Fastcode Non-Nil Zero Length String Validation Reply with quote

Hi Aleksandr

Quote:
We know Trim is string function, but I have constructed the example
which validates Trim on integers RTL Trim passes this "validation".

No you have not. Trim takes a string and you have made a string in a weird
way and passing it to trim.

Best regards
Dennis Kjaer Christensen
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Language BASM All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.