[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: EndOfLine Pattern Matching
- From: Gavin Wraith <gavin@...>
- Date: Wed, 3 Apr 2002 23:05:11 +0100 (BST)
On Wed 03 Apr, Markus Huber wrote:
>
> How can I match all possible EndOfLines in strfind() with a Lua pattern?
>
> EndOfLine is \n\r
> or \r\n
> or \n
> or \r
>
> but \n\n are two EndOfLines with an empty string between
> also \r\r
>
> Since one hour I try to define a pattern that matches all possible
> EndOfLine definitions.
Are you sure you need to? It is very rare to find different
sorts of EndOfLines in the same file. It is probably easiest
to detect which sort of EndOfLine is being used, e.g.
readfrom(arg[1])
repeat
eol = read(1)
until eol < " " or not eol
if eol then
char = read(1)
if char < " " then
eol = eol..char
end -- if
end -- if
readfrom()
Of course, this won't work if your file has nasty
control characters in it.
--
Gavin Wraith (gavin@wraith.u-net.com)
Home page: http://www.wraith.u-net.com/