Bram Moolenaar wrote:
> 
> Ben Schmidt wrote:
> 
>> Another oddity I've recently discovered is that str2nr won't accept an
>> explicitly positive number, such as '+3'.
>>
>> This is unexpected. Would you be willing to adjust the behaviour? I
>> can't think of any negative/compatibility-breaking side effects this
>> would have, but I also don't know where the vim_str2nr function is used.
>>
>> The attached patch does the job.
> 
> vim_str2nr() is used in many places, I can't quickly see the impact of
> this change.  What user facing issue are you trying to solve?  If it's
> about str2nr() itself then it's better solved in f_str2nr().

Yes, it is about str2nr() itself. Very happy to have it solved there.

The problem I was facing this time was passing the exponent part of
output from printf, which always has the form +\d\+

Your patch looks fine. It will accept, e.g., +-3 as well, but I don't
see why that's a problem. In a scripting language it's better to be more
permissive than less. It could be avoided by changing + into - before
calling vim_str2nr and then returning the negative of its return value.
But it's probably not worth it.

Ben.

> *** eval.c~   Mon Jun 23 20:25:08 2008
> --- eval.c    Mon Jun 23 21:31:49 2008
> ***************
> *** 16165,16170 ****
> --- 16165,16172 ----
>       }
>   
>       p = skipwhite(get_tv_string(&argvars[0]));
> +     if (*p == '+')
> +     p = skipwhite(p + 1);
>       vim_str2nr(p, NULL, NULL, base == 8 ? 2 : 0, base == 16 ? 2 : 0, &n, 
> NULL);
>       rettv->vval.v_number = n;
>   }
> 

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Raspunde prin e-mail lui