-
Notifications
You must be signed in to change notification settings - Fork 16
/
script.param.get.fmfn
55 lines (47 loc) · 1.87 KB
/
script.param.get.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
52
53
54
55
/*
* =====================================================
* script.param.get( values; key)
*
* RETURNS: (mixed) the value associated to the supplied key
* DEPENDENCIES: none
* NOTES: Compliments to Mikhail Edoshin http://mikhailedoshin.com
* =====================================================
*
* This function is used to extract a named value from a
* data structure which preserves carriage returns and
* other special characters.
*
*/
Case(
IsEmpty( values ) or IsEmpty( key );
"";
Let(
[
//------------------------- VARIABLES
var.UnwrappedValues = Substitute( values;
[ "¶"; "" ];
[ ".^^"; "¶" ];
[ ".^"; "^" ] );
var.KeyPosition = Position( "¶" & values; "¶.^^" & key & ".^^"; 1; 1 )
];
//------------------------- RESULT
If( var.KeyPosition = 0; "";
Let(
[
//------------------------- VARIABLES
var.ValuePosition = ValueCount( Left( values; var.KeyPosition ) );
var.OptionString = MiddleValues( values; var.ValuePosition; 1 );
var.Start = Position( var.OptionString; ".^^"; 1; 2 ) + Length( ".^^" );
var.End = Position( var.OptionString; ".^^"; 1; 3 )
];
//------------------------- RESULT
Substitute( Middle( var.OptionString; var.Start; var.End - var.Start );
[ ".^^"; "¶" ];
[ ".^"; "^" ];
[ "¶"; "" ];
[ ".^^"; "¶" ];
[ ".^"; "^" ] )
)
)
)
)