tree-sitter/functions.lua
Martin Pluskal 6291acbcdd Accepting request 1160845 from home:Thaodan:editors
- Add packaging macros for tree-sitter grammar
- Add missing dependency for tree-sitter generate

OBS-URL: https://build.opensuse.org/request/show/1160845
OBS-URL: https://build.opensuse.org/package/show/editors/tree-sitter?expand=0&rev=23
2024-03-25 15:00:40 +00:00

46 lines
865 B
Lua

--[[
SPDX-License-Identifier: GPL-2.0
SPDX-FileCopyrightText: 2024 Björn Bidar
partly based of functions.lua from python-rpm-macros
--]]
-- declare common functions
function string.startswith(str, prefix)
return str:sub(1, prefix:len()) == prefix
end
function string.endswith(str, suffix)
return str:sub(-suffix:len()) == suffix
end
function string.dirname(str)
if str:match("(.*)/") == "" then
return nil
else
return str:match("(.*)/")
end
end
function string.basename(str)
while true do
local idx = str:find("/")
if not idx then return str end
str = str:sub(idx + 1)
end
end
function string.split(str, sep)
if sep == nil then
sep = '%s'
end
local res = {}
local func = function(w)
table.insert(res, w)
end
string.gsub(str, '[^'..sep..']+', func)
return res
end