Stringify reformat_for_screen

This is the only usage of wcsndup, and we can just use wcstring::substr.
This commit is contained in:
Fabian Homborg 2022-01-07 18:42:39 +01:00
parent 71cfd25c1d
commit 753f29df4c

View File

@ -710,20 +710,18 @@ wcstring reformat_for_screen(const wcstring &msg, const termsize_t &termsize) {
pos = pos + 1; pos = pos + 1;
} else if (overflow) { } else if (overflow) {
// In case of overflow, we print a newline, except if we already are at position 0. // In case of overflow, we print a newline, except if we already are at position 0.
wchar_t *token = wcsndup(start, pos - start); wcstring token = msg.substr(start - msg.c_str(), pos - start);
if (line_width != 0) buff.push_back(L'\n'); if (line_width != 0) buff.push_back(L'\n');
buff.append(format_string(L"%ls-\n", token)); buff.append(format_string(L"%ls-\n", token.c_str()));
free(token);
line_width = 0; line_width = 0;
} else { } else {
// Print the token. // Print the token.
wchar_t *token = wcsndup(start, pos - start); wcstring token = msg.substr(start - msg.c_str(), pos - start);
if ((line_width + (line_width != 0 ? 1 : 0) + tok_width) > screen_width) { if ((line_width + (line_width != 0 ? 1 : 0) + tok_width) > screen_width) {
buff.push_back(L'\n'); buff.push_back(L'\n');
line_width = 0; line_width = 0;
} }
buff.append(format_string(L"%ls%ls", line_width ? L" " : L"", token)); buff.append(format_string(L"%ls%ls", line_width ? L" " : L"", token.c_str()));
free(token);
line_width += (line_width != 0 ? 1 : 0) + tok_width; line_width += (line_width != 0 ? 1 : 0) + tok_width;
} }