forked from DonovanChan/fmfunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodeMerge.calc
59 lines (57 loc) · 2.18 KB
/
CodeMerge.calc
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
56
57
58
59
Let ( [
tagOpen = "‡‡" ;
tagClose = "‡‡" ;
tagOpenLen = Length ( tagOpen ) ;
tagCloseLen = Length ( tagClose ) ;
posMarker = Position ( text ; tagOpen & "CODE" ; 1 ; 1 ) ;
endMarkerType = Position ( text ; "[" ; posMarker ; 1 ) - 1 ;
endMarker = Position ( text ; tagClose ; posMarker + 1 ; 1 ) + tagCloseLen - 1 ;
marker = Middle ( text ; posMarker ; endMarker + tagCloseLen - 1 - posMarker ) ;
markerType = Middle ( text ; posMarker + tagOpenLen ; endMarkerType - posMarker - tagCloseLen + 1 ) ;
index = GetAsNumber ( marker ) ;
code =
Case (
markerType = "CODE" ; FOCUS::CODE_INCLUDE_rep[index] ;
markerType = "CODE_LINK" ;
CodeMerge (
Substitute ( FOCUS::CODE_LINK_rep[index] ;
[ tagOpen & "CODE" & tagClose ; FOCUS::CODE_rep[index] ] ;
[ tagOpen & "NAME" & tagClose ; FOCUS::CODE_FILE_NAMESPACE & FOCUS::CODE_FILE_NAME_rep[index] ]
)
) ;
markerType = "CODE_NAME" ;
CodeMerge (
Substitute ( FOCUS::CODE_FILE_NAME_rep[index] ;
[ tagOpen & "CODE" & tagClose ; FOCUS::CODE_rep[index] ] ;
[ tagOpen & "NAME" & tagClose ; FOCUS::CODE_FILE_NAMESPACE & FOCUS::CODE_FILE_NAME_rep[index] ]
)
) ;
//-- Modify tag so it doesn't get processed again
"INVALID CODE LABEL: " & Substitute ( marker ; [ tagOpen ; tagOpen & " " ] ; [ tagClose ; " " & tagClose ] )
) ;
textNew =
If (
posMarker = 0 ; text ;
Substitute ( text ; marker ; code )
)
] ;
Case (
Position ( textNew ; tagOpen & "CODE" ; 1 ; 1 ) ;
CodeMerge ( textNew ) ;
textNew
)
)
/* __________________________________________________
NAME: CodeMerge ( text )
PURPOSE: Merges value from LIBRARY_CODE table into text.
Useful for on-the-fly merging of code libraries in a web viewer.
EXAMPLES:
// Where FOCUS::LIBRARY_CODE_INCLUDE[1] = "Beezwax!"
// Where FOCUS::LIBRARY_CODE_LINK[1] = "http://beezwax.net"
CodeMerge ( "Hello ‡‡CODE[1]‡‡" ) = "Hello Beezwax!"
CodeMerge ( "Hello ‡‡CODE_LINK[1]‡‡" ) = "http://beezwax.net"
HISTORY:
Created: 2010-08-27 21:06 PT - Donovan Chandler
Modified: 2013-11-18 14:18 PT - Donovan Chandler : Merges NAME and CODE tags.
Modified: 2013-12-16 18:26 PT - Donovan Chandler : Easier to change tag format.
*/