mirror of
https://github.com/neovim/neovim.git
synced 2024-12-29 14:41:06 -07:00
vim-patch:7.4.341
Problem: sort() doesn't handle numbers well. Solution: Add an argument to specify sorting on numbers. (Christian Brabandt) https://code.google.com/p/vim/source/detail?r=adc4a84f72eb44dae657af713922a6e2c1f64ae3
This commit is contained in:
parent
1761a4af71
commit
9f252554e3
@ -13362,6 +13362,7 @@ static void f_sinh(typval_T *argvars, typval_T *rettv)
|
|||||||
|
|
||||||
|
|
||||||
static int item_compare_ic;
|
static int item_compare_ic;
|
||||||
|
static bool item_compare_numeric;
|
||||||
static char_u *item_compare_func;
|
static char_u *item_compare_func;
|
||||||
static dict_T *item_compare_selfdict;
|
static dict_T *item_compare_selfdict;
|
||||||
static int item_compare_func_err;
|
static int item_compare_func_err;
|
||||||
@ -13384,10 +13385,18 @@ static int item_compare(const void *s1, const void *s2)
|
|||||||
p1 = (char_u *)"";
|
p1 = (char_u *)"";
|
||||||
if (p2 == NULL)
|
if (p2 == NULL)
|
||||||
p2 = (char_u *)"";
|
p2 = (char_u *)"";
|
||||||
if (item_compare_ic)
|
if (!item_compare_numeric) {
|
||||||
|
if (item_compare_ic) {
|
||||||
res = STRICMP(p1, p2);
|
res = STRICMP(p1, p2);
|
||||||
else
|
} else {
|
||||||
res = STRCMP(p1, p2);
|
res = STRCMP(p1, p2);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
double n1, n2;
|
||||||
|
n1 = strtod((char *)p1, (char **)&p1);
|
||||||
|
n2 = strtod((char *)p2, (char **)&p2);
|
||||||
|
res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1;
|
||||||
|
}
|
||||||
free(tofree1);
|
free(tofree1);
|
||||||
free(tofree2);
|
free(tofree2);
|
||||||
return res;
|
return res;
|
||||||
@ -13454,6 +13463,7 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort)
|
|||||||
return; /* short list sorts pretty quickly */
|
return; /* short list sorts pretty quickly */
|
||||||
|
|
||||||
item_compare_ic = FALSE;
|
item_compare_ic = FALSE;
|
||||||
|
item_compare_numeric = false;
|
||||||
item_compare_func = NULL;
|
item_compare_func = NULL;
|
||||||
item_compare_selfdict = NULL;
|
item_compare_selfdict = NULL;
|
||||||
|
|
||||||
@ -13471,6 +13481,15 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort)
|
|||||||
item_compare_ic = TRUE;
|
item_compare_ic = TRUE;
|
||||||
else
|
else
|
||||||
item_compare_func = get_tv_string(&argvars[1]);
|
item_compare_func = get_tv_string(&argvars[1]);
|
||||||
|
if (item_compare_func != NULL) {
|
||||||
|
if (STRCMP(item_compare_func, "n") == 0) {
|
||||||
|
item_compare_func = NULL;
|
||||||
|
item_compare_numeric = true;
|
||||||
|
} else if (STRCMP(item_compare_func, "i") == 0) {
|
||||||
|
item_compare_func = NULL;
|
||||||
|
item_compare_ic = TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argvars[2].v_type != VAR_UNKNOWN) {
|
if (argvars[2].v_type != VAR_UNKNOWN) {
|
||||||
|
@ -332,6 +332,11 @@ let l = [0, 1, 2, 3]
|
|||||||
:$put =string(reverse(sort(l)))
|
:$put =string(reverse(sort(l)))
|
||||||
:$put =string(sort(reverse(sort(l))))
|
:$put =string(sort(reverse(sort(l))))
|
||||||
:$put =string(uniq(sort(l)))
|
:$put =string(uniq(sort(l)))
|
||||||
|
:let l=[7, 9, 18, 12, 22, 10.0e-16, -1, 0xff, 0, -0, 0.22, 'foo', 'FOOBAR',{}, []]
|
||||||
|
:$put =string(sort(copy(l), 'n'))
|
||||||
|
:$put =string(sort(copy(l), 1))
|
||||||
|
:$put =string(sort(copy(l), 'i'))
|
||||||
|
:$put =string(sort(copy(l)))
|
||||||
:"
|
:"
|
||||||
:" splitting a string to a List
|
:" splitting a string to a List
|
||||||
:$put =string(split(' aa bb '))
|
:$put =string(split(' aa bb '))
|
||||||
|
@ -101,6 +101,10 @@ caught a:000[3]
|
|||||||
[[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0']
|
[[0, 1, 2], [0, 1, 2], 4, 2, 2, 1.5, 'xaaa', 'x8', 'foo6', 'foo', 'foo', 'A11', '-0']
|
||||||
['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]]
|
['-0', 'A11', 'foo', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 2, 4, [0, 1, 2], [0, 1, 2]]
|
||||||
['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]]
|
['-0', 'A11', 'foo', 'foo6', 'x8', 'xaaa', 1.5, 2, 4, [0, 1, 2]]
|
||||||
|
[-1, 0, 0, 'foo', 'FOOBAR', {}, [], 1.0e-15, 0.22, 7, 9, 12, 18, 22, 255]
|
||||||
|
['foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}]
|
||||||
|
['foo', 'FOOBAR', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}]
|
||||||
|
['FOOBAR', 'foo', -1, 0, 0, 0.22, 1.0e-15, 12, 18, 22, 255, 7, 9, [], {}]
|
||||||
['aa', 'bb']
|
['aa', 'bb']
|
||||||
['aa', 'bb']
|
['aa', 'bb']
|
||||||
['', 'aa', 'bb', '']
|
['', 'aa', 'bb', '']
|
||||||
|
@ -254,7 +254,7 @@ static int included_patches[] = {
|
|||||||
344,
|
344,
|
||||||
343,
|
343,
|
||||||
//342 NA
|
//342 NA
|
||||||
//341,
|
341,
|
||||||
//340 NA
|
//340 NA
|
||||||
339,
|
339,
|
||||||
338,
|
338,
|
||||||
|
Loading…
Reference in New Issue
Block a user