From ef41e8c9a54119628aa8cffb193e42782e69563f Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Thu, 5 Feb 2026 20:50:31 -0800 Subject: support searching currently playing programmes --- util.lua | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'util.lua') diff --git a/util.lua b/util.lua index d678a9e..ca693ba 100644 --- a/util.lua +++ b/util.lua @@ -155,6 +155,29 @@ function util.unflatten_table(src, dst) return dst end +function util.find_matches(str, substr, case_sensitive) + if not str then + return + end + + if not case_sensitive then + str = str:lower() + end + + local matches + local i, j = 0, 0 + while true do + i, j = str:find(substr, j + 1, true) + -- j < i avoids infinite loop on empty substr + if not i or j < i then + break + end + matches = matches or {} + matches[#matches+1] = {start = i, stop = j} + end + return matches or i and {} +end + function util.str_seek_prev_char(str, pos) return util.utf8_seek(str, pos, -1) end -- cgit v1.2.3-70-g09d2