diff options
author | bfredl <bjorn.linse@gmail.com> | 2024-02-18 18:04:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-02-18 18:04:28 +0100 |
commit | 93c911e52feadff72003f7e78257c00c3bbf1570 (patch) | |
tree | ff0e65d868b9e30ec4759f13e3c3809f8fd41697 /src/nvim/message.c | |
parent | d94adff48b1882f9078b0ae94b677be5d29e5fd2 (diff) | |
parent | 97531be1f766e6cad79e6360ae9cb827434cff3c (diff) | |
download | rneovim-93c911e52feadff72003f7e78257c00c3bbf1570.tar.gz rneovim-93c911e52feadff72003f7e78257c00c3bbf1570.tar.bz2 rneovim-93c911e52feadff72003f7e78257c00c3bbf1570.zip |
Merge pull request #27511 from bfredl/maparena
refactor(api): use arena for mappings, autocmd, channel info
Diffstat (limited to 'src/nvim/message.c')
-rw-r--r-- | src/nvim/message.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/nvim/message.c b/src/nvim/message.c index b4e1d61cc7..175e3b5d03 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -1713,6 +1713,39 @@ char *str2special_save(const char *const str, const bool replace_spaces, const b return (char *)ga.ga_data; } +/// Convert string, replacing key codes with printables +/// +/// Used for lhs or rhs of mappings. +/// +/// @param[in] str String to convert. +/// @param[in] replace_spaces Convert spaces into `<Space>`, normally used for +/// lhs of mapping and keytrans(), but not rhs. +/// @param[in] replace_lt Convert `<` into `<lt>`. +/// +/// @return [allocated] Converted string. +char *str2special_arena(const char *str, bool replace_spaces, bool replace_lt, Arena *arena) + FUNC_ATTR_NONNULL_ALL FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_MALLOC + FUNC_ATTR_NONNULL_RET +{ + const char *p = str; + size_t len = 0; + while (*p) { + len += strlen(str2special(&p, replace_spaces, replace_lt)); + } + + char *buf = arena_alloc(arena, len + 1, false); + size_t pos = 0; + p = str; + while (*p) { + const char *s = str2special(&p, replace_spaces, replace_lt); + size_t s_len = strlen(s); + memcpy(buf + pos, s, s_len); + pos += s_len; + } + buf[pos] = NUL; + return buf; +} + /// Convert character, replacing key with printable representation. /// /// @param[in,out] sp String to convert. Is advanced to the next key code. |