PPWIZARD is a free preprocessor for HTML, REXX, Visual Basic or any text files.
CompareReplaceFixed() |
This is an inbuilt function function provided by PPWIZARD.
This function has 2 main operations as follows:
This is quite a complicated routine and hopefully the examples will clarify things.
This routine can be very useful in #AsIs and #AutoTag processing.
The function takes 3 parameters as follows:
This is made up of one or more of the following command sequences (in any order):
The "posn" is the integer position of the substring within the "COMPARE" parameter to compare with "CmpText".
If the value is positive then the value refers to a position from the left else it refers to a position from the right. For example "2" indicates the second character from the left while "-2" indicates the second last character. If you have previosly modified the (leading/trailing) whitespace then the position is relative to the updated string.
The length of the substring is the same as the length of "CmpText".
Any character can be used for a quote character around the "CmpText".
Any character can be used for a quote character around the "CmpText".
If not supplied then we are doing a simple compare operation and returning 1 on match and 0 if not.
This parameter determines what string this routine will return. You can extract parts of the first parameter and intermix text of your own.
A return command is imbedded in text and begins with the '@' character, the following character determines the type of command (and where it ends), valid commands are:
If the value is positive then the value refers to a position from the left else it refers to a position from the right. For example "2" indicates the second character from the left while "-2" indicates the second last character. If you have previosly modified the (leading/trailing) whitespace then the position is relative to the updated string.
Any character can be used for a quote character around the "RexxExpression" parameter.
While some validation of the parameters is performed you should be careful with the parameters passed. If invalid parameters are passed you probably will not get the "change" you desire and I'm not ruling out a PPWIZARD trap. Validations are only performed when they will not (greatly) affect performance.
Example - Compare Specifications |
Example - Return Specifications |
Real Life Examples (via #AutoTag) |
<p>This is used in documentation for a language where each command starts on a new line and you are providing examples in the documenattion. <p>What this command is doing: <$OrdListCompact> <$li>The 1st #autotag parameter is the search specification and the 2nd is the return string. The string being compared/updated is supplied from the line being auto-tagged. <p> <$li>Indicates the compare is case insensitive <$li>Indicates that we want to ignore leading spaces <$li>Checks if HTML is at the 1st position <p> <$li>The return string should begin with the previously removed spaces. <$li>Output some specific text to start a macro reference ("<LT>$LinkTo Text=~"). <$li>Grab the first 2 characters of the line ("ht") in whatever the ORIGINAL case was. <$li>Output some specific text to break up the HTML string ("<LT>?_<GT>"). <$li>Grab the next 2 characters of the line ("ml") in whatever the ORIGINAL case was. <$li>Output some specific text to end a macro reference ("~<GT>"). <$li>Grab the rest of the line <$eOrdListCompact> <$Example STATE="REMEMBER"> #option PUSH AtChangeType="FIXED" #AutoTag ^!i!L@=,1=~HTML~^ ^@<<$LinkTo Text=~@$1,2;<?_>@$3,2;~>@$5,*;^ ;;Note don't want any following auto tagging to find "html" #option POP
Stupid Examples |
;--- Use CompareReplaceFixed() via #AutoTag ----------- #option PUSH AtChangeType="FIXED" #AutoTag '@=,1=^HTML^@=,5=+x+' 'REM CS->@$1,*;' ;;Case sensitive compare for "HTML" then "x" #AutoTag '!i@=,1=^HTML^!S@=,-1=+x+' 'REM CI->@$1,*;' ;;Case insensitive comapre for "HTML" + sensitive compare for "x" #AutoTag '!L!i@=,1=^HTML^!S@=,5=+x+' 'REM CI+spaces->@$1,*;' ;;Same as above but ignoring whitespace (leading) #option POP ;--- The following compare operation will return "1" as the compare "matches" --- #evaluate ^^ ^say 'Expect to see 1 ==> ' || CompareReplaceFixed('HTML', '@=,1=~HTML~')^ ;--- The following compare matches and the return specification is processed --- #evaluate ^^ ^say 'Expect to see ASDF ==> ' || CompareReplaceFixed('HTML', '@=,1=~HTML~', 'ASDF')^