[caseKey]

Description

Link: [caseKey]
Author: Kyle Jessup
Category: String
Version: 8.x
License: Public Domain
Posted: Feb. 06, 2006
Updated: Jan. 01, 0001
More by this author...
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.

Parameters

-p string, required The string to be used as the comparison value.

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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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

none

Email:


Password:



Newest

Most Popular