On Tue, Oct 10, 2017 at 10:19 PM, Soni L. wrote:
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 ')
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?
It says "end". It implies you already know the start.
"\""
function end_of_string_literal (text, start_pos, quote)
return text:gsub("\\?.", {[quote]="0円"}):match("%z()", start_pos)
end
print(end_of_string_literal ([[a="\"A",b="\\\"B\"",c="C"]], 4, '"')) --> 8
print(end_of_string_literal ([[a="\"A",b="\\\"B\"",c="C"]], 12, '"')) --> 20
print(end_of_string_literal ([[a="\"A",b="\\\"B\"",c="C"]], 24, '"')) --> 26