Lasso Soft Inc. > Home

[caseKey]

LinkcaseKey
AuthorKyle Jessup
CategoryString
Version8.x
LicensePublic Domain
Posted06 Feb 2006
Updated06 Feb 2006
More by this author...

Description

This type can be used as the key in a TreeMap to provide case sensitive map lookups. Normally, all Lasso string comparisons are non-case-sensitive which makes 'one' equal to 'ONE'. Storing both of those values in a map will result in them being interpreted as the same value, so the second inserted pair will replace the first. By using the TreeMap and caseKey types, 'one' and 'ONE' will be treated as distinct values. This caseKey type needs to be used as the key for the map when both inserting and finding. Also, this method will not work with the regular 'Map' type, since it will always convert its keys into strings. The TreeMap type will preserve the key's original type.

Sample Usage

treemap(caseKey('one')=1, caseKey('ONE')=2)->find(caseKey('ONE')); // found
treemap(caseKey('one')=1, caseKey('ONE')=2)->find(caseKey('oNe')); // not found
treemap(caseKey('one')=1, caseKey('ONE')=2)->find(caseKey('one')); // found

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_type('caseKey');
	local('str'='');
	define_tag('onCreate', -req='p');
		self->'str' = #p;
	/define_tag;
	define_tag('onCompare', -req='p');
		if (#p->isa('caseKey'));
			return: self->'str'->compare(#p->'str', -case);
		/if;
		return: self->'str'->compare(#p, -case);
	/define_tag;
	
	define_tag('onConvert');
		return: self->'str';
	/define_tag;
/define_type;

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft