Mercurial > vim
comparison src/search.c @ 23475:79fd5217b125 v8.2.2280
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Commit: https://github.com/vim/vim/commit/9d19e4f4ba55f8bef18d4991abdf740ff6472dba
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 2 18:31:32 2021 +0100
patch 8.2.2280: fuzzy matching doesn't give access to the scores
Problem: Fuzzy matching doesn't give access to the scores.
Solution: Return the scores with a third list. (Yegappan Lakshmanan,
closes #7596)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 02 Jan 2021 18:45:03 +0100 |
parents | a84e7abb0c92 |
children | bb29b09902d5 |
comparison
equal
deleted
inserted
replaced
23474:e4906ec48336 | 23475:79fd5217b125 |
---|---|
4721 qsort((void *)ptrs, (size_t)len, sizeof(fuzzyItem_T), | 4721 qsort((void *)ptrs, (size_t)len, sizeof(fuzzyItem_T), |
4722 fuzzy_match_item_compare); | 4722 fuzzy_match_item_compare); |
4723 | 4723 |
4724 // For matchfuzzy(), return a list of matched strings. | 4724 // For matchfuzzy(), return a list of matched strings. |
4725 // ['str1', 'str2', 'str3'] | 4725 // ['str1', 'str2', 'str3'] |
4726 // For matchfuzzypos(), return a list with two items. | 4726 // For matchfuzzypos(), return a list with three items. |
4727 // The first item is a list of matched strings. The second item | 4727 // The first item is a list of matched strings. The second item |
4728 // is a list of lists where each list item is a list of matched | 4728 // is a list of lists where each list item is a list of matched |
4729 // character positions. | 4729 // character positions. The third item is a list of matching scores. |
4730 // [['str1', 'str2', 'str3'], [[1, 3], [1, 3], [1, 3]]] | 4730 // [['str1', 'str2', 'str3'], [[1, 3], [1, 3], [1, 3]]] |
4731 if (retmatchpos) | 4731 if (retmatchpos) |
4732 { | 4732 { |
4733 li = list_find(fmatchlist, 0); | 4733 li = list_find(fmatchlist, 0); |
4734 if (li == NULL || li->li_tv.vval.v_list == NULL) | 4734 if (li == NULL || li->li_tv.vval.v_list == NULL) |
4747 } | 4747 } |
4748 | 4748 |
4749 // next copy the list of matching positions | 4749 // next copy the list of matching positions |
4750 if (retmatchpos) | 4750 if (retmatchpos) |
4751 { | 4751 { |
4752 li = list_find(fmatchlist, -2); | |
4753 if (li == NULL || li->li_tv.vval.v_list == NULL) | |
4754 goto done; | |
4755 l = li->li_tv.vval.v_list; | |
4756 | |
4757 for (i = 0; i < len; i++) | |
4758 { | |
4759 if (ptrs[i].score == SCORE_NONE) | |
4760 break; | |
4761 if (ptrs[i].lmatchpos != NULL && | |
4762 list_append_list(l, ptrs[i].lmatchpos) == FAIL) | |
4763 goto done; | |
4764 } | |
4765 | |
4766 // copy the matching scores | |
4752 li = list_find(fmatchlist, -1); | 4767 li = list_find(fmatchlist, -1); |
4753 if (li == NULL || li->li_tv.vval.v_list == NULL) | 4768 if (li == NULL || li->li_tv.vval.v_list == NULL) |
4754 goto done; | 4769 goto done; |
4755 l = li->li_tv.vval.v_list; | 4770 l = li->li_tv.vval.v_list; |
4756 | |
4757 for (i = 0; i < len; i++) | 4771 for (i = 0; i < len; i++) |
4758 { | 4772 { |
4759 if (ptrs[i].score == SCORE_NONE) | 4773 if (ptrs[i].score == SCORE_NONE) |
4760 break; | 4774 break; |
4761 if (ptrs[i].lmatchpos != NULL && | 4775 if (list_append_number(l, ptrs[i].score) == FAIL) |
4762 list_append_list(l, ptrs[i].lmatchpos) == FAIL) | |
4763 goto done; | 4776 goto done; |
4764 } | 4777 } |
4765 } | 4778 } |
4766 } | 4779 } |
4767 | 4780 |
4840 goto done; | 4853 goto done; |
4841 if (retmatchpos) | 4854 if (retmatchpos) |
4842 { | 4855 { |
4843 list_T *l; | 4856 list_T *l; |
4844 | 4857 |
4845 // For matchfuzzypos(), a list with two items are returned. First item | 4858 // For matchfuzzypos(), a list with three items are returned. First |
4846 // is a list of matching strings and the second item is a list of | 4859 // item is a list of matching strings, the second item is a list of |
4847 // lists with matching positions within each string. | 4860 // lists with matching positions within each string and the third item |
4861 // is the list of scores of the matches. | |
4848 l = list_alloc(); | 4862 l = list_alloc(); |
4849 if (l == NULL) | 4863 if (l == NULL) |
4850 goto done; | 4864 goto done; |
4851 if (list_append_list(rettv->vval.v_list, l) == FAIL) | 4865 if (list_append_list(rettv->vval.v_list, l) == FAIL) |
4852 goto done; | 4866 goto done; |
4853 l = list_alloc(); | 4867 l = list_alloc(); |
4854 if (l == NULL) | 4868 if (l == NULL) |
4855 goto done; | 4869 goto done; |
4856 if (list_append_list(rettv->vval.v_list, l) == FAIL) | 4870 if (list_append_list(rettv->vval.v_list, l) == FAIL) |
4857 goto done; | 4871 goto done; |
4872 l = list_alloc(); | |
4873 if (l == NULL) | |
4874 goto done; | |
4875 if (list_append_list(rettv->vval.v_list, l) == FAIL) | |
4876 goto done; | |
4858 } | 4877 } |
4859 | 4878 |
4860 fuzzy_match_in_list(argvars[0].vval.v_list, tv_get_string(&argvars[1]), | 4879 fuzzy_match_in_list(argvars[0].vval.v_list, tv_get_string(&argvars[1]), |
4861 matchseq, key, &cb, retmatchpos, rettv->vval.v_list); | 4880 matchseq, key, &cb, retmatchpos, rettv->vval.v_list); |
4862 | 4881 |