by Carl Ranson >> Tue, 24 Apr 2001 3:17:10 GMT
Hi All,
I wanted to give everyone a heads up about an jade "feature" that is not obvious.
When you have a string key in a dictionary, Jade (presumably because it knows what's best for us) will strip all trailing spaces automatically.
For instance:
Assume we have a class "Data" with a string field "name" and a dictionary "DataDict" using Data.name as its key, the following code demonstrates the problems.
showBug();
vars
dataDict : DataDict;
data : Data;begin
create dataDict transient;
create data transient; data.name := "Palm"; dataDict.add(data);
create data transient; data.name := "PalmerstonX"; dataDict.add(data);
create data transient; data.name := "Palmerston "; dataDict.add(data);
write '(' & dataDict.getAtKey('Palmerston').name & ')'; // no traling space - writes (Palmerston )
write '(' & dataDict.getAtKey('Palmerston ').name & ')'; // one traling space - returns (Palmerston )
write '(' & dataDict.getAtKey('Palmerston ').name & ')'; // three traling spaces - returns (Palmerston )
create data transient; data.name := "Palmerston"; dataDict.add(data); // !!! exception - key already used in this dictionary
end;
In short the assumption that the dictionary key will equal the data field is invalid in cases where the data field has trailing spaces. I've been told this is the intended behaviour of Jade.
Cheers,
CR