Citation from help: "Return the *byte count* from the start of the buffer
for line {lnum}"

Returned *byte count* is wrong. It returns character count instead of byte
count.

Your suggestion to use strchars() is too expansive - i need just get byte
count, and i need to allocate a huge string for this (say, i edit 500-Kb
file), and do split() or substitute(). This isn't good solution.


19 декабря 2011 г. 16:26 пользователь Ingo Karkat <[email protected]>написал:

> On 19-Dec-2011 13:07, Дмитрий Франк wrote:
>
> > line2byte() does not care multi-byte characters.
> >
> > For example, if my buffer has file-encoding utf-8, and there's some
> > cyrillic characters in the buffer (each cyrillic charater takes 2
> > bytes), then line2byte('.') returns wrong result (it doesn't care
> > about multi-byte characters)
>
> As stated in the help, line2byte() is about byte indexes, not character
> counts,
> like many other Vim functions (stridx(), strlen(), etc.) You have to
> convert to
> a character count yourself:
>
>    let cnt = strchars(str) " new in Vim 7.3
>    let cnt = strlen(substitute(str, '.', 'x', 'g'))
> This seems to be much faster for long strings:
>    let cnt = len(split(str, '\zs'))
>
> -- regards, ingo
>
> --
> 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 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

Raspunde prin e-mail lui