piChar mbrtowc

This commit is contained in:
2022-04-25 22:14:42 +03:00
parent 2246b8b5fd
commit 095ecd254f
2 changed files with 6 additions and 28 deletions

View File

@@ -35,12 +35,6 @@ char * __utf8name__ = 0;
# include <ctype.h>
#endif
#include <wchar.h>
#ifdef ANDROID
# if __ANDROID_API__ < 21
# define wctomb(s, wc) wcrtomb(s, wc, NULL)
# define mbtowc(pwc, s, n) mbrtowc(pwc, s, n, NULL)
# endif
#endif
//! \addtogroup Core
//! \{
@@ -86,9 +80,10 @@ ushort charFromCodepage(const char * c, int size, const char * codepage, int * t
if (taken) *taken = ret;
return buffer;
# else
wchar_t wc(0);
mbtowc(0, 0, 0); // reset mbtowc
ret = mbtowc(&wc, c, size);
mbstate_t state;
memset(&state, 0, sizeof(state));
wchar_t wc;
ret = mbrtowc(&wc, c, size, &state);
//printf("mbtowc = %d\n", ret);
if (ret < 1) return 0;
return ushort(wc);
@@ -387,15 +382,9 @@ PICout operator <<(PICout s, const PIChar & v) {
} else
#endif
#ifdef WINDOWS
s << v.toSystem();
s << v.toSystem();
#else
{
char tc[8];
wctomb(0, 0);
int sz = wctomb(tc, v.ch);
for (int b = 0; b < sz; ++b)
s << tc[b];
}
s << PIString(v);
#endif
}
s.restoreControl();

View File

@@ -236,17 +236,6 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
mbsrtowcs(&wstr[0], &c, len+1, &state);
resize(len);
for (int i=0; i<len; ++i) (*this)[i] = wstr[i];
// wchar_t wc;
// //qDebug() << "FromChars ...";
// while (sz = mbrtowc(&wc, c, s, &state) > 0) {
// //qDebug() << "0" << s;
//// sz = mbrtowc(&wc, c, s, &state);
// //qDebug() << "1" << sz;
//// if (sz < 1) break;
// push_back(PIChar(wc));
// c += sz; s -= sz;
// //qDebug() << "2" << c;
// }
// //qDebug() << "FromChars done" << size();
# endif
#endif