Link | caseKey |
Author | Kyle Jessup |
Category | String |
Version | 8.x |
License | Public Domain |
Posted | 06 Feb 2006 |
Updated | 06 Feb 2006 |
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.
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
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;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft