2015-12-06 21:50 GMT+03:00 Bram Moolenaar <[email protected]>:
>
> Jason Schulz wrote:
>
> > Since C++ (Java, Python, etc...) have support for binary literals now,
> > I'm trying to add support for a 'bin' nrformat. So far, I've been
> > able to add it to sort, increment/decrement, key parsing, and some
> > other various functions.
> >
> > I would still need to add some tests, but I was hoping to get feedback
> > on what I have so far. As it currently works it could double the
> > stack space used for ASCII numbers (30 -> sizeof(unsigned long) * 8),
> > so I thought that may be one concern.
> >
> > This 'bin' nrformat actually ties into another feature I was
> > considering (radix conversion), so any feedback is much appreciated.
>
> I don't think there is much use for binary in Vim script, but it doesn't
> hurt either.
>
> I suggest you write some documentation before tests. Then you have some
> hints about what to test.
>
> The number of arguments for vim_str2nr() is getting a bit large. It's
> probably better to turn dooct, dohex and dobin into one flag.
>
I would actually suggest to not use vim_str2nr for this feature the way it
is used now. Neovim has received the complain that some rather large
numbers cannot be incremented/decremented with `<C-a>`, and the same
problem applies to vim as well. It is better to do the following instead:
1. Merge all boolean arguments into one flag as you suggested.
2. Add an argument where pointer to the character just after the last digit
is stored (assuming it is not NULL). Basically it just needs to save one
pointer that is already being computed.
3. Add an argument where pointer to the first number of digit is stored
(assuming it is not NULL). Same thing: this pointer is already computed
inside the function.
4. Now in the caller in place of incrementing the number found in *u?nptr,
ignore it completely except for its sign. In place of incrementing the
number, copy the initial string and increment *the string* directly. E.g.
with something like
const uint8_t number_base = (hex == 0 ? 10 : hex == '0' : 8 : hex ==
'x' || hex == 'X' ? 16 : 2);
bool proceed = true;
for (char *p = number_end; proceed && p >= number_start; p--) {
int8_t digit = CHAR_TO_DIGIT(p, number_base);
digit = MODIFY(digit, subtract);
proceed = true;
if (digit == number_base) {
digit = 0;
} else if (digit == -1) {
digit = 9;
} else {
proceed = false;
}
*p = DIGIT_TO_CHAR(digit, number_type);
}
if (proceed) {
memmove(number_start + 1, number_start, (size_t) (number_end -
number_start + 1));
*number_start = '1';
}
// Note: code is here to show the idea. It really works fine only for
incrementing positive number by one, or decrementing some negative values
by one (but not all; increment/decrement that changes sign also does not
work), if I have not made mistakes.
>
> --
> hundred-and-one symptoms of being an internet addict:
> 209. Your house stinks because you haven't cleaned it in a week.
>
> /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net
> \\\
> /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/
> \\\
> \\\ an exciting new programming language -- http://www.Zimbu.org
> ///
> \\\ help me help AIDS victims -- http://ICCF-Holland.org
> ///
>
> --
> --
> You received this message from the "vim_dev" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups
> "vim_dev" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.