diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-10-29 02:13:12 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-10-29 02:13:12 +0200 |
commit | 7b0ceb3726e6d331625d5754be534e28a7f6092a (patch) | |
tree | 2edc27166a5034c1fe4d670769dac2076c30cf7e /src/nvim/api/private/helpers.c | |
parent | 122f52bf897abd1cda4fa467157657fee6bcfe94 (diff) | |
parent | 1a93f5883105c304d496d6c2e841626ebb7d44c1 (diff) | |
download | rneovim-7b0ceb3726e6d331625d5754be534e28a7f6092a.tar.gz rneovim-7b0ceb3726e6d331625d5754be534e28a7f6092a.tar.bz2 rneovim-7b0ceb3726e6d331625d5754be534e28a7f6092a.zip |
Merge #7173 'api/ui: externalize cmdline'
closes #6162
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r-- | src/nvim/api/private/helpers.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index e736e29e2d..2944925a9c 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -667,6 +667,22 @@ tabpage_T *find_tab_by_handle(Tabpage tabpage, Error *err) return rv; } +/// Allocates a String consisting of a single char. Does not support multibyte +/// characters. The resulting string is also NUL-terminated, to facilitate +/// interoperating with code using C strings. +/// +/// @param char the char to convert +/// @return the resulting String, if the input char was NUL, an +/// empty String is returned +String cchar_to_string(char c) +{ + char buf[] = { c, NUL }; + return (String) { + .data = xmemdupz(buf, 1), + .size = (c != NUL) ? 1 : 0 + }; +} + /// Copies a C string into a String (binary safe string, characters + length). /// The resulting string is also NUL-terminated, to facilitate interoperating /// with code using C strings. @@ -687,6 +703,23 @@ String cstr_to_string(const char *str) }; } +/// Copies buffer to an allocated String. +/// The resulting string is also NUL-terminated, to facilitate interoperating +/// with code using C strings. +/// +/// @param buf the buffer to copy +/// @param size length of the buffer +/// @return the resulting String, if the input string was NULL, an +/// empty String is returned +String cbuf_to_string(const char *buf, size_t size) + FUNC_ATTR_NONNULL_ALL +{ + return (String) { + .data = xmemdupz(buf, size), + .size = size + }; +} + /// Creates a String using the given C string. Unlike /// cstr_to_string this function DOES NOT copy the C string. /// |