def compute_lcd_of_matches(match_list, matches, text)
if (matches == 1)
match_list[0] = match_list[1]
match_list[1] = nil
return 1
end
i = 1
low = 100000
while(i<matches)
if (@_rl_completion_case_fold)
si = 0
while((c1 = _rl_to_lower(match_list[i][si])) &&
(c2 = _rl_to_lower(match_list[i + 1][si])))
if !@rl_byte_oriented
if(!_rl_compare_chars(match_list[i],si,match_list[i+1],si))
break
elsif ((v = _rl_get_char_len(match_list[i][si..-1])) > 1)
si += v - 1
end
else
break if (c1 != c2)
end
si += 1
end
else
si = 0
while((c1 = match_list[i][si]) &&
(c2 = match_list[i + 1][si]))
if !@rl_byte_oriented
if(!_rl_compare_chars(match_list[i],si,match_list[i+1],si))
break
elsif ((v = _rl_get_char_len(match_list[i][si..-1])) > 1)
si += v - 1
end
else
break if (c1 != c2)
end
si += 1
end
end
if (low > si)
low = si
end
i += 1
end
if (low == 0 && text && text.length>0 )
match_list[0] = text.dup
else
if (@_rl_completion_case_fold)
if (@rl_filename_completion_desired &&
@rl_filename_dequoting_function &&
@rl_completion_found_quote &&
@rl_filename_quoting_desired)
dtext = send(@rl_filename_dequoting_function,text, @rl_completion_quote_character)
text = dtext
end
match_list = [match_list[0]] + match_list[1..-1].sort
si = text.length
if (si <= low)
for i in 1 .. matches
if match_list[i][0,si] == text
match_list[0] = match_list[i][0,low]
break
end
if (i > matches)
match_list[0] = match_list[1][0,low]
end
end
else
match_list[0] = text[0,low]
end
else
match_list[0] = match_list[1][0,low]
end
end
return matches
end