[PATCH] templates: add substring and string length operations

Yuya Nishihara yuya at tcha.org
Sat Jul 15 02:23:56 EDT 2017


On Fri, 14 Jul 2017 20:40:36 -0700, Martin von Zweigbergk wrote:
> On Jul 14, 2017 8:19 PM, "Yuya Nishihara" <yuya at tcha.org> wrote:
> 
> On Fri, 14 Jul 2017 19:50:34 -0700, Rodrigo Damazio wrote:
> > > On Fri, 14 Jul 2017 16:27:49 -0700, Rodrigo Damazio via Mercurial-devel
> > > > + at templatefunc('substr(text, start[, end])')
> > >
> > > I think substr() generally takes offset and length, not start:end range.
> >
> > Yes, I considered that the start:end (like Python has) was more powerful
> > because it allows negative numbers to reference the end, whereas offset
> and
> > length needs to be calculated in those cases. Would you like me to switch?
> 
> start and offset can be negative anyway, though length can't. The name
> 'substr()' seems confusing if it takes start:end. Can you find another name
> or switch it to take length?
> 
> Maybe Python calls it slicing? So slice() might be okay.

Sounds good to me. It could optionally support a slice over list.


More information about the Mercurial-devel mailing list