Monday, March 7, 2016

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

2016-03-08 1:32 GMT+03:00 rameo <raiwil@gmail.com>:
>
>> In Python you are not using *byte* counts, it indexes *unicode
>> codepoints*. You may convert unicode Python objects to bytes objects
>> by using `string.encode(vim.options['encoding'])`, use
>> `.decode(vim.options['encoding'])` to convert back. bytes objects are
>> indexed by bytes. You may also count codepoints on Vim side by using
>> `strchars()`.
>>
>
> Thank you ZyX, Can you please tell me where to put string.encode(vim.options['encoding'])? Before searchpos()? And decode(vim.options['encoding'])after searchpos()?

When using byte indexes you use them on encoded unicode string in
Python. Decoding is needed to convert byte strings (which are rather
inconvenient to use in Python 3) back to unicode strings when you are
done working with indexes. I cannot say anything more because it is
your code.

>
> --
> --
> 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:

Post a Comment