Quick actions

cmd+k|ctrl+k

Navigation

Languages

a bunch of.lua

Snippet info

Language

Lua

Visibility

public

Author

techhog

Created

2021-05-01T17:53:13.15055Z

Updated

2021-12-23T19:26:29.982972Z

function string.split(inputstr, sep)
    local sep = sep or '%s'
    local split = {}
    for str in string.gmatch(inputstr, '([^' .. sep .. ']+)') do
        table.insert(split, str)
    end
    return split
end
function getRidOfSpaces(_string)
	local emptyString = ''
	local split = string.split(_string, ' ')
	for a,b in pairs(split) do
		if b then
			emptyString = emptyString .. b
		end
	end
	return emptyString
end
function containsTerm(term1, term2)
	if term1 and term2 then
	    local containsterm = false
		local _term1 = getRidOfSpaces(string.lower(term1))
		local _term2 = getRidOfSpaces(string.lower(term2))
		if _term1 == _term2 then containsterm = true end
		if string.find(_term1, _term2) or string.find(_term2, _term1) then containsterm = true end
		if string.match(_term1, _term2) or string.match(_term2, _term1) then containsterm = true end
		return containsterm
	end
end
local dataBase = {{term='burger king', title='Burger King', description='Burger King is a fast food chain with burgers.'}, {term='balls',title='BALLS',description='Balls is a funny word'}}
function getTitle(term)
	for a,b in pairs(dataBase) do 
		if containsTerm(term, b['term']) == true then 
			local title = b['title']
			return title
		end 
	end 
end
function getDescription(term)
	for a,b in pairs(dataBase) do 
		if containsTerm(term, b['term']) == true then 
			local description = b['description']
			return description
		end 
	end 
end
function assertPrint(a, _string)
    if not a then 
        print(_string)
        return
    end 
    return a
end

function indexInTable(t, v)
    for a,b in pairs(t) do 
        if b == v then return a end
    end 
end 
function tableLength(t)
    local length = 0
    for a,b in pairs(t) do
        if b then length = length + 1 end
    end 
    return length
end 

function convertTableToString(t)
   local lol = '{'
    for a,b in pairs(t) do 
        if b then
            if a == tableLength(t) then
                lol = lol .. b..'}'
            else
                lol = lol .. b .. ', '
            end
        end
    end
    return lol
end

function lowercase(str)
    local result = str:gsub('.', function(a) return string.lower(a) end)
    return result
end 

--//showcase\\--
local _ = ''
for a,split in pairs(string.split('H     e      l     l     o T h e r   e', ' ')) do 
    if split then
       _ = _ .. split
    end
end
print('string.split: ', _)
_ = ''
print('getRidOfSpaces: ', getRidOfSpaces('H     e       l     l      o      T   h  e   r   e '))
print('containsTerm: ', containsTerm('big balls', 'ball'))
print('containsTerm: ', containsTerm('big balls', 'llab'))
assertPrint('chicken'=='chicken', 'chicken!')
assertPrint('chicken'~='chicken', 'no chicken!')
print(lowercase('HI JOE!'))
INFO