message: Refactor str2specialbuf

Does not alter its usages.
This commit is contained in:
ZyX 2017-07-02 18:24:16 +03:00
parent e9e1668ca6
commit 832c158a66

View File

@ -1374,19 +1374,25 @@ const char *str2special(const char **const sp, const bool replace_spaces)
return buf; return buf;
} }
/* /// Convert string, replacing key codes with printables
* Translate a key sequence into special key names. ///
*/ /// @param[in] str String to convert.
void str2specialbuf(char_u *sp, char_u *buf, int len) /// @param[out] buf Buffer to save results to.
/// @param[in] len Buffer length.
void str2specialbuf(const char *sp, char *buf, size_t len)
FUNC_ATTR_NONNULL_ALL
{ {
char_u *s;
*buf = NUL;
while (*sp) { while (*sp) {
s = str2special(&sp, FALSE); const char *s = str2special(&sp, false);
if ((int)(STRLEN(s) + STRLEN(buf)) < len) const size_t s_len = strlen(s);
STRCAT(buf, s); if (s_len <= len) {
break;
}
memcpy(buf, s, s_len);
buf += s_len;
len -= s_len;
} }
*buf = NUL;
} }
/* /*