]> granicus.if.org Git - vim/commitdiff
updated for version 7.4.341 v7.4.341
authorBram Moolenaar <Bram@vim.org>
Wed, 25 Jun 2014 15:31:09 +0000 (17:31 +0200)
committerBram Moolenaar <Bram@vim.org>
Wed, 25 Jun 2014 15:31:09 +0000 (17:31 +0200)
Problem:    sort() doesn't handle numbers well.
Solution:   Add an argument to specify sorting on numbers. (Christian Brabandt)

src/eval.c
src/testdir/test55.in
src/testdir/test55.ok
src/version.c

index 31f5c91873f7d8378c561f163b63b348c03a9cb4..2aa4e5407ad3b96a86c098329e4aff19bc7f8168 100644 (file)
@@ -17330,6 +17330,7 @@ static int
        item_compare2 __ARGS((const void *s1, const void *s2));
 
 static int     item_compare_ic;
+static int     item_compare_numeric;
 static char_u  *item_compare_func;
 static dict_T  *item_compare_selfdict;
 static int     item_compare_func_err;
@@ -17359,10 +17360,20 @@ item_compare(s1, s2)
        p1 = (char_u *)"";
     if (p2 == NULL)
        p2 = (char_u *)"";
-    if (item_compare_ic)
-       res = STRICMP(p1, p2);
+    if (!item_compare_numeric)
+    {
+       if (item_compare_ic)
+           res = STRICMP(p1, p2);
+       else
+           res = STRCMP(p1, p2);
+    }
     else
-       res = STRCMP(p1, p2);
+    {
+       double n1, n2;
+       n1 = strtod((char *)p1, (char **)&p1);
+       n2 = strtod((char *)p2, (char **)&p2);
+       res = n1 == n2 ? 0 : n1 > n2 ? 1 : -1;
+    }
     vim_free(tofree1);
     vim_free(tofree2);
     return res;
@@ -17439,6 +17450,7 @@ do_sort_uniq(argvars, rettv, sort)
            return;     /* short list sorts pretty quickly */
 
        item_compare_ic = FALSE;
+       item_compare_numeric = FALSE;
        item_compare_func = NULL;
        item_compare_selfdict = NULL;
        if (argvars[1].v_type != VAR_UNKNOWN)
@@ -17457,6 +17469,19 @@ do_sort_uniq(argvars, rettv, sort)
                    item_compare_ic = TRUE;
                else
                    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)
index 85a8063774d143b1b552ce5824cd1816f4b42ce2..f12dc2d22fb40baf361bbdb005dfaa5fad15c2b6 100644 (file)
@@ -332,6 +332,11 @@ let l = [0, 1, 2, 3]
 :$put =string(reverse(sort(l)))
 :$put =string(sort(reverse(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
 :$put =string(split('  aa  bb '))
index be476e8e939ef0ca0f3cc2f41dd7b4e7276a99d0..901bc94066315986d35b4677cb7d08fdb5001bd3 100644 (file)
@@ -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', '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]]
+[-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', '']
index 4b4f826f371798e8a39e07856b96bb80168fafe2..d6c1eb3a002dd8a292c3e9faac6ee52de5fab07c 100644 (file)
@@ -734,6 +734,8 @@ static char *(features[]) =
 
 static int included_patches[] =
 {   /* Add new patch number below this line */
+/**/
+    341,
 /**/
     340,
 /**/