Lasso Soft Inc. > Home

[alphasorter]

Linkalphasorter
AuthorJohan Solve
CategoryArray
Version8.x
LicensePublic Domain
Posted10 Oct 2007
Updated10 Oct 2007
More by this author...

Description

Comparator to get arrays of strings (or arrays of pairs) sorted in the correct order for the Swedish language.
With normal array->sort the sort order will be ä, å, ö instead of the desired å, ä, ö.

This comparator is very limited. It will only look at the first character position of the strings, and does only care about the characters å, ä and ö.

Johan Sölve 2007-06-25

Sample Usage

var: 'myarray'=(array: 'östen', 'åke', 'ärlig');

$myarray -> (sortwith: \alphasorter);

$myarray;

Result: 
array: (åke), (ärlig), (östen)

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.

[//lasso
define_tag: 'alphasorter', -required='left', -copy, -required='right', -copy;
	// used as comparator for proper sorting of arrays of strings (or array of string pairs)
	// otherwise the sorted order will be ä, å, ö
	// usage: $myarray -> (sortwith: \alphasorter);
	
	// Johan Sölve 2007-06-25

	if: #left -> type == 'pair';
		#left = #left -> name;
	/if;
	if: #right -> type == 'pair';
		#right = #right -> name;
	/if;

	
	if: #left -> size > 1 && #right -> size > 1;
		if: #left -> (get: 1) == 'å' && #right -> (get: 1) == 'ä';
			return: 0;
		else: #left -> (get: 1) == 'ä' && #right -> (get: 1) == 'å';
			return: -1;
		/if;
	/if;
	return: (#left > #right ? -1 | 0);
/define_tag;
]

Related Tags

Comments

No comments

Please log in to comment

LassoSoft Inc. > Home

 

 

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