mirror of
https://github.com/neovim/neovim.git
synced 2025-09-16 08:18:17 +00:00
vim-patch:7.4.1143
Problem: Can't sort on floating point numbers.
Solution: Add the "f" flag to ":sort". (Alex Jakushev) Also add the "f"
flag to sort().
f7edf40448
This commit is contained in:
@@ -15749,6 +15749,7 @@ typedef struct {
|
||||
static int item_compare_ic;
|
||||
static bool item_compare_numeric;
|
||||
static bool item_compare_numbers;
|
||||
static bool item_compare_float;
|
||||
static char_u *item_compare_func;
|
||||
static dict_T *item_compare_selfdict;
|
||||
static int item_compare_func_err;
|
||||
@@ -15778,6 +15779,13 @@ static int item_compare(const void *s1, const void *s2, bool keep_zero)
|
||||
return v1 == v2 ? 0 : v1 > v2 ? 1 : -1;
|
||||
}
|
||||
|
||||
if (item_compare_float) {
|
||||
float_T v1 = get_tv_float(tv1);
|
||||
float_T v2 = get_tv_float(tv2);
|
||||
|
||||
return v1 == v2 ? 0 : v1 > v2 ? 1 : -1;
|
||||
}
|
||||
|
||||
// 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.
|
||||
@@ -15925,6 +15933,7 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort)
|
||||
item_compare_ic = FALSE;
|
||||
item_compare_numeric = false;
|
||||
item_compare_numbers = false;
|
||||
item_compare_float = false;
|
||||
item_compare_func = NULL;
|
||||
item_compare_selfdict = NULL;
|
||||
|
||||
@@ -15949,6 +15958,9 @@ static void do_sort_uniq(typval_T *argvars, typval_T *rettv, bool sort)
|
||||
} else if (STRCMP(item_compare_func, "N") == 0) {
|
||||
item_compare_func = NULL;
|
||||
item_compare_numbers = true;
|
||||
} else if (STRCMP(item_compare_func, "f") == 0) {
|
||||
item_compare_func = NULL;
|
||||
item_compare_float = true;
|
||||
} else if (STRCMP(item_compare_func, "i") == 0) {
|
||||
item_compare_func = NULL;
|
||||
item_compare_ic = TRUE;
|
||||
@@ -18586,6 +18598,33 @@ long get_tv_number_chk(typval_T *varp, int *denote)
|
||||
return n;
|
||||
}
|
||||
|
||||
static float_T get_tv_float(typval_T *varp)
|
||||
{
|
||||
switch (varp->v_type) {
|
||||
case VAR_NUMBER:
|
||||
return (float_T)(varp->vval.v_number);
|
||||
case VAR_FLOAT:
|
||||
return varp->vval.v_float;
|
||||
break;
|
||||
case VAR_FUNC:
|
||||
EMSG(_("E891: Using a Funcref as a Float"));
|
||||
break;
|
||||
case VAR_STRING:
|
||||
EMSG(_("E892: Using a String as a Float"));
|
||||
break;
|
||||
case VAR_LIST:
|
||||
EMSG(_("E893: Using a List as a Float"));
|
||||
break;
|
||||
case VAR_DICT:
|
||||
EMSG(_("E894: Using a Dictionary as a Float"));
|
||||
break;
|
||||
default:
|
||||
EMSG2(_(e_intern2), "get_tv_float()");
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the lnum from the first argument.
|
||||
* Also accepts ".", "$", etc., but that only works for the current buffer.
|
||||
|
Reference in New Issue
Block a user