diff options
author | Bram Moolenaar <Bram@vim.org> | 2016-01-02 17:56:35 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2016-01-02 17:56:35 +0100 |
commit | 887c1fea4a114e7170091942d0446c8882701b5b (patch) | |
tree | 23173526918b54763e5eed1b26a7bdad3ac7884a /src/ex_cmds.c | |
parent | acf92d27c94811e3bd6b84cfd54246e91d44c355 (diff) |
patch 7.4.1027v7.4.1027
Problem: No support for binary numbers.
Solution: Add "bin" to nrformats. (Jason Schulz)
Diffstat (limited to 'src/ex_cmds.c')
-rw-r--r-- | src/ex_cmds.c | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/src/ex_cmds.c b/src/ex_cmds.c index 9da5c0956e..1d0a3856c5 100644 --- 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 |