Marius Gedminas wrote:
> For the special case of UTF-8, caching could be a solution: store the
> (char_index, byte_offset) pair of the last access in the string, and
> if the next access has a small char_index difference, start looping
> from the previous byte_offset.
>
> UTF-8 is self-synchronizing: the start byte of any character has its
> MSB set to 0, so you can iterate backwards and forwards from any
> position.
Yes, this is what is done for a list, the last accessed item and its
index is remembered.
For a string it requires an extra allocation for the structure that
stores the cached values. That causes overhead when it's not used.
I wonder if we can put the cached values in a list, so that we don't
need to add a new data type. Something like:
l = [0]
c = char_forward(text, l)
" now l is [3] for a 3-byte character
Adding the character index might be useful:
l = [0, 0]
c = char_forward(text, l)
" now l is [1, 3] for a 3-byte character
Might want a function to get the character as a number and a function to
get the character as a string (which can then also include composing
characters). Although just using a string would be sufficient, there
are other functions to get the character as a number.
--
How To Keep A Healthy Level Of Insanity:
3. Every time someone asks you to do something, ask if they want fries
with that.
/// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\
/// \\\
\\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///
--
--
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 because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/202103251828.12PISBTg119229%40masaka.moolenaar.net.