TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Issue with #if and \;

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
new_to_tin_tin



Joined: 05 Jan 2011
Posts: 36

PostPosted: Fri Jul 21, 2017 4:36 pm    Post subject: Issue with #if and \; Reply with quote

When trying to match strings with \; in them, #if doesn't seem to correctly match. See this sample code from version 2.01.2.

Code:

#alias testerdebug5 {

        #showme ;
        #showme ----------------------------------------------;
        #showme ;
        #showme Trying first match;
        #var test1 {The quick brown fox\; he jumped.};
        #var test2 {The quick brown fox\; he jumped.};
        #if {"$test1" == "$test2"}{
                #showme Test1 and test2 are a match!;
        }; #else {
                #showme Test1 and test2 are NOT match!;
        };

        #showme ;
        #showme ----------------------------------------------;
        #showme ;

        #showme Now trying second match;
        #var test3 {A slobbering troll rushes towards you; looks like it wants to eat your flesh.};
        #var test4 {A slobbering troll rushes towards you; looks like it wants to eat your flesh.};
        #if {"$test3" == "$test4"}{
                #showme Test3 and test4 are a match!;
        }; #else {
                #showme Test3 and test4 are NOT match!;
        };

        #showme ;
        #showme ----------------------------------------------;
        #showme ;

        #showme Trying final match, this one is a doozy!;
        #var test5 {The quick brown fox\; he jumped.};
        #var test6 {The quick brown fox\; he jumped.};
        #if {"$test5" == "$test5"}{
                #showme Test5 and test5 are a match!;
        }; #else {
                #showme Test5 and test5 are NOT match! This one is the most interesting!;
        };

        #showme ;
        #showme ----------------------------------------------;
        #showme ;
};


This produces the following output:

Quote:
testerdebug5

----------------------------------------------

Trying first match
Test1 and test2 are NOT match!

----------------------------------------------

Now trying second match
Test3 and test4 are a match!

----------------------------------------------

Trying final match, this one is a doozy!
Test5 and test5 are NOT match! This one is the most interesting!

----------------------------------------------


The bug appears in the first and last matches, the middle one is a control showing that #if is working correctly without the semi-colons.

Even if I'm doing something wrong with the first #if statement, surely we could agree that comparing the variable with itself should return true!
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Fri Jul 21, 2017 5:20 pm    Post subject: Reply with quote

I confirm the above, but I also found out that if you use these for the first and last comparison, the FIRST MATCHES and the LAST NOT

Code:

#var test1 {The quick brown fox\; he jumped.};
#var test2 {The quick brown fox\\; he jumped.};


EDIT: If you try to #read the alias with the previous change, it can't be loaded !!
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3770

PostPosted: Tue Jul 25, 2017 10:00 pm    Post subject: Re: Issue with #if and \; Reply with quote

new_to_tin_tin wrote:

Even if I'm doing something wrong with the first #if statement, surely we could agree that comparing the variable with itself should return true!

The left field in #if and #regex is plain text, the right field is a regular expression. So the behavior is correct.

Doing a real string comparison isn't supported right now, though there's a work around:

#if {"$test1" <= "$test2" && "$test1" >= "$test2"}
Back to top
View user's profile Send private message Send e-mail
PowerGod



Joined: 04 Aug 2014
Posts: 339

PostPosted: Wed Jul 26, 2017 11:24 am    Post subject: Reply with quote

This function seems working well too (at least for this case):
Code:

#var test1 {The quick brown fox\; he jumped.};

#func {escape} {#var {result} {%0};#replace {result} {\x5C} {\\}}

#if {"$test1"=="@escape{$test1}"} {#echo YES} {#echo NO}
YES


Code:

#VARIABLE {test1}={The quick brown fox\; he jumped.}

#echo {$test1}
The quick brown fox; he jumped.

#echo {@escape{$test1}}
The quick brown fox\; he jumped.


EDIT: I did a minor correction

EDIT: anyway, if the right part is a regex, why this doesn't work ?

Code:

#var test3 {A dotted line}
#OK. VARIABLE {test3} HAS BEEN SET TO {A dotted line}.
#var test4 {A ...... line}
#OK. VARIABLE {test4} HAS BEEN SET TO {A ...... line}.
#if {"$test3"=="$test4"} {#echo YES} {#echo NO}
NO
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports All times are GMT - 5 Hours
Page 1 of 1

 
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
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group