[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.6.3 CASE - Select one of several template blocks

The arguments are evaluated and converted to a string, if necessary. A simple name will be interpreted as an AutoGen value name and its value will be used by the SELECT macros (see the example below and the expression evaluation function, see section EXPR - Evaluate and emit an Expression). The scope of the macro is up to the matching ESAC macro. Within the scope of a CASE, this string is matched against case selection macros. There are sixteen match macros that are derived from four different ways matches may be performed, plus an "always true", "true if the AutoGen value was found", and "true if no AutoGen value was found" matches. The codes for the nineteen match macros are formed as follows:

  1. Must the match start matching from the beginning of the string? If not, then the match macro code starts with an asterisk (*).
  2. Must the match finish matching at the end of the string? If not, then the match macro code ends with an asterisk (*).
  3. Is the match a pattern match or a string comparison? If a comparison, use an equal sign (=). If a pattern match, use a tilde (~).
  4. Is the match case sensitive? If alphabetic case is important, double the tilde or equal sign.
  5. Do you need a default match when none of the others match? Use a single asterisk (*).
  6. Do you need to distinguish between an empty string value and a value that was not found? Use the non-existence test (!E) before testing a full match against an empty string (== ''). There is also an existence test (+E), more for symmetry than for practical use.

For example:

[+ CASE <full-expression> +]
[+ ~~*  "[Tt]est" +]reg exp must match at start, not at end
[+ ==   "TeSt"    +]a full-string, case sensitive compare
[+ =    "TEST"    +]a full-string, case insensitive compare
[+ !E             +]not exists - matches if no AutoGen value found
[+ ==   ""        +]expression yielded a zero-length string
[+ +E             +]exists - matches if there is any value result
[+ *              +]always match - no testing
[+ ESAC +]

<full-expression> (see section Macro Expression Syntax) may be any expression, including the use of apply-codes and value-names. If the expression yields a number, it is converted to a decimal string.

These case selection codes have also been implemented as Scheme expression functions using the same codes. They are documented in this texi doc as “string-*?” predicates (see section Common Scheme Functions).

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Bruce Korb on August 21, 2015 using texi2html 1.82.