LibC: Implement wcswidth

This commit is contained in:
Tim Schumacher 2022-06-29 05:01:14 +02:00 committed by Andreas Kling
parent 9497cc6c97
commit 6d4d6c3e2a
2 changed files with 18 additions and 0 deletions

View file

@ -531,6 +531,23 @@ int wcwidth(wchar_t wc)
return 1;
}
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcswidth.html
int wcswidth(wchar_t const* pwcs, size_t n)
{
int len = 0;
for (size_t i = 0; i < n && pwcs[i]; i++) {
int char_len = wcwidth(pwcs[i]);
if (char_len == -1)
return -1;
len += char_len;
}
return len;
}
// https://pubs.opengroup.org/onlinepubs/9699919799/functions/wcsnrtombs.html
size_t wcsnrtombs(char* dest, wchar_t const** src, size_t nwc, size_t len, mbstate_t* ps)
{

View file

@ -63,6 +63,7 @@ float wcstof(wchar_t const*, wchar_t**);
double wcstod(wchar_t const*, wchar_t**);
long double wcstold(wchar_t const*, wchar_t**);
int wcwidth(wchar_t);
int wcswidth(wchar_t const*, size_t);
size_t wcsrtombs(char*, wchar_t const**, size_t, mbstate_t*);
size_t mbsrtowcs(wchar_t*, char const**, size_t, mbstate_t*);
int wmemcmp(wchar_t const*, wchar_t const*, size_t);