Wednesday, October 6, 2010

Re: Adding items'List to items'List2

Ответ на сообщение «Re: Adding items'List to items'List2»,
присланное в 00:36:50 07 октября 2010, Четверг.
Отправитель: Benjamin R. Haskell:

> I guess it's only surprising because I thought the whole point of the
> odd \r/\n behavior in s/// was to support null bytes, and didn't realize
> it was only for buffers (not for strings).
It is also for list of strings that is generated by readfile() or used by
writefile: here `\n' replaces null or is being replaced by null. Same for
getline(start,end)/setline/append.

> Upshot: 'empty(v:val)' or 'v:val == ""' is better. (Any particular
> reason to use '==#', seeing as how the case of "" doesn't matter?)
Just because I specify either `?' or `#' whenever I compare strings in order to
get independent of the 'ignorecase' option. Here it does not matter but
somewhere it does, so specifying it explicitely is in my opinion a good habit.

Текст сообщения:
> On Wed, 6 Oct 2010, ZyX wrote:
> > Ответ на сообщение <<Re: Adding items'List to items'List2>>, присланное
> > в 23:18:25 06 октября 2010, Среда. Отправитель: Benjamin R. Haskell:
> >
> > Why you are using `strlen()'? Vim neither stores string length
> > alongside with string nor recognizes when `strlen' is used in boolean
> > context, so using `empty()' or `()==#""' is better as it does not
> > require to loop over the entire string for a null byte.
>
> "Why"? = unaware that Vimscript, unlike many langs, doesn't store the
> string length. Also didn't realize that strings can't have null bytes
> (which is often what the strlen() optimization allows for in the first
>
> place):
> :echo strlen("foo\x00bar")
>
> 3
>
> :echo strlen("foo".nr2char(0)."bar")
>
> 3
>
> (( explained right above ':help literal-string' ("Note that "\000" and
> "\x00" force the end of the string"), and in ':help nr2char()' ))
>
> I guess it's only surprising because I thought the whole point of the
> odd \r/\n behavior in s/// was to support null bytes, and didn't realize
> it was only for buffers (not for strings).
>
> Upshot: 'empty(v:val)' or 'v:val == ""' is better. (Any particular
> reason to use '==#', seeing as how the case of "" doesn't matter?)

No comments: