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

10.2.2 Quick Start

As an example, let's consider the following Rewrite function:

 
string
foo(integer i)
{
    string rc;
    if (i % 2)
        rc = "odd";
    else
        rc = "even";
    return "the number is " + rc;
}

The function takes an integer argument and returns the string ‘the number is odd’ or ‘the number is even’, depending on the value of i. This illustrates the fact that in Rewrite the addition operator is defined on the string type. The result of such operation is the concatenation of operands.

Another example is a function that adds a prefix to the User-Name attribute:

 
integer
px_add()
{
        %[User-Name] = "pfx-" + %[User-Name];
        return 0;
}

This function manipulates the contents of the incoming request; its return value has no special meaning.


This document was generated by Sergey Poznyakoff on December, 6 2008 using texi2html 1.78.