reduce use of rfind

[?]
Jan 13, 2023, 5:10 PM
NQM25OZVXXUTUBIIWE2QPHC22JMJB7YRIDKS2XTMQLJLCMLTM5SAC

Dependencies

  • [2] 6K5PFF6X helper: trimming whitespace from strings
  • [3] DW6SNODM source editing: highlight [[ ]] comments/strings
  • [4] KKMFQDR4 editing source code from within the app
  • [*] BULPIBEG beginnings of a module for the text editor
  • [*] PLKNHYZ4 extract a function
  • [*] LXTTOB33 extract a couple of files

Change contents

  • edit in text.lua at line 1003
    [2.172]
    [7.438]
    end
    function starts_with(s, prefix)
    if #s < #prefix then
    return false
    end
    for i=1,#prefix do
    if s:sub(i,i) ~= prefix:sub(i,i) then
    return false
    end
    end
    return true
    end
    function ends_with(s, suffix)
    if #s < #suffix then
    return false
    end
    for i=0,#suffix-1 do
    if s:sub(#s-i,#s-i) ~= suffix:sub(#suffix-i,#suffix-i) then
    return false
    end
    end
    return true
  • edit in search.lua at line 119
    [8.51767]
    [4.177926]
    -- TODO: avoid the expensive reverse() operations
    -- Particularly if we only care about literal matches, we don't need all of string.find
  • replacement in colorize.lua at line 63
    [4.209036][4.209036:209116]()
    if edge.prefix and find(frag, edge.prefix, nil, --[[plain]] true) == 1 then
    [4.209036]
    [4.209116]
    if edge.prefix and starts_with(frag, edge.prefix) then
  • replacement in colorize.lua at line 76
    [4.209358][3.439:543]()
    if edge.suffix and rfind(frag, edge.suffix, nil, --[[plain]] true) == #frag - #edge.suffix + 1 then
    [4.209358]
    [4.209443]
    if edge.suffix and ends_with(frag, edge.suffix) then
  • edit in colorize.lua at line 81
    [4.209503][4.209503:209672]()
    end
    function trim(s)
    return s:gsub('^%s+', ''):gsub('%s+$', '')
    end
    function ltrim(s)
    return s:gsub('^%s+', '')
    end
    function rtrim(s)
    return s:gsub('%s+$', '')