[ZPT] Truncating strings

fergal at esatclear.ie fergal at esatclear.ie
Fri Oct 24 07:15:07 EDT 2003


From: Fernando Martins fmartins at hetnet.nl

> How would you explain in the FAQ why constants and parameter names are not
> allowed? ;-)

Not sure why the smiley, this is a problem. However you could just do

replace="lib/fmt/append(this/thing, string:hello)"

however there is a problem with parsing that. The string: construct has no
end marker, so you don't know if the string is "hello" or "hello)". I would
suggest allowing " and ' delimited strings in argument lists and also
treating anything which looks like a number. So 10 would be the 10, not the
variable called "10". Anyone using a variable called 10 deserves to be shot
anyway.

So append(this/thing, 'hello') and truncate(this/thing, 10) would do
exactly what you'd expect.

If people really objected to using numeric constants then you could make an
object num such that num/x returns x where x is a number so you do

truncate(this/thing, num/10)

or you introduce a num: equivalent of string: but I think both of these
suck compared just treating "10" as 10 in argument context. If you really
need to get inside the variable named "10" you could do $10 or ${10} or
something but like I said anyone who used numbers for variables names...

As for parameter names, you can't have everything. I'd suggest that any
method being called from a template that needs named paramters is going way
beyond what you should be doing in a template.

Although if you really really wanted then you could correctly parse

truncate(this/thing, 10, more='...')

but I think that's going too far.

Anyone making sensible use of this would be probably be using methods that
have been designed specifically for templates, like the array batching
methods or pretty truncation and so should have no need for named params,

F



--------------------------------------------------------------------
mail2web - Check your email from the web at
http://mail2web.com/ .





More information about the ZPT mailing list