endswithany

function endswithany( str, tab ) --> res

Description

Checks if str ends with one of the values in tab.

Parameters

str

The string that should be checked.

tab

An array table with strings.

Return Values

res

Is true if the string ends with one of the values in tab, otherwise false.

Code

--ZFUNC-endswithany-v1
local function endswithany( str, tab ) --> res
   for _, v in ipairs( tab ) do
      local sub = string.sub( str, -string.len( v ) )
      if sub == v then
         return true
      end
   end

   return false
end

return endswithany

Examples

local t = require( "tapered" )
local endswithany = require( "endswithany" )

filename = "note.adoc"
t.ok( endswithany( filename, { ".adoc", ".lua" } ) )
t.nok( endswithany( filename, { ".txt", ".lua" } ) )

t.done()