[macfindersort]

Description

Link: [macfindersort]
Author: Pier Kuipers
Category: Array
Version: 8.5.x
License: Public Domain
Posted: Sep. 08, 2009
Updated: Sep. 08, 2009
More by this author...
Promted by a thread on LassoTalk and inspired by Johan Sölve's alphasorter, I came up with this tag to sort strings in the same quirky way as the Macintosh Finder. Normal sorting of strings has this result:
File 12.pdf
File 3.pdf
File 6.pdf
The Mac Finder however, will honour the numerical values like so:
File 3.pdf
File 6.pdf
File 12.pdf
..And that is what this tag is trying to mimic.
http://www.listsearch.com/Lasso/Thread/index.lasso?22876#251316

Parameters

none


Sample Usage

local('strings' = array(
	'File 6.pdf',
	'File 12.pdf',
	'File 3.pdf'
	)
);

#strings -> (sortwith: \macfindersort);

iterate(#strings,local('p'));
	#p + '<br />\n';
/iterate;
						

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
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
define_tag('macfindersort', 
			-description='sorts an array of strings in the same way as the Macintosh Finder, honouring numerical values',
			-required='left', 
			-copy, 
			-required='right', 
			-copy); 
    if((#left -> size > 1) && (#right -> size > 1)); 
		local('leftarray' = array);
		local('leftsplit' = (#left->split('')));
		local('previousleft'='');
		local('thisleft'='');
		iterate(#leftsplit, local('currentleft'));
			if((#currentleft->isdigit)&&(#previousleft->isdigit));
				#thisleft += string(#currentleft);
				#leftarray -> remove;	
			else;
				#thisleft = #currentleft;
			/if;
			if(#thisleft -> isdigit);
				#leftarray -> insert(integer(#thisleft));
			else;
				#leftarray -> insert(string(#thisleft));
			/if;
			#previousleft = #currentleft;
		/iterate;
		local('rightarray' = array);
		local('rightsplit' = (#right->split('')));
		local('previousright'='');
		local('thisright'='');
		iterate(#rightsplit, local('currentright'));
			if((#currentright->isdigit)&&(#previousright->isdigit));
				#thisright += string(#currentright);
				#rightarray -> remove;	
			else;
				#thisright = #currentright;
			/if;
			if(#thisright -> isdigit);
				#rightarray -> insert(integer(#thisright));
			else;
				#rightarray -> insert(string(#thisright));
			/if;
			#previousright = #currentright;
		/iterate;
    /if; 
    return: (#leftarray > #rightarray ? -1 | 0); 
/define_tag;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net