o do faster searches (-sorted)
    if { ! $sorted }  {
	set list [ lsort $list ]
    }

    # Ok, now match the elements
    #
    #puts "[info level 0]"

    # First try the exact match. -all returns all matches and -sorted makes search faster
    #
    if {! [llength [set matchedVals [ lsearch -exact -all -inline -sorted $list $val ]]] } {
	#puts "Didnt find an exact match"
	
	# ok, now try the glob match
	if {! [llength [set matchedVals [ lsearch -glob -inline -all $list "$val*"]]] } {
	    # Not found. Return an empty string
	    #puts "Didnt find an glob match either"
	    return ""
	}
    } 
   

    # Cool, now we have one (or more) matched indexes.
    # First do fatalIfNotUnique thingy
    #
    if {$fatalIfNotUnique && [llength $matchedVals] > 1 } {
	error "Utils::findabbr : Multiple matches found for $val"
    }


    # Now do returnList thingy
    if {$returnList} {
	return $matchedVals
    } else {
	return [lindex $matchedVals 0]
    }

    error "Should not reach here"
}



proc Utils::test_findabbr args {

    set t1list "abc defo fgt fptos lkgdo"
    
    # Test if it returns the correct abbr (exact match)
    if {[set ret [findabbr $t1list "fgt"]] ne "fgt"} {
	error "Error: Expected fgt. Got $ret"
    } else {
	puts "Exact match test successfull: $ret (expecting fgt)"
    }
    
    # Multiple matches
    # Test if it returns the correct abbr (glob match)
    # fatalIfNotUnique is set to 0 here and returnList is set to 1
    set ret [findabbr $t1list "f" 0 0 1]
    # should have only two matches
    if {[llength $ret] == 2} {	
    } else {
	error "Error: Expected return to be list of 2 elements {fgt fptos}. Got $ret"
    }

    if { [lsearch -exact $ret "fptos"] > -1  && [lsearch -exact $ret "fgt"] > -1 } {
	puts "Glob match (returnList true) test successfull: $ret (expecting fptos and fgt)"
    } else {
	error "Error: Expected {fgt fptos}. Got $ret"
    }

    # Test if it returns the correct abbr (glob match)
    # fatalIfNotUnique is set to 0 here and returnList is set to 0
    set ret [findabbr $t1list "f" 0 0 0]
    # should have only one match
    if {$ret ne "fgt"} {
	error "Error: Expected fgt. Got $ret"
    } else {
	puts "Glob match (returnList false) successfull: $ret (expecting only fgt)"
    }

    ## Test if it returns the index if returnIndex is set
    #set ret [findabbr $t1list "f" 0 0 0]
    ## should have only one match
    #if {! [llength $ret] == 2} {
    #	error "Error: Expected fgt and fptos. Got $ret"
    #}
    #if { [lsearch -exact $ret "fptos"] > -1  && [lsearch -exact $ret "fgt"] > -1 } {
    #} else {
    #	error "Error: Expected fptos and fgt. Got $ret"
    #}
    #
    ## Test if it returns the index if returnIndex is set
    #set ret [findabbr $t1list "f" 1 0 0 0]
    ## should have only one match
    #if {! [llength $ret] == 2} {
    #	error "Error: Expected fptos and fgt. Got $ret"
    #}
    #if { [lsearch -exact $ret "fptos"] > -1  && [lsearch -exact $ret "fgt"] > -1 } {
    #} else {
    #	error "Error: Expected fptos and fgt. Got $ret"
    #}
    

    # Test if it croaks when multiple matches and fatalIfNotUnique
    if { [catch { findabbr $t1list "f" } ret]} {
	puts "Glob match (fatalIfNotUnique set to default true) successfull: Failure: $ret (expecting Multiple matches found for f)"
    } else {
	error "Error: Should have croaked here since fatalIfUnique was true"
    }

    # Test if it returns muliple matches when returnList is true
    # Already checked above

    # Test if it returns muliple indexs when returnList is true and returnIndex is true
    # N/A

    # Test if it returns first of the muliple matches when returnList is false
    # Already checked above

    puts "All tests concluded successfully"
}


