forked from aniani/vim
patch 9.1.1076: vim_strnchr() is strange and unnecessary
Problem: vim_strnchr() is strange and unnecessary (after v9.1.1009) Solution: Remove vim_strnchr() and use memchr() instead. Also remove a comment referencing an #if that is no longer present. vim_strnchr() is strange in several ways: - It's named like vim_strchr(), but unlike vim_strchr() it doesn't support finding a multibyte char. - Its logic is similar to vim_strbyte(), but unlike vim_strbyte() it uses char instead of char_u. - It takes a pointer as its size argument, which isn't convenient for all its callers. - It allows embedded NULs, unlike other "strn*" functions which stop when encountering a NUL byte. In comparison, memchr() also allows embedded NULs, and it converts bytes in the string to (unsigned char). closes: #16579 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
committed by
Christian Brabandt
parent
f7cb9f9280
commit
34e1e8de91
@@ -674,22 +674,6 @@ vim_strchr(char_u *string, int c)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Sized version of strchr that can handle embedded NULs.
|
||||
// Adjusts n to the new size.
|
||||
char *
|
||||
vim_strnchr(const char *p, size_t *n, int c)
|
||||
{
|
||||
while (*n > 0)
|
||||
{
|
||||
if (*p == c)
|
||||
return (char *)p;
|
||||
p++;
|
||||
(*n)--;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Version of strchr() that only works for bytes and handles unsigned char
|
||||
* strings with characters above 128 correctly. It also doesn't return a
|
||||
@@ -3558,8 +3542,6 @@ vim_vsnprintf_typval(
|
||||
str_arg_l = 0;
|
||||
else
|
||||
{
|
||||
// Don't put the #if inside memchr(), it can be a
|
||||
// macro.
|
||||
// memchr on HP does not like n > 2^31 !!!
|
||||
char *q = memchr(str_arg, '\0',
|
||||
precision <= (size_t)0x7fffffffL ? precision
|
||||
|
Reference in New Issue
Block a user