From d8beb77b1b84fc9e40993af9610f0c4e9ddc9571 Mon Sep 17 00:00:00 2001 From: Rui Abreu Ferreira Date: Tue, 8 Jul 2014 17:05:30 +0100 Subject: Add helper cstr_as_string() - Add nocopy helper alternative to cstr_to_string --- src/nvim/api/private/helpers.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src') diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 354a74d19a..f6fb46e1d1 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -343,6 +343,20 @@ String cstr_to_string(const char *str) }; } +/// Creates a String using the given C string. Unlike +/// cstr_to_string this function DOES NOT copy the C string. +/// +/// @param str the C string to use +/// @return The resulting String, or an empty String if +/// str was NULL +String cstr_as_string(char *str) FUNC_ATTR_PURE +{ + if (str == NULL) { + return (String) STRING_INIT; + } + return (String) {.data = str, .size = strlen(str)}; +} + bool object_to_vim(Object obj, typval_T *tv, Error *err) { tv->v_type = VAR_UNKNOWN; -- cgit