Here is a copy of the function 'SortHeader' that will sort the header of a function or the methods of a class:
r„vr SortHeader name;header;i;inter;methods;vars
© Sort the Header of a Function or Class
©
© name = Function or Class Name
© r and vr are used when called Recursively
:If (›name) ¹ ŒDBR¨›[2] ŒNL 9 © Class Name ?
© name is a Class
methods „ –name,'.ŒNL 3' © Public Methods of the Class
:For i :In ¼1½½methods
vr „ –"2 ŒCR '",name,'.',methods[i;],"'" © ŒCR of the method
vr „ vr SortHeader '' © Call SortHeader Recursively to Sort the Header in vr
:If (ŒFX vr) » (methods[i;]~' ') © Fix the Method
© Failure
'ERROR: Not Able to Fix: ',methods[i;]
:Continue
:Else
© Success, Do Nothing
:EndIf
:If 1 = name ŒIC methods[i;] © Insert back the Method into the Class
© Success
name,'.',(methods[i;]~' '),' Sorted'
:Else
© Failure
'Not Able to Fix ',(methods[i;]~' '),' into ',name
:EndIf
:EndFor
:ElseIf (›name) ¹ ŒDBR¨›[2] ŒNL 3 © Function Name ?
© name is a Function
vr„2 ŒCR name
vr„vr SortHeader ''
:If (inter„ŒFX vr) » (name~' ')
© Failure
'Not Able to Fix ',name,' at line: ',•inter
:Else
© Success
'Function Sorted: ',name
:EndIf
:ElseIf 0 ¬ ŒNC 'vr' © vr Exists ?
© SORT vr (must be a nested vector from 2 ŒCR 'Function_Name')
© Removes the extra Blanks at the End of each line of the Function
vr„(-¯1+(²¨' '=¨vr)¼¨0)‡¨vr
© Extract the Header of the Function
header „ 1œvr
© Check if there is local variables to sort in header
:If ~';' ¹ header
© no ';' in header
r „ vr
:Else
© There is local variables in Header
© Split the Header
vars „ (header¼';')‡header
© Sort the variables
vars „ ';' ŒBOX (vars~' ')
vars „ vars[ŒAV“vars;]
vars „ (,';',vars)~' '
© Reassemble the header
header „ ((¯1+header¼';')†header),vars
© Insert the Sorted Header in ŒCR of function
(1œvr)„header
© Return the Result
r „ vr
:End
:Else
'ERROR: Argument Must Be the Name of a Function or a Class',ŒR
:End
Regards,
Pierre Gilbert