[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Finding end of string
- From: Dirk Laurie <dirk.laurie@...>
- Date: Tue, 10 Oct 2017 21:13:42 +0200
function end_of_string_literal(word,quote)
local m,pos
repeat
m, pos = string.match(word, "(\\*)"..quote.."()", pos or 2)
until m == nil or #m % 2 == 0
return pos
end
end_of_string_literal("abc'defgh'ijkl","'")
5
Should not the answer rather be 11?
And would not
function end_of_string_literal(word,quote)
local pattern = '()%b' .. quote:rep(2) ..'()'
return select(2,word:match(pattern))
end
be somewhat simpler?
2017-10-10 20:25 GMT+02:00 Soni L. <fakedme@gmail.com>:
>
>
> On 2017-10-10 02:44 PM, Dirk Laurie wrote:
>>
>> 2017-10-10 14:52 GMT+02:00 Soni L. <fakedme@gmail.com>:
>>>
>>> local m, pos
>>> repeat -- TODO fix
>>> m, pos = string.match(word_eol[2],
>>> "%f[\\"..cw:sub(1,1).."](\\*)"..cw:sub(1,1).."()", pos)
>>> until #m % 2 == 0
>>>
>>> I'm having issues making this work.
>>
>> The title of the post describes a trivial problem (answer: #str+1).
>>
>> I can't work by reading it what problem the code tries to solve.
>>
>
> Sorry, I meant end of string literal.
>
> After a few hours I came up with this, which works:
>
> local m, pos
> repeat
> m, pos = string.match(word_eol[2], "(\\*)"..cw:sub(1,1).."()", pos or 2)
> until m == nil or #m % 2 == 0
>
> (cw:sub(1,1) being one of " or ')
>
>
> --
> Disclaimer: these emails may be made public at any given time, with or
> without reason. If you don't agree with this, DO NOT REPLY.
>
>