1 | #ifndef NVIM_EVAL_ENCODE_H |
2 | #define NVIM_EVAL_ENCODE_H |
3 | |
4 | #include <stddef.h> |
5 | |
6 | #include <msgpack.h> |
7 | |
8 | #include "nvim/eval.h" |
9 | #include "nvim/garray.h" |
10 | #include "nvim/vim.h" // For STRLEN |
11 | |
12 | /// Convert VimL value to msgpack string |
13 | /// |
14 | /// @param[out] packer Packer to save results in. |
15 | /// @param[in] tv Dumped value. |
16 | /// @param[in] objname Object name, used for error message. |
17 | /// |
18 | /// @return OK in case of success, FAIL otherwise. |
19 | int encode_vim_to_msgpack(msgpack_packer *const packer, |
20 | typval_T *const tv, |
21 | const char *const objname); |
22 | |
23 | /// Convert VimL value to :echo output |
24 | /// |
25 | /// @param[out] packer Packer to save results in. |
26 | /// @param[in] tv Dumped value. |
27 | /// @param[in] objname Object name, used for error message. |
28 | /// |
29 | /// @return OK in case of success, FAIL otherwise. |
30 | int encode_vim_to_echo(garray_T *const packer, |
31 | typval_T *const tv, |
32 | const char *const objname); |
33 | |
34 | /// Structure defining state for read_from_list() |
35 | typedef struct { |
36 | const list_T *const list; ///< List being currently read. |
37 | const listitem_T *li; ///< Item currently read. |
38 | size_t offset; ///< Byte offset inside the read item. |
39 | size_t li_length; ///< Length of the string inside the read item. |
40 | } ListReaderState; |
41 | |
42 | /// Initialize ListReaderState structure |
43 | static inline ListReaderState encode_init_lrstate(const list_T *const list) |
44 | FUNC_ATTR_NONNULL_ALL |
45 | { |
46 | return (ListReaderState) { |
47 | .list = list, |
48 | .li = tv_list_first(list), |
49 | .offset = 0, |
50 | .li_length = (TV_LIST_ITEM_TV(tv_list_first(list))->vval.v_string == NULL |
51 | ? 0 |
52 | : STRLEN(TV_LIST_ITEM_TV( |
53 | tv_list_first(list))->vval.v_string)), |
54 | }; |
55 | } |
56 | |
57 | /// Array mapping values from SpecialVarValue enum to names |
58 | extern const char *const encode_special_var_names[]; |
59 | |
60 | /// First codepoint in high surrogates block |
61 | #define SURROGATE_HI_START 0xD800 |
62 | |
63 | /// Last codepoint in high surrogates block |
64 | #define SURROGATE_HI_END 0xDBFF |
65 | |
66 | /// First codepoint in low surrogates block |
67 | #define SURROGATE_LO_START 0xDC00 |
68 | |
69 | /// Last codepoint in low surrogates block |
70 | #define SURROGATE_LO_END 0xDFFF |
71 | |
72 | /// First character that needs to be encoded as surrogate pair |
73 | #define SURROGATE_FIRST_CHAR 0x10000 |
74 | |
75 | #ifdef INCLUDE_GENERATED_DECLARATIONS |
76 | # include "eval/encode.h.generated.h" |
77 | #endif |
78 | #endif // NVIM_EVAL_ENCODE_H |
79 | |