Cygwin: next_unicode_mbs: return full char prefix from multibyte

Convert multibyte string to wint_t string and return the length
of the multibyte prefix constituting a full unicode char, taking
collating elements into account.  Also return the resulting wint_t
string.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
This commit is contained in:
Corinna Vinschen 2023-03-09 11:10:53 +01:00
parent c47a998d0a
commit fbd8b4a9ad
2 changed files with 17 additions and 0 deletions

View File

@ -21,6 +21,7 @@ int is_unicode_equiv (wint_t, wint_t);
int is_unicode_coll_elem (const wint_t *);
size_t next_unicode_char (wint_t *);
size_t next_unicode_mbs (wint_t *, const char *, size_t);
#ifdef __cplusplus
};

View File

@ -1360,6 +1360,22 @@ next_unicode_char (wint_t *inp)
return 1;
}
/* Return the number of bytes making up the next full character in inp, and
copies them over to out. This is basically next_unicode_char(), just for
multibyte input. outlen is the buffer size of the out buffer. */
extern "C" size_t
next_unicode_mbs (wint_t *out, const char *inp, size_t outlen)
{
size_t ret;
/* Max collation element is 8 wint_t's. */
ret = mbsnrtowci (out, &inp, SIZE_MAX, outlen - 1, NULL);
out[ret] = L'\0'; /* mbsnrtowci never returns -1 */
ret = next_unicode_char (out);
out[ret] = L'\0';
return wcitombs (NULL, out, 0);
}
extern "C" size_t
wcsxfrm_l (wchar_t *__restrict ws1, const wchar_t *__restrict ws2, size_t wsn,
struct __locale_t *locale)