mirror of
https://github.com/tildearrow/furnace.git
synced 2024-11-22 20:45:11 +00:00
dirent: use custom UTF-16 to UTF-8 converter
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
This commit is contained in:
parent
1ee23ac198
commit
06dfb7e803
1 changed files with 23 additions and 1 deletions
24
extern/igfd/dirent/dirent.h
vendored
24
extern/igfd/dirent/dirent.h
vendored
|
@ -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(
|
||||
|
@ -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 */
|
||||
|
|
Loading…
Reference in a new issue