Tuesday, March 8, 2016

Re: Is there any way to count all latin characters in utf-8 as 1 byte?

2016-03-08 13:22 GMT+03:00 rameo <raiwil@gmail.com>:
> Thank you.
> You're right. It is not a question of decoding a list but decoding a string. Never did anything before with string encoding. I've got it: I cannot use searchpos() to use with python. Searching positions must be done in python (p.e. finditer).

You can use searchpos() with Python. Searchpos searches strings in
buffer which *is* accessible through Python, vim.current.buffer[linenr
- 1] or vim.buffers[bufnr][linenr - 1]. Line numbers are returned by
searchpos.

When using Python-3 though prepare that `vim.current.buffer[linenr -
1]` may yield UnicodeDecodeError: because buffer is not guaranteed to
contain only valid &encoding strings. Using
`vim.bindeval('getline(%u)' % linenr)` you may get byte string without
encoding anything and thus without errors.

>
> BTW I thought that ['encoding'] was a placeholder for utf8/latin1.
>
> --
> --
> You received this message from the "vim_use" 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_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" 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_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: