Skip to content

Commit

Permalink
Merge pull request #11 from johnchristopherjones/master
Browse files Browse the repository at this point in the history
Modify #GetNameList, #Remove, and #Filter to use Position/Middle instead of GetValue
  • Loading branch information
Jeremy Bante committed Dec 24, 2013
2 parents 7065305 + bf38cc6 commit 174e6ce
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
22 changes: 19 additions & 3 deletions Functions/#Name-Value/#Filter.fmfn
Expand Up @@ -23,6 +23,9 @@
* DEPENDENCIES: none
*
* HISTORY:
* MODIFIED on 2013-12-23 by John Jones john.christopher@alumni.virginia.edu
* to use Position/Middle. Modified to add trailing return if it doesn't
* exist.
* CREATED on 2012-11-28 by Jeremy Bante <http://scr.im/jbante>.
* =====================================
*/
Expand All @@ -39,7 +42,8 @@ Case (
& Substitute ( filterParameters ; ¶ ; "¶$" )
& ¶ ;

$#Filter.parameterCount = ValueCount ( parameters ) ;
$#Filter.parameterCount = PatternCount ( parameters ; Char ( 13 ) ) ;
$#Filter.parameterLength = Length ( parameters ) ;
$#Filter.step = If ( ~empty ; -1 ; /* Else */ 1 )
];
#Filter ( parameters ; filterParameters )
Expand All @@ -49,7 +53,12 @@ Case (
$#Filter.step = 1 ;
Let ( [
$#Filter.i = $#Filter.i + 1 ;
~pair = GetValue ( parameters ; $#Filter.i ) ;
~start = Position ( parameters ; Char ( 13 ) ; 1 ; $#Filter.i - 1 ) + 1 ;
~end = Min (
Position ( parameters ; Char ( 13 ) ; 1 ; $#Filter.i ) ;
$#Filter.parameterLength
);
~pair = Middle ( parameters ; ~start ; ~end - ~start ) ;
~name = Left ( ~pair ; Position ( ~pair ; " = " ; 1 ; 1 ) - 1 ) ;
$#Filter.result =
// only include ~pair if ~name is in filterParameters
Expand All @@ -73,11 +82,18 @@ Case (
$#Filter.step = 2 or $#Filter.step = -1 ;
Let ( [
~error = $#Filter.step = -1 ;
~result = $#Filter.result ;
~result = $#Filter.result
// add trailing return if it doesn't exist
& If (
not IsEmpty ( $#Filter.result )
and Right ( $#Filter.result ; 1 ) ≠ ¶ ;
) ;

// purge variables
$#Filter.i = "" ;
$#Filter.parameterCount = "" ;
$#Filter.parameterLength = "" ;
$#Filter.result = "" ;
$#Filter.step = ""
];
Expand Down
13 changes: 11 additions & 2 deletions Functions/#Name-Value/#GetNameList.fmfn
Expand Up @@ -17,6 +17,8 @@
* DEPENDENCIES: none
*
* HISTORY:
* MODIFIED on 2013-12-23 by John Jones john.christopher@alumni.virginia.edu
* to use Position/Middle.
* CREATED on 2013-01-24 by Daniel Smith dansmith65@gmail.com
* =====================================
*/
Expand All @@ -34,7 +36,8 @@ Case (
[ "¶¶" ; ¶ ] // remove empty values
) ;

$#GetNameList.parameterCount = ValueCount ( parameters ) ;
$#GetNameList.parameterCount = PatternCount ( parameters ; Char ( 13 ) ) ;
$#GetNameList.parameterLength = Length ( parameters ) ;
$#GetNameList.step = If ( ~empty ; -1 ; /* Else */ 1 )
];
#GetNameList ( parameters )
Expand All @@ -44,7 +47,12 @@ Case (
$#GetNameList.step = 1 ;
Let ( [
$#GetNameList.i = $#GetNameList.i + 1 ;
~pair = GetValue ( parameters ; $#GetNameList.i ) ;
~start = Position ( parameters ; Char ( 13 ) ; 1 ; $#GetNameList.i - 1 ) + 1 ;
~end = Min (
Position ( parameters ; Char ( 13 ) ; 1 ; $#GetNameList.i ) ;
$#GetNameList.parameterLength
);
~pair = Middle ( parameters ; ~start ; ~end - ~start ) ;
~name = Left ( ~pair ; Position ( ~pair ; " = " ; 1 ; 1 ) - 1 ) ;
$#GetNameList.result =
// only include ~name if it isn't already in the result
Expand Down Expand Up @@ -72,6 +80,7 @@ Case (

// purge variables
$#GetNameList.i = "" ;
$#GetNameList.parameterLength = "" ;
$#GetNameList.parameterCount = "" ;
$#GetNameList.result = "" ;
$#GetNameList.step = ""
Expand Down
14 changes: 12 additions & 2 deletions Functions/#Name-Value/#Remove.fmfn
Expand Up @@ -16,6 +16,9 @@
* This is a recursive function.
*
* HISTORY:
* MODIFIED on 2013-12-23 by John Jones
* <john.christopher@alumn.virginia.edu> to use Middle/Position instead of
* GetValue.
* MODIFIED on 2013-03-15 by Daniel Smith <http://scr.im/dansmith> to add
* trailing return if it doesn't exist.
* MODIFIED on 2013-01-08 by Jeremy Bante <http://scr.im/jbante> to extend
Expand All @@ -36,7 +39,8 @@ Case (
& Substitute ( removeParameters ; ¶ ; "¶$" )
& ¶ ;

$#Remove.parameterCount = ValueCount ( parameters ) ;
$#Remove.parameterCount = PatternCount ( parameters ; Char ( 13 ) ) ;
$#Remove.parameterLength = Length ( parameters ) ;
$#Remove.step = If ( ~empty ; -1 ; /* Else */ 1 )
];
#Remove ( parameters ; removeParameters )
Expand All @@ -46,7 +50,12 @@ Case (
$#Remove.step = 1 ;
Let ( [
$#Remove.i = $#Remove.i + 1 ;
~pair = GetValue ( parameters ; $#Remove.i ) ;
~start = Position ( parameters ; Char ( 13 ) ; 1 ; $#Remove.i - 1 ) + 1 ;
~end = Min (
Position ( parameters ; Char ( 13 ) ; 1 ; $#Remove.i ) ;
$#Remove.parameterLength
);
~pair = Middle ( parameters ; ~start ; ~end - ~start ) ;
~name = Left ( ~pair ; Position ( ~pair ; " = " ; 1 ; 1 ) - 1 ) ;
$#Remove.result =
// only include ~pair if ~name is not in removeParameters
Expand Down Expand Up @@ -81,6 +90,7 @@ Case (

// purge variables
$#Remove.i = "" ;
$#Remove.parameterLength = "" ;
$#Remove.parameterCount = "" ;
$#Remove.result = "" ;
$#Remove.step = ""
Expand Down
Binary file modified Functions/#Name-Value/FM-Parameters.fmp12
Binary file not shown.

0 comments on commit 174e6ce

Please sign in to comment.