string.gmatch starting position

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

string.gmatch starting position

Daurnimator
Hi Roberto,

A feature request that would make some code simpler and faster:
It would be great if string.gmatch took a position argument that was used as the starting offset.
This would line up with string.match and string.find.
Looking at the implementation in lstrlib.c it should be very simple to add.

Daurn.

Reply | Threaded
Open this post in threaded view
|

Re: string.gmatch starting position

Enrico Colombini
On 30-Aug-18 05:17, Daurnimator wrote:
> Hi Roberto,
>
> A feature request that would make some code simpler and faster:
> It would be great if string.gmatch took a position argument that was
> used as the starting offset.
> This would line up with string.match and string.find.
> Looking at the implementation in lstrlib.c it should be very simple to add.

Yes, it could be very useful when parsing large strings. I missed this
feature when I wrote a tiny gstring.match-based XML parser some time ago.

--
   Enrico

Reply | Threaded
Open this post in threaded view
|

Re: string.gmatch starting position

云风 Cloud Wu
Enrico Colombini <[hidden email]>于2018年8月30日周四 下午3:21写道:
On 30-Aug-18 05:17, Daurnimator wrote:
> Hi Roberto,
>
> A feature request that would make some code simpler and faster:
> It would be great if string.gmatch took a position argument that was
> used as the starting offset.
> This would line up with string.match and string.find.
> Looking at the implementation in lstrlib.c it should be very simple to add.

Yes, it could be very useful when parsing large strings. I missed this
feature when I wrote a tiny gstring.match-based XML parser some time ago.


I prefer  lua string type can support string slice, A small string slice can share a part of large string.