Skip to content

Commit

Permalink
dirent: use custom UTF-16 to UTF-8 converter
Browse files Browse the repository at this point in the history
see issue #22
files/dirs with non-Latin chars are displayed after this commit
they still do not load though, but a fix is guaranteed
  • Loading branch information
tildearrow committed Jan 20, 2022
1 parent 1ee23ac commit 06dfb7e
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion extern/igfd/dirent/dirent.h
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,27 @@ dirent_mbstowcs_s(
return error;
}

static int u16to8s(char* dest, const wchar_t* src, size_t limit) {
size_t ret=0;
for (; (*src)!=0; src++) {
if ((*src)<0x80) {
if (ret+1>=limit-1) break;
dest[ret++]=(*src);
} else if ((*src)<0x800) {
if (ret+2>=limit-1) break;
dest[ret++]=(0xc0+(((*src)>>6)&31));
dest[ret++]=(0x80+((*src)&63));
} else {
if (ret+3>=limit-1) break;
dest[ret++]=(0xe0+(((*src)>>12)&15));
dest[ret++]=(0x80+(((*src)>>6)&63));
dest[ret++]=(0x80+((*src)&63));
}
}
dest[ret]=0;
return ret;
}

/* Convert wide-character string to multi-byte string */
static int
dirent_wcstombs_s(
Expand All @@ -1105,7 +1126,8 @@ dirent_wcstombs_s(
size_t n;

/* Convert to multi-byte string (or count the number of bytes needed) */
n = wcstombs (mbstr, wcstr, sizeInBytes);
// TODO: please fix for internationalization! issue #22
n = u16to8s(mbstr, wcstr, sizeInBytes);
if (!mbstr || n < count) {

/* Zero-terminate output buffer */
Expand Down

0 comments on commit 06dfb7e

Please sign in to comment.