diff options
author | watiko <service@mail.watiko.net> | 2016-02-20 17:45:51 +0900 |
---|---|---|
committer | watiko <service@mail.watiko.net> | 2016-03-02 17:32:24 +0900 |
commit | 313810ccada3b5f3dad73d8c376652533636f46b (patch) | |
tree | 384396be13e65ee2565fe7aa255a49c1c2c49d05 /src/nvim/eval.c | |
parent | f6dca79f3aa2b55927a5f1cee4a6bf25d5c9bd37 (diff) | |
download | rneovim-313810ccada3b5f3dad73d8c376652533636f46b.tar.gz rneovim-313810ccada3b5f3dad73d8c376652533636f46b.tar.bz2 rneovim-313810ccada3b5f3dad73d8c376652533636f46b.zip |
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().
https://github.com/vim/vim/commit/f7edf40448a09e04eec3bd05e043f7fea93b07c9
Diffstat (limited to 'src/nvim/eval.c')
-rw-r--r-- | src/nvim/eval.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index c4e3781543..b2370e7047 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -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. |