refactor: add function xstrnsave

xstrnsave is a clone of vim_strnsave that uses char* instead of char_u*.
Its purpose short-term is to help reduce the number of casts and for
long-term to replace vim_strnsave as the need to use char_u is
eliminated.
This commit is contained in:
Dundar Goc
2022-04-15 19:49:06 +02:00
parent 7a2fcbbbec
commit 88270a5735
4 changed files with 13 additions and 6 deletions

View File

@@ -1275,7 +1275,7 @@ static char *popup_mode_name(char *name, int idx)
size_t len = STRLEN(name);
assert(len >= 4);
char *p = (char *)vim_strnsave((char_u *)name, len + 1);
char *p = xstrnsave(name, len + 1);
memmove(p + 6, p + 5, len - 4);
p[5] = menu_mode_chars[idx];
@@ -1308,7 +1308,7 @@ static char *menu_text(const char *str, int *mnemonic, char **actext)
*actext = xstrdup(p + 1);
}
assert(p >= str);
text = (char *)vim_strnsave((char_u *)str, (size_t)(p - str));
text = xstrnsave(str, (size_t)(p - str));
} else {
text = xstrdup(str);
}
@@ -1560,7 +1560,7 @@ void ex_menutranslate(exarg_T *eap)
from = xstrdup(from);
from_noamp = menu_text(from, NULL, NULL);
assert(arg >= to);
to = (char *)vim_strnsave((char_u *)to, (size_t)(arg - to));
to = xstrnsave(to, (size_t)(arg - to));
menu_translate_tab_and_shift(from);
menu_translate_tab_and_shift(to);
menu_unescape_name(from);