Tuesday, March 8, 2016

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

2016-03-08 12:23 GMT+03:00 rameo <raiwil@gmail.com>:
> Can't find anything on the net about string.encode(vim.options[encoding]).
> No info either in Vim documentation: if_pyth
>
> Let say I create my list "MyPositions" with start/end position of matches using searchpos() in vim.
>
> Then in my python code I have to do something like this to convert it to byte strings:
>
> python3 << endpython
> import vim
> myposPyth = str(vim.eval("MyPositions"))
> myposPyth = myposPyth.encode(vim.options['utf8'])
>
> ?
> I still don't get it.
> (btw above returns a key-error)

You do not understand what you are doing. `string` in my code means
*string* to which positions apply, not *position*. And not even
stringified position. To convert byte offsets into character ones you
would need to get string to which position applies, convert it to a
byte string, slice it using found positions, convert the slice back to
unicode string and find its length.

And I explicitly written `vim.options['encoding']`, where on Earth
have you seen `vim.options['utf8']`?

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