patch 7.4.951
Problem: Sorting number strings does not work as expected. (Luc Hermitte)
Solution: Add the 'N" argument to sort()
diff --git a/src/eval.c b/src/eval.c
index 2d6c34b..ef0ea5e 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -17928,6 +17928,7 @@
static int item_compare_ic;
static int item_compare_numeric;
+static int item_compare_numbers;
static char_u *item_compare_func;
static dict_T *item_compare_selfdict;
static int item_compare_func_err;
@@ -17958,6 +17959,15 @@
si2 = (sortItem_T *)s2;
tv1 = &si1->item->li_tv;
tv2 = &si2->item->li_tv;
+
+ if (item_compare_numbers)
+ {
+ long v1 = get_tv_number(tv1);
+ long v2 = get_tv_number(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. */
@@ -18091,6 +18101,7 @@
item_compare_ic = FALSE;
item_compare_numeric = FALSE;
+ item_compare_numbers = FALSE;
item_compare_func = NULL;
item_compare_selfdict = NULL;
if (argvars[1].v_type != VAR_UNKNOWN)
@@ -18116,6 +18127,11 @@
item_compare_func = NULL;
item_compare_numeric = TRUE;
}
+ else if (STRCMP(item_compare_func, "N") == 0)
+ {
+ item_compare_func = NULL;
+ item_compare_numbers = TRUE;
+ }
else if (STRCMP(item_compare_func, "i") == 0)
{
item_compare_func = NULL;