mirror of
https://github.com/neovim/neovim.git
synced 2025-09-13 06:48:17 +00:00
vim-patch:7.4.411
Problem: "foo bar" sorts before "foo" with sort(). (John Little) Solution: Avoid putting quotes around strings before comparing them. https://code.google.com/p/vim/source/detail?r=v7-4-411
This commit is contained in:
@@ -13461,15 +13461,36 @@ static int item_compare(const void *s1, const void *s2)
|
|||||||
{
|
{
|
||||||
sortItem_T *si1, *si2;
|
sortItem_T *si1, *si2;
|
||||||
char_u *p1, *p2;
|
char_u *p1, *p2;
|
||||||
char_u *tofree1, *tofree2;
|
char_u *tofree1 = NULL, *tofree2 = NULL;
|
||||||
int res;
|
int res;
|
||||||
char_u numbuf1[NUMBUFLEN];
|
char_u numbuf1[NUMBUFLEN];
|
||||||
char_u numbuf2[NUMBUFLEN];
|
char_u numbuf2[NUMBUFLEN];
|
||||||
|
|
||||||
si1 = (sortItem_T *)s1;
|
si1 = (sortItem_T *)s1;
|
||||||
si2 = (sortItem_T *)s2;
|
si2 = (sortItem_T *)s2;
|
||||||
p1 = tv2string(&si1->item->li_tv, &tofree1, numbuf1, 0);
|
typval_T *tv1 = &si1->item->li_tv;
|
||||||
p2 = tv2string(&si2->item->li_tv, &tofree2, numbuf2, 0);
|
typval_T *tv2 = &si2->item->li_tv;
|
||||||
|
// tv2string() puts quotes around a string and allocates memory. Don't do
|
||||||
|
// that for string variables. Use a single quote when comparing with a
|
||||||
|
// non-string to do what the docs promise.
|
||||||
|
if (tv1->v_type == VAR_STRING) {
|
||||||
|
if (tv2->v_type != VAR_STRING || item_compare_numeric) {
|
||||||
|
p1 = (char_u *)"'";
|
||||||
|
} else {
|
||||||
|
p1 = tv1->vval.v_string;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
p1 = tv2string(tv1, &tofree1, numbuf1, 0);
|
||||||
|
}
|
||||||
|
if (tv2->v_type == VAR_STRING) {
|
||||||
|
if (tv1->v_type != VAR_STRING || item_compare_numeric) {
|
||||||
|
p2 = (char_u *)"'";
|
||||||
|
} else {
|
||||||
|
p2 = tv2->vval.v_string;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
p2 = tv2string(tv2, &tofree2, numbuf2, 0);
|
||||||
|
}
|
||||||
if (p1 == NULL)
|
if (p1 == NULL)
|
||||||
p1 = (char_u *)"";
|
p1 = (char_u *)"";
|
||||||
if (p2 == NULL)
|
if (p2 == NULL)
|
||||||
@@ -13487,8 +13508,8 @@ static int item_compare(const void *s1, const void *s2)
|
|||||||
res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1;
|
res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// When the result would be zero, compare the pointers themselves. Makes
|
// When the result would be zero, compare the item indexes. Makes the
|
||||||
// the sort stable.
|
// sort stable.
|
||||||
if (res == 0 && !item_compare_keep_zero) {
|
if (res == 0 && !item_compare_keep_zero) {
|
||||||
res = si1->idx > si2->idx ? 1 : -1;
|
res = si1->idx > si2->idx ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
@@ -217,7 +217,7 @@ static int included_patches[] = {
|
|||||||
//414,
|
//414,
|
||||||
//413 NA
|
//413 NA
|
||||||
//412 NA
|
//412 NA
|
||||||
//411,
|
411,
|
||||||
410,
|
410,
|
||||||
//409 NA
|
//409 NA
|
||||||
//408,
|
//408,
|
||||||
|
Reference in New Issue
Block a user