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

leading spaces in lists

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



Joined: 17 May 2014
Posts: 22

PostPosted: Sun May 18, 2014 7:31 am    Post subject: leading spaces in lists Reply with quote

Lists don't work correctly if their elements have leading spaces.

Code:
#list mylist create {a} { a} {  a} {b} {b } {b  }
#showme $mylist
{1}{a}{2}{a}{3}{a}{4}{b}{5}{b }{6}{b  }

#list mylist create {a} {\ a} {\ \ a} {b} {b } {b  }
#showme $mylist
{1}{a}{2}{ a}{3}{  a}{4}{b}{5}{b }{6}{b  }

#list mylist find {a} {index} ; #showme $index
1
#list mylist find { a} {index} ; #showme $index
0
#list mylist find {\ a} {index} ; #showme $index
0
#list mylist find {\\ a} {index} ; #showme $index
2
#list mylist find {b} {index} ; #showme $index
4
#list mylist find {b } {index} ; #showme $index
5
#list mylist find {b  } {index} ; #showme $index
6

#list listtwo create {ab} {a b} {a  b}
#showme $listtwo
{1}{ab}{2}{a b}{3}{a  b}
#list listtwo find {a  b} {index} ; #showme $index
3


Leading spaces need backslashes to work in lists but other spaces don't.

This bug appeared in 2.00.3. "#list mylist create {a} { a} { a}" and "#list mylist find { a} index" worked correctly in 2.00.2.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Sun May 18, 2014 10:03 am    Post subject: Reply with quote

You need to add an extra set of braces:
Code:

#list mylist create {{a} { a} {  a} {b} {b } {b  }}
Back to top
View user's profile Send private message Send e-mail
Slither



Joined: 17 May 2014
Posts: 22

PostPosted: Mon May 19, 2014 3:42 am    Post subject: Reply with quote

Scandum wrote:
You need to add an extra set of braces:


Code:
#list one create {a} {\ a} {\ \ a} {b} {b } {b  }
#list two create {{a} { a} {  a} {b} {b } {b  }}
#showme $one
{1}{a}{2}{ a}{3}{  a}{4}{b}{5}{b }{6}{b  }
#showme $two
{1}{a}{2}{ a}{3}{  a}{4}{b}{5}{b }{6}{b  }

#list one find { a} {index} ; #showme $index
0
#list two find { a} {index} ; #showme $index
2


Coming up with a workaround doesn't negate that the code has a bug.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Mon May 19, 2014 7:38 am    Post subject: Reply with quote

The need for the extra brace is proper behavior. It's more obvious if you use ; to separate items.


You need to match a \ with \\ in a regular expression.
Back to top
View user's profile Send private message Send e-mail
Slither



Joined: 17 May 2014
Posts: 22

PostPosted: Mon May 19, 2014 12:13 pm    Post subject: Reply with quote

Scandum wrote:
The need for the extra brace is proper behavior. It's more obvious if you use ; to separate items.


The addition of the ; syntax for lists is the version in which the bug first appears. In my last example, lists one and two appear to be identical lists.
Code:
#showme $one[1]
a
#showme $one[2]
 a
#showme $one[3]
  a
#showme $two[1]
a
#showme $two[2]
 a
#showme $two[3]
  a


Something's wrong if #list somelist find { a} {index} returns different results.

#help list doesn't mention the need for an extra brace.

Trailing spaces work correctly and in version 2.00.2, leading spaces also worked correctly, without having to escape a space or use nested braces. The code from 2.00.3 and on is inherently inconsistent, regardless of adding script-side syntax to make things work.
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Mon May 19, 2014 6:33 pm    Post subject: Reply with quote

Not sure how to explain that {a;b;c} is the equivalent of {{a}{b}{c}} in the helpfile.

The problem with your #list find issue is that there are \ characters embedded in the string.

#showme escapes the \ characters upon execution, which is why you don't see them, but they're there.
Back to top
View user's profile Send private message Send e-mail
Slither



Joined: 17 May 2014
Posts: 22

PostPosted: Tue May 20, 2014 7:02 am    Post subject: Reply with quote

Scandum wrote:
The problem with your #list find issue is that there are \ characters embedded in the string.


If the strings differ because of embedded backslashes, why don't trailing spaces lead to the same error?
Back to top
View user's profile Send private message
Scandum
Site Admin


Joined: 03 Dec 2004
Posts: 3796

PostPosted: Tue May 20, 2014 6:42 pm    Post subject: Reply with quote

Not sure what you mean.
Back to top
View user's profile Send private message Send e-mail
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