-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathnumber.format.fmfn
51 lines (49 loc) · 1.74 KB
/
number.format.fmfn
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
48
49
50
51
/*
* =====================================================
* number.format ( input ; format )
*
* RETURNS: (string) Formatted input according to format supplied
* DEPENDENCIES: none
* NOTES: Adapted from http://www.briandunning.com/cf/769 by Toby Beedell
* =====================================================
*
*/
Let ( [
var.input = input;
var.format = format;
var.valid = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var.match = "#";
test.exit = IsEmpty ( var.input ) or IsEmpty ( var.format )
];
If ( test.exit;
// then
var.input;
// else
Let ( [
match.count = PatternCount ( var.format; var.match );
match.none = match.count < 1;
format.length = Length ( var.format );
format.end = If ( match.none and format.length > 0 ; var.format )
];
If ( match.none;
// then
format.end & var.input;
// else
Let ( [
var.filtered = Filter ( var.input ; var.valid );
filtered.length = Length ( var.filtered );
match.position = Position ( var.format ; var.match ; 1 ; 1 );
var.prefix = If ( match.position ≠ 1 ; Left ( var.format ; match.position - 1 ) );
format.char = Middle ( var.format ; match.position ; 1 );
var.char = Left ( var.filtered ; 1 );
is.upper = IsEmpty ( Filter ( format.char ; var.match ) );
_tBit = If ( is.upper ; Upper ( var.char ) ; Lower ( var.char ) );
format.remainder = Right ( var.format ; format.length - match.position );
input.remainder = Right ( var.filtered ; filtered.length - 1 )
];
var.prefix & _tBit & number.format ( input.remainder ; format.remainder )
)
)
)
)
)