From 49e893f296bca9eef5ff45a3d746c261d055bf10 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/strings.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 16691d0ded..423436eccc 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -59,15 +59,6 @@ char_u *vim_strsave(const char_u *string) /// Copy up to `len` bytes of `string` into newly allocated memory and /// terminate with a NUL. The allocated memory always has size `len + 1`, even /// when `string` is shorter. -char_u *vim_strnsave(const char_u *string, size_t len) - FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL -{ - // strncpy is intentional: some parts of Vim use `string` shorter than `len` - // and expect the remainder to be zeroed out. - return (char_u *)strncpy(xmallocz(len), (char *)string, len); -} - -/// A clone of vim_strnsave() that uses char* instead of char_u* char *xstrnsave(const char *string, size_t len) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { @@ -318,15 +309,13 @@ char_u *vim_strsave_up(const char_u *string) return p1; } -/* - * Like vim_strnsave(), but make all characters uppercase. - * This uses ASCII lower-to-upper case translation, language independent. - */ -char_u *vim_strnsave_up(const char_u *string, size_t len) +/// Like xstrnsave(), but make all characters uppercase. +/// This uses ASCII lower-to-upper case translation, language independent. +char *vim_strnsave_up(const char *string, size_t len) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { - char_u *p1 = vim_strnsave(string, len); - vim_strup(p1); + char *p1 = xstrnsave(string, len); + vim_strup((char_u *)p1); return p1; } -- cgit From 1ffd527c837fb2465c9659273bbe5447a1352db2 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Fri, 2 Sep 2022 17:39:49 +0100 Subject: refactor: migrate comment style (#20012) Done automatically using the following perl command: perl -pi -0777pe 's#\n\K */\*\n(.+?)\s*\*/\n#join("\n", map { $_ =~ s:^\s*\K \*://:; $_ } split("\n", $1)) . "\n"#sge' src/nvim/**/*.c Co-authored-by: zeertzjq Co-authored-by: zeertzjq --- src/nvim/strings.c | 78 ++++++++++++++++++++---------------------------------- 1 file changed, 28 insertions(+), 50 deletions(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 423436eccc..12bfa35dd6 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -65,28 +65,22 @@ char *xstrnsave(const char *string, size_t len) return strncpy(xmallocz(len), string, len); // NOLINT(runtime/printf) } -/* - * Same as vim_strsave(), but any characters found in esc_chars are preceded - * by a backslash. - */ +// Same as vim_strsave(), but any characters found in esc_chars are preceded +// by a backslash. char_u *vim_strsave_escaped(const char_u *string, const char_u *esc_chars) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { return vim_strsave_escaped_ext(string, esc_chars, '\\', false); } -/* - * Same as vim_strsave_escaped(), but when "bsl" is true also escape - * characters where rem_backslash() would remove the backslash. - * Escape the characters with "cc". - */ +// Same as vim_strsave_escaped(), but when "bsl" is true also escape +// characters where rem_backslash() would remove the backslash. +// Escape the characters with "cc". char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars, char_u cc, bool bsl) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { - /* - * First count the number of backslashes required. - * Then allocate the memory and insert them. - */ + // First count the number of backslashes required. + // Then allocate the memory and insert them. size_t length = 1; // count the trailing NUL for (const char_u *p = string; *p; p++) { const size_t l = (size_t)(utfc_ptr2len((char *)p)); @@ -169,16 +163,14 @@ char *vim_strnsave_unquoted(const char *const string, const size_t length) return ret; } -/* - * Escape "string" for use as a shell argument with system(). - * This uses single quotes, except when we know we need to use double quotes - * (MS-Windows without 'shellslash' set). - * Escape a newline, depending on the 'shell' option. - * When "do_special" is true also replace "!", "%", "#" and things starting - * with "<" like "". - * When "do_newline" is false do not escape newline unless it is csh shell. - * Returns the result in allocated memory. - */ +// Escape "string" for use as a shell argument with system(). +// This uses single quotes, except when we know we need to use double quotes +// (MS-Windows without 'shellslash' set). +// Escape a newline, depending on the 'shell' option. +// When "do_special" is true also replace "!", "%", "#" and things starting +// with "<" like "". +// When "do_newline" is false do not escape newline unless it is csh shell. +// Returns the result in allocated memory. char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_newline) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { @@ -295,10 +287,8 @@ char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_n return escaped_string; } -/* - * Like vim_strsave(), but make all characters uppercase. - * This uses ASCII lower-to-upper case translation, language independent. - */ +// Like vim_strsave(), but make all characters uppercase. +// This uses ASCII lower-to-upper case translation, language independent. char_u *vim_strsave_up(const char_u *string) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { @@ -319,9 +309,7 @@ char *vim_strnsave_up(const char *string, size_t len) return p1; } -/* - * ASCII lower-to-upper case translation, language independent. - */ +// ASCII lower-to-upper case translation, language independent. void vim_strup(char_u *p) FUNC_ATTR_NONNULL_ALL { @@ -375,9 +363,7 @@ char *strcase_save(const char *const orig, bool upper) return res; } -/* - * delete spaces at the end of a string - */ +// delete spaces at the end of a string void del_trailing_spaces(char_u *ptr) FUNC_ATTR_NONNULL_ALL { @@ -402,11 +388,9 @@ size_t xstrnlen(const char *s, size_t n) #endif #if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) -/* - * Compare two strings, ignoring case, using current locale. - * Doesn't work for multi-byte characters. - * return 0 for match, < 0 for smaller, > 0 for bigger - */ +// Compare two strings, ignoring case, using current locale. +// Doesn't work for multi-byte characters. +// return 0 for match, < 0 for smaller, > 0 for bigger int vim_stricmp(const char *s1, const char *s2) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE { @@ -428,11 +412,9 @@ int vim_stricmp(const char *s1, const char *s2) #endif #if (!defined(HAVE_STRNCASECMP) && !defined(HAVE_STRNICMP)) -/* - * Compare two strings, for length "len", ignoring case, using current locale. - * Doesn't work for multi-byte characters. - * return 0 for match, < 0 for smaller, > 0 for bigger - */ +// Compare two strings, for length "len", ignoring case, using current locale. +// Doesn't work for multi-byte characters. +// return 0 for match, < 0 for smaller, > 0 for bigger int vim_strnicmp(const char *s1, const char *s2, size_t len) FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE { @@ -477,9 +459,7 @@ char *vim_strchr(const char *const string, const int c) } } -/* - * Sort an array of strings. - */ +// Sort an array of strings. #ifdef INCLUDE_GENERATED_DECLARATIONS # include "strings.c.generated.h" @@ -495,10 +475,8 @@ void sort_strings(char **files, int count) qsort((void *)files, (size_t)count, sizeof(char *), sort_compare); } -/* - * Return true if string "s" contains a non-ASCII character (128 or higher). - * When "s" is NULL false is returned. - */ +// Return true if string "s" contains a non-ASCII character (128 or higher). +// When "s" is NULL false is returned. bool has_non_ascii(const char_u *s) FUNC_ATTR_PURE { -- cgit From 12afc344deb2df3973904fe55813d700da985dbf Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 6 Sep 2022 16:23:00 +0200 Subject: refactor: migrate comment style 2 #20080 --- src/nvim/strings.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 12bfa35dd6..d7a0472cbf 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -180,10 +180,10 @@ char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_n int csh_like; bool fish_like; - /* Only csh and similar shells expand '!' within single quotes. For sh and - * the like we must not put a backslash before it, it will be taken - * literally. If do_special is set the '!' will be escaped twice. - * Csh also needs to have "\n" escaped twice when do_special is set. */ + // Only csh and similar shells expand '!' within single quotes. For sh and + // the like we must not put a backslash before it, it will be taken + // literally. If do_special is set the '!' will be escaped twice. + // Csh also needs to have "\n" escaped twice when do_special is set. csh_like = csh_like_shell(); // Fish shell uses '\' as an escape character within single quotes, so '\' -- cgit From 73207cae611a1efb8cd17139e8228772daeb9866 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/strings.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index d7a0472cbf..04f9311d7e 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -49,13 +49,6 @@ #include "nvim/vim.h" #include "nvim/window.h" -/// Copy "string" into newly allocated memory. -char_u *vim_strsave(const char_u *string) - FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL -{ - return (char_u *)xstrdup((char *)string); -} - /// Copy up to `len` bytes of `string` into newly allocated memory and /// terminate with a NUL. The allocated memory always has size `len + 1`, even /// when `string` is shorter. @@ -292,11 +285,11 @@ char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_n char_u *vim_strsave_up(const char_u *string) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { - char_u *p1; + char *p1; - p1 = vim_strsave(string); - vim_strup(p1); - return p1; + p1 = xstrdup((char *)string); + vim_strup((char_u *)p1); + return (char_u *)p1; } /// Like xstrnsave(), but make all characters uppercase. -- cgit From c5322e752e9e568de907f7a1ef733bbfe342140c Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/strings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 04f9311d7e..ee6172e7fc 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -460,7 +460,7 @@ char *vim_strchr(const char *const string, const int c) static int sort_compare(const void *s1, const void *s2) FUNC_ATTR_NONNULL_ALL { - return STRCMP(*(char **)s1, *(char **)s2); + return strcmp(*(char **)s1, *(char **)s2); } void sort_strings(char **files, int count) -- cgit From 3ff46544c9872b4161fd098569c30b55fe3abd36 Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/strings.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index ee6172e7fc..b73221d4da 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -341,7 +341,7 @@ char *strcase_save(const char *const orig, bool upper) int newl = utf_char2len(uc); if (newl != l) { // TODO(philix): use xrealloc() in strcase_save() - char *s = xmalloc(STRLEN(res) + (size_t)(1 + newl - l)); + char *s = xmalloc(strlen(res) + (size_t)(1 + newl - l)); memcpy(s, res, (size_t)(p - res)); STRCPY(s + (p - res) + newl, p + l); p = s + (p - res); @@ -504,8 +504,8 @@ bool has_non_ascii_len(const char *const s, const size_t len) char *concat_str(const char *restrict str1, const char *restrict str2) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { - size_t l = STRLEN(str1); - char *dest = xmalloc(l + STRLEN(str2) + 1); + size_t l = strlen(str1); + char *dest = xmalloc(l + strlen(str2) + 1); STRCPY(dest, str1); STRCPY(dest + l, str2); return dest; @@ -1473,7 +1473,7 @@ char *reverse_text(char *s) FUNC_ATTR_NONNULL_RET { // Reverse the pattern. - size_t len = STRLEN(s); + size_t len = strlen(s); char *rev = xmalloc(len + 1); size_t rev_i = len; for (size_t s_i = 0; s_i < len; s_i++) { @@ -1498,7 +1498,7 @@ char *reverse_text(char *s) char *strrep(const char *src, const char *what, const char *rep) { char *pos = (char *)src; - size_t whatlen = STRLEN(what); + size_t whatlen = strlen(what); // Count occurrences size_t count = 0; @@ -1511,8 +1511,8 @@ char *strrep(const char *src, const char *what, const char *rep) return NULL; } - size_t replen = STRLEN(rep); - char *ret = xmalloc(STRLEN(src) + count * (replen - whatlen) + 1); + size_t replen = strlen(rep); + char *ret = xmalloc(strlen(src) + count * (replen - whatlen) + 1); char *ptr = ret; while ((pos = strstr(src, what)) != NULL) { size_t idx = (size_t)(pos - src); -- cgit From 6d557e324fd4223fff3279a0112f40431c540163 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 18 Sep 2022 03:17:15 +0200 Subject: vim-patch:8.1.0941: macros for MS-Windows are inconsistent (#20215) Problem: Macros for MS-Windows are inconsistent, using "32", "3264 and others. Solution: Use MSWIN for all MS-Windows builds. Use FEAT_GUI_MSWIN for the GUI build. (Hirohito Higashi, closes vim/vim#3932) https://github.com/vim/vim/commit/4f97475d326c2773a78561fb874e4f23c25cbcd9 --- src/nvim/strings.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index b73221d4da..10173fac1d 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -186,7 +186,7 @@ char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_n // First count the number of extra bytes required. size_t length = STRLEN(string) + 3; // two quotes and a trailing NUL for (const char_u *p = string; *p != NUL; MB_PTR_ADV(p)) { -#ifdef WIN32 +#ifdef MSWIN if (!p_ssl) { if (*p == '"') { length++; // " -> "" @@ -217,7 +217,7 @@ char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_n d = (char *)escaped_string; // add opening quote -#ifdef WIN32 +#ifdef MSWIN if (!p_ssl) { *d++ = '"'; } else @@ -225,7 +225,7 @@ char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_n *d++ = '\''; for (const char *p = (char *)string; *p != NUL;) { -#ifdef WIN32 +#ifdef MSWIN if (!p_ssl) { if (*p == '"') { *d++ = '"'; @@ -269,7 +269,7 @@ char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_n } // add terminating quote and finish with a NUL -#ifdef WIN32 +#ifdef MSWIN if (!p_ssl) { *d++ = '"'; } else -- cgit From b05d1943f063c382ea96b76d250877bc58297314 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 1 Nov 2022 15:39:49 +0100 Subject: build(lint): remove clint.py rules for braces #20880 Uncrustify is the source of truth where possible. Remove any redundant checks from clint.py. See also https://github.com/neovim/neovim/pull/18563 --- src/nvim/strings.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 10173fac1d..4d1401293b 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -1041,7 +1041,7 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, t break; } if (arg > 0) { - arg_sign = 1; + arg_sign = 1; } else if (arg < 0) { arg_sign = -1; } -- cgit From 731cdde28ea8d48cc23ba2752a08c261c87eee92 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sat, 22 Oct 2022 12:36:38 +0200 Subject: refactor: fix clang-tidy warnings Enable and fix bugprone-misplaced-widening-cast warning. Fix some modernize-macro-to-enum and readability-else-after-return warnings, but don't enable them. While the warnings can be useful, they are in general too noisy to enable. --- src/nvim/strings.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 4d1401293b..806e1eb5ec 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -604,10 +604,9 @@ static const void *tv_ptr(const typval_T *const tvs, int *const idxp) if (tvs[idx].v_type == VAR_UNKNOWN) { emsg(_(e_printf)); return NULL; - } else { - (*idxp)++; - return tvs[idx].vval.v_string; } + (*idxp)++; + return tvs[idx].vval.v_string; } /// Get float argument from idxp entry in tvs -- cgit From bdb98de2d16ce7185a0f53740e06511904fdd814 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 7 Nov 2022 10:21:44 +0000 Subject: refactor: more clint (#20910) --- src/nvim/strings.c | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 4d1401293b..7086f47e33 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -1035,9 +1035,7 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, t : va_arg(ap, long long)); // NOLINT (runtime/int) break; case 'z': - arg = (tvs - ? (ptrdiff_t)tv_nr(tvs, &arg_idx) - : va_arg(ap, ptrdiff_t)); + arg = (tvs ? (ptrdiff_t)tv_nr(tvs, &arg_idx) : va_arg(ap, ptrdiff_t)); break; } if (arg > 0) { @@ -1049,19 +1047,13 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, t // unsigned switch (length_modifier) { case '\0': - uarg = (unsigned int)(tvs - ? tv_nr(tvs, &arg_idx) - : va_arg(ap, unsigned int)); + uarg = (unsigned int)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, unsigned int)); break; case 'h': - uarg = (uint16_t)(tvs - ? tv_nr(tvs, &arg_idx) - : va_arg(ap, unsigned int)); + uarg = (uint16_t)(tvs ? tv_nr(tvs, &arg_idx) : va_arg(ap, unsigned int)); break; case 'l': - uarg = (tvs - ? (unsigned long)tv_nr(tvs, &arg_idx) - : va_arg(ap, unsigned long)); + uarg = (tvs ? (unsigned long)tv_nr(tvs, &arg_idx) : va_arg(ap, unsigned long)); break; case '2': uarg = (uintmax_t)(unsigned long long)( // NOLINT (runtime/int) @@ -1071,9 +1063,7 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, t : va_arg(ap, unsigned long long)); // NOLINT (runtime/int) break; case 'z': - uarg = (tvs - ? (size_t)tv_nr(tvs, &arg_idx) - : va_arg(ap, size_t)); + uarg = (tvs ? (size_t)tv_nr(tvs, &arg_idx) : va_arg(ap, size_t)); break; } arg_sign = (uarg != 0); -- cgit From 66360675cf4d091b7460e4a8e1435c13216c1929 Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 11 Sep 2022 17:12:44 +0200 Subject: build: allow IWYU to fix includes for all .c files Allow Include What You Use to remove unnecessary includes and only include what is necessary. This helps with reducing compilation times and makes it easier to visualise which dependencies are actually required. Work on https://github.com/neovim/neovim/issues/549, but doesn't close it since this only works fully for .c files and not headers. --- src/nvim/strings.c | 37 +++++++++---------------------------- 1 file changed, 9 insertions(+), 28 deletions(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index dc48273c8e..7fdcaaa355 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -6,48 +6,29 @@ #include #include #include +#include +#include +#include #include +#include "auto/config.h" #include "nvim/ascii.h" #include "nvim/assert.h" -#include "nvim/buffer.h" #include "nvim/charset.h" -#include "nvim/diff.h" -#include "nvim/edit.h" -#include "nvim/eval.h" #include "nvim/eval/encode.h" -#include "nvim/ex_cmds.h" +#include "nvim/eval/typval.h" +#include "nvim/eval/typval_defs.h" #include "nvim/ex_docmd.h" -#include "nvim/ex_getln.h" -#include "nvim/file_search.h" -#include "nvim/fileio.h" -#include "nvim/fold.h" -#include "nvim/func_attr.h" -#include "nvim/getchar.h" -#include "nvim/mark.h" +#include "nvim/gettext.h" +#include "nvim/macros.h" #include "nvim/math.h" #include "nvim/mbyte.h" -#include "nvim/memfile.h" -#include "nvim/memline.h" #include "nvim/memory.h" #include "nvim/message.h" -#include "nvim/move.h" -#include "nvim/ops.h" #include "nvim/option.h" -#include "nvim/os/os.h" -#include "nvim/os/shell.h" -#include "nvim/os_unix.h" -#include "nvim/path.h" -#include "nvim/quickfix.h" -#include "nvim/regexp.h" -#include "nvim/screen.h" -#include "nvim/search.h" -#include "nvim/spell.h" #include "nvim/strings.h" -#include "nvim/syntax.h" -#include "nvim/tag.h" +#include "nvim/types.h" #include "nvim/vim.h" -#include "nvim/window.h" /// Copy up to `len` bytes of `string` into newly allocated memory and /// terminate with a NUL. The allocated memory always has size `len + 1`, even -- cgit From bd22585061b66d7f71d4832b4a81e950b3c9d19d Mon Sep 17 00:00:00 2001 From: Dundar Göc Date: Fri, 26 Aug 2022 23:11:25 +0200 Subject: refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/strings.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index 7fdcaaa355..cfe821715c 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -137,15 +137,16 @@ char *vim_strnsave_unquoted(const char *const string, const size_t length) return ret; } -// Escape "string" for use as a shell argument with system(). -// This uses single quotes, except when we know we need to use double quotes -// (MS-Windows without 'shellslash' set). -// Escape a newline, depending on the 'shell' option. -// When "do_special" is true also replace "!", "%", "#" and things starting -// with "<" like "". -// When "do_newline" is false do not escape newline unless it is csh shell. -// Returns the result in allocated memory. -char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_newline) +/// Escape "string" for use as a shell argument with system(). +/// This uses single quotes, except when we know we need to use double quotes +/// (MS-Windows without 'shellslash' set). +/// Escape a newline, depending on the 'shell' option. +/// When "do_special" is true also replace "!", "%", "#" and things starting +/// with "<" like "". +/// When "do_newline" is false do not escape newline unless it is csh shell. +/// +/// @return the result in allocated memory. +char *vim_strsave_shellescape(const char *string, bool do_special, bool do_newline) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { char *d; @@ -165,8 +166,8 @@ char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_n fish_like = fish_like_shell(); // First count the number of extra bytes required. - size_t length = STRLEN(string) + 3; // two quotes and a trailing NUL - for (const char_u *p = string; *p != NUL; MB_PTR_ADV(p)) { + size_t length = strlen(string) + 3; // two quotes and a trailing NUL + for (const char_u *p = (char_u *)string; *p != NUL; MB_PTR_ADV(p)) { #ifdef MSWIN if (!p_ssl) { if (*p == '"') { @@ -258,7 +259,7 @@ char_u *vim_strsave_shellescape(const char_u *string, bool do_special, bool do_n *d++ = '\''; *d = NUL; - return escaped_string; + return (char *)escaped_string; } // Like vim_strsave(), but make all characters uppercase. @@ -338,12 +339,12 @@ char *strcase_save(const char *const orig, bool upper) } // delete spaces at the end of a string -void del_trailing_spaces(char_u *ptr) +void del_trailing_spaces(char *ptr) FUNC_ATTR_NONNULL_ALL { - char_u *q; + char *q; - q = ptr + STRLEN(ptr); + q = ptr + strlen(ptr); while (--q > ptr && ascii_iswhite(q[0]) && q[-1] != '\\' && q[-1] != Ctrl_V) { *q = NUL; } -- cgit From ec1738a6ed08dd3a89fd07950fa2dcc55a72b705 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Wed, 21 Dec 2022 12:00:05 +0100 Subject: refactor: replace char_u with char 16 - remove STRNCMP (#21208) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/strings.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index cfe821715c..a96134be8f 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -185,7 +185,7 @@ char *vim_strsave_shellescape(const char *string, bool do_special, bool do_newli length++; // insert backslash } } - if (do_special && find_cmdline_var(p, &l) >= 0) { + if (do_special && find_cmdline_var((char *)p, &l) >= 0) { length++; // insert backslash p += l - 1; } @@ -234,7 +234,7 @@ char *vim_strsave_shellescape(const char *string, bool do_special, bool do_newli *d++ = *p++; continue; } - if (do_special && find_cmdline_var((char_u *)p, &l) >= 0) { + if (do_special && find_cmdline_var(p, &l) >= 0) { *d++ = '\\'; // insert backslash while (--l != SIZE_MAX) { // copy the var *d++ = *p++; -- cgit From f2141de9e462ed8976b2a59337c32a0fcba2a11d Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Fri, 13 Jan 2023 00:35:39 +0100 Subject: refactor: replace char_u with char 20 (#21714) refactor: replace char_u with char Work on https://github.com/neovim/neovim/issues/459 --- src/nvim/strings.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'src/nvim/strings.c') diff --git a/src/nvim/strings.c b/src/nvim/strings.c index a96134be8f..f0f9fbf51b 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -41,7 +41,7 @@ char *xstrnsave(const char *string, size_t len) // Same as vim_strsave(), but any characters found in esc_chars are preceded // by a backslash. -char_u *vim_strsave_escaped(const char_u *string, const char_u *esc_chars) +char *vim_strsave_escaped(const char *string, const char *esc_chars) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { return vim_strsave_escaped_ext(string, esc_chars, '\\', false); @@ -50,36 +50,36 @@ char_u *vim_strsave_escaped(const char_u *string, const char_u *esc_chars) // Same as vim_strsave_escaped(), but when "bsl" is true also escape // characters where rem_backslash() would remove the backslash. // Escape the characters with "cc". -char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars, char_u cc, bool bsl) +char *vim_strsave_escaped_ext(const char *string, const char *esc_chars, char cc, bool bsl) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { // First count the number of backslashes required. // Then allocate the memory and insert them. size_t length = 1; // count the trailing NUL - for (const char_u *p = string; *p; p++) { - const size_t l = (size_t)(utfc_ptr2len((char *)p)); + for (const char *p = string; *p; p++) { + const size_t l = (size_t)(utfc_ptr2len(p)); if (l > 1) { length += l; // count a multibyte char p += l - 1; continue; } - if (vim_strchr((char *)esc_chars, *p) != NULL || (bsl && rem_backslash((char *)p))) { + if (vim_strchr(esc_chars, (uint8_t)(*p)) != NULL || (bsl && rem_backslash(p))) { length++; // count a backslash } length++; // count an ordinary char } - char_u *escaped_string = xmalloc(length); - char_u *p2 = escaped_string; - for (const char_u *p = string; *p; p++) { - const size_t l = (size_t)(utfc_ptr2len((char *)p)); + char *escaped_string = xmalloc(length); + char *p2 = escaped_string; + for (const char *p = string; *p; p++) { + const size_t l = (size_t)(utfc_ptr2len(p)); if (l > 1) { memcpy(p2, p, l); p2 += l; p += l - 1; // skip multibyte char continue; } - if (vim_strchr((char *)esc_chars, *p) != NULL || (bsl && rem_backslash((char *)p))) { + if (vim_strchr(esc_chars, (uint8_t)(*p)) != NULL || (bsl && rem_backslash(p))) { *p2++ = cc; } *p2++ = *p; @@ -150,7 +150,7 @@ char *vim_strsave_shellescape(const char *string, bool do_special, bool do_newli FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { char *d; - char_u *escaped_string; + char *escaped_string; size_t l; int csh_like; bool fish_like; @@ -196,7 +196,7 @@ char *vim_strsave_shellescape(const char *string, bool do_special, bool do_newli // Allocate memory for the result and fill it. escaped_string = xmalloc(length); - d = (char *)escaped_string; + d = escaped_string; // add opening quote #ifdef MSWIN @@ -206,7 +206,7 @@ char *vim_strsave_shellescape(const char *string, bool do_special, bool do_newli #endif *d++ = '\''; - for (const char *p = (char *)string; *p != NUL;) { + for (const char *p = string; *p != NUL;) { #ifdef MSWIN if (!p_ssl) { if (*p == '"') { @@ -259,19 +259,19 @@ char *vim_strsave_shellescape(const char *string, bool do_special, bool do_newli *d++ = '\''; *d = NUL; - return (char *)escaped_string; + return escaped_string; } // Like vim_strsave(), but make all characters uppercase. // This uses ASCII lower-to-upper case translation, language independent. -char_u *vim_strsave_up(const char_u *string) +char *vim_strsave_up(const char *string) FUNC_ATTR_NONNULL_RET FUNC_ATTR_MALLOC FUNC_ATTR_NONNULL_ALL { char *p1; - p1 = xstrdup((char *)string); + p1 = xstrdup(string); vim_strup((char_u *)p1); - return (char_u *)p1; + return p1; } /// Like xstrnsave(), but make all characters uppercase. @@ -452,14 +452,14 @@ void sort_strings(char **files, int count) // Return true if string "s" contains a non-ASCII character (128 or higher). // When "s" is NULL false is returned. -bool has_non_ascii(const char_u *s) +bool has_non_ascii(const char *s) FUNC_ATTR_PURE { - const char_u *p; + const char *p; if (s != NULL) { for (p = s; *p != NUL; p++) { - if (*p >= 128) { + if ((uint8_t)(*p) >= 128) { return true; } } @@ -946,18 +946,18 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, t - str_arg); } if (fmt_spec == 'S') { - char_u *p1; + char *p1; size_t i; - for (i = 0, p1 = (char_u *)str_arg; *p1; p1 += utfc_ptr2len((char *)p1)) { - size_t cell = (size_t)utf_ptr2cells((char *)p1); + for (i = 0, p1 = (char *)str_arg; *p1; p1 += utfc_ptr2len(p1)) { + size_t cell = (size_t)utf_ptr2cells(p1); if (precision_specified && i + cell > precision) { break; } i += cell; } - str_arg_l = (size_t)(p1 - (char_u *)str_arg); + str_arg_l = (size_t)(p1 - str_arg); if (min_field_width != 0) { min_field_width += str_arg_l - i; } -- cgit