Mercurial > vim
diff src/ex_cmds.c @ 7447:ad432f8f68fb v7.4.1027
commit https://github.com/vim/vim/commit/887c1fea4a114e7170091942d0446c8882701b5b
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 2 17:56:35 2016 +0100
patch 7.4.1027
Problem: No support for binary numbers.
Solution: Add "bin" to nrformats. (Jason Schulz)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sat, 02 Jan 2016 18:00:05 +0100 |
parents | bc5de65e499a |
children | 1fded31d9e04 |
line wrap: on
line diff
--- a/src/ex_cmds.c +++ b/src/ex_cmds.c @@ -365,8 +365,8 @@ ex_sort(eap) long deleted; colnr_T start_col; colnr_T end_col; - int sort_oct; /* sort on octal number */ - int sort_hex; /* sort on hex number */ + int sort_what = 0; + int format_found = 0; /* Sorting one line is really quick! */ if (count <= 1) @@ -381,7 +381,7 @@ ex_sort(eap) if (nrs == NULL) goto sortend; - sort_abort = sort_ic = sort_rx = sort_nr = sort_oct = sort_hex = 0; + sort_abort = sort_ic = sort_rx = sort_nr = 0; for (p = eap->arg; *p != NUL; ++p) { @@ -392,11 +392,25 @@ ex_sort(eap) else if (*p == 'r') sort_rx = TRUE; else if (*p == 'n') + { sort_nr = 2; + ++format_found; + } + else if (*p == 'b') + { + sort_what = STR2NR_BIN + STR2NR_FORCE; + ++format_found; + } else if (*p == 'o') - sort_oct = 2; + { + sort_what = STR2NR_OCT + STR2NR_FORCE; + ++format_found; + } else if (*p == 'x') - sort_hex = 2; + { + sort_what = STR2NR_HEX + STR2NR_FORCE; + ++format_found; + } else if (*p == 'u') unique = TRUE; else if (*p == '"') /* comment start */ @@ -439,15 +453,15 @@ ex_sort(eap) } } - /* Can only have one of 'n', 'o' and 'x'. */ - if (sort_nr + sort_oct + sort_hex > 2) + /* Can only have one of 'n', 'b', 'o' and 'x'. */ + if (format_found > 1) { EMSG(_(e_invarg)); goto sortend; } /* From here on "sort_nr" is used as a flag for any number sorting. */ - sort_nr += sort_oct + sort_hex; + sort_nr += sort_what; /* * Make an array with all line numbers. This avoids having to copy all @@ -489,8 +503,10 @@ ex_sort(eap) *s2 = NUL; /* Sorting on number: Store the number itself. */ p = s + start_col; - if (sort_hex) + if (sort_what & STR2NR_HEX) s = skiptohex(p); + else if (sort_what & STR2NR_BIN) + s = skiptobin(p); else s = skiptodigit(p); if (s > p && s[-1] == '-') @@ -499,8 +515,8 @@ ex_sort(eap) /* empty line should sort before any number */ nrs[lnum - eap->line1].start_col_nr = -MAXLNUM; else - vim_str2nr(s, NULL, NULL, sort_oct, sort_hex, - &nrs[lnum - eap->line1].start_col_nr, NULL, 0); + vim_str2nr(s, NULL, NULL, sort_what, + &nrs[lnum - eap->line1].start_col_nr, NULL, 0); *s2 = c; } else