Skip to content

Commit

Permalink
LibC: Implement wcswidth
Browse files Browse the repository at this point in the history
  • Loading branch information
timschumi authored and awesomekling committed Jun 30, 2022
1 parent 9497cc6 commit 6d4d6c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Userland/Libraries/LibC/wchar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions Userland/Libraries/LibC/wchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 6d4d6c3

Please sign in to comment.