lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Markus Huber  wrote:
> > Tom Wrensch wrote:
> > I don't think you can do this directly with strfind. The pattern
> > matcher built into Lua cannot handle disjunctions of multicharacter
> > 'tokens'.
> Then I will implement a enhanced strfind() to handle disjunctions of
> multicharacter 'tokens' to accept optional an table instead of a single
> string search pattern:
> strfind(String,{"\n","\r","\n\r","\r\n"})
> Then a standard strfind() call with a single string is - besides the
> type check - as fast as ever. And the example above needs internal four
> strfind() runs and returns the leftmost result.
> Any other suggestions? Has anyone done this before? Do you see problems?

That's the problem with strfind, you can search only one string at a time,
which is annoying when parsing a file.

I started to code an alternate version, without RE, but using a fast search
algorithm, which will process a string as fast as possible, performing its
matchings simultaneously (instead of search one string, then another, etc. and
return the first occurence).

Alas, it is far from finished and I have little time to spend on it,
although I can try.

Other suggestions:
- As suggested by various people, including me, pre-process the string where
you have read the file. If you don't need to write it back in the same (or
similar) state as it was, it is the easiest in the current state of Lua.
- Do 4 strfind and take the lowest position... Not very fast I fear.
- Parse the file char by char. The slowest solution...


Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist

GMX - Die Kommunikationsplattform im Internet.