

//--------------------------------------------
#script=lcontains
//--------------------------------------------
// return true if any list element matches @def, else return false.
// @0: list name, @def: search string

set,i 0
set,l ?{globname,{${@caller}} ${@0}}

if ?{not ?{llen ${l}}}
	return
endif

set,result false
loop
	if ?{equal,${i} ?{llen ${l}}}
		exitloop
	endif
	set,elem ?{lindex,{${l}} ${i}}
	if ?{equal,{${elem}} ${@def}}
		set,result true
		exitloop
	endif
	add,i 1
endloop
unset i
unset l
unset elem
return ${result}


// -----------------------------------------
#script=lcontains_ext
// -----------------------------------------
// returns the amount of matched substrings of @def in list @0.
// default delimiter is space, override with @1.
// by default, any char in @1 serves as delimiter.
// if you set @2 to true, the exact string @1 is used as delimiter (no default is set)
// to check for individual chars in @def, use the following: "lcontains_ex,<list>,,true string_of_chars_for_example"

set,i 0
set,j 0
set,l ?{globname,{${@caller}} ${@0}}
set,delim ${@1}

if ${@2}
	set,engine lsplit
else
	set,engine lcsplit
	// take care of the whitespaces: we use space as delimiter!
	default,delim { }
endif

${engine},myl,{${delim}} ${@def}

// list to check must at least contain 1 element
if ?{not ?{llen ${l}}}
	return 0
endif

// and our pattern list must contain 1 element also
if ?{not ?{llen myl}}
	return 0
endif

set,result 0

loop
	if ?{equal,${i} ?{llen ${l}}}
		exitloop
	endif
	set,elem ?{lindex,{${l}} ${i}}
	set,j 0
	loop
		if ?{equal,${j} ?{llen myl}}
			exitloop
		endif
		set,myelem ?{lindex,myl ${j}}
		if ?{equal,{${elem}} ${myelem}}
			add,result 1
		endif
		add,j 1
	endloop
	add,i 1
endloop

unset i
unset j
unset l
unset engine
unset elem
unset myelem
ldelete myl
unset delim

return ${result}


//--------------------------------------------
#script=lfind
//--------------------------------------------
// return the position of the first element matching @def
// @0: list name, @def: search string
// @1: ignore case?
// if nothing is found, return empty string

set,i 0
set,l ?{globname,{${@caller}} ${@0}}

if ?{not ?{llen ${l}}}
	return
endif

set,result
loop
	if ?{equal,${i} ?{llen ${l}}}
		exitloop
	endif
	set,elem ?{lindex,{${l}} ${i}}
	if ${@1}
		set,eq ?{equal,{?{lowercase ${elem}}} ?{lowercase ${@def}}}
	else
		set,eq ?{equal,{${elem}} ${@def}}
	endif
	if ${eq}
		set,result ${i}
		exitloop
	endif
	add,i 1
endloop
unset i
unset l
unset elem
return ${result}
