This patch allows the macro programmer to drop the last
parameter to the three parameter built-in function
substring(). Normally substring() is called as
substring(string, start, end)
This leads to heavy duty calls such as
substring(string, start, length(string))
just to retrieve the end of a string. It would be easier
just to say
and make the function itself provide the end position.
This is the first thing this patch does. Note that this
change in itself has no adverse effects on existing macro
code since, until now, all three parameters were required.
The patch does change some behaviour. The changes
seem sensible and useful to me, as well as better than
the current behaviour. This concerns the actions of
substring() when the given end marker is negative or
less than the start position.
Former behaviour: if end is negative, it is set to zero; if
it is less than start, the values of start and end are
swapped. This means that the following are true:
substring("hello world", 5, -1) == "hello"
substring("hello world", 5, 1) == "ello"
This behaviour seems very counterintuitive. The
result "should" be "".
New behaviour: if end is negative or smaller than start,
the empty string is returned. If it is not given, the end
position used is the end of the string. So the following is
substring("hello world", 5, -1) == ""
substring("hello world", 5, 1) == ""
substring("hello world", 5) == " world"
The behaviour with negative values for end appears
justified since there does not appear (to me at least) for
a program to desire the "flip the positions" behaviour,
and that existing, non-buggy macro code will make
certain this is the case.