lua-users home
lua-l archive

Re: Finding end of string

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


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.
>
>

AltStyle によって変換されたページ (->オリジナル) /