fix appendFromChars

This commit is contained in:
2022-04-25 23:06:49 +03:00
parent a6cea11911
commit 23907c7043

View File

@@ -200,19 +200,20 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) {
void PIString::appendFromChars(const char * c, int s, const char * codepage) {
if (s <= 0) return;
int old_sz = size_s();
int sz;
#ifdef PIP_ICU
UErrorCode e((UErrorCode)0);
UConverter * cc = ucnv_open(codepage, &e);
if (cc) {
resize(s);
enlarge(s);
// UChar * ucs = new UChar[s];
// memset(ucs, 0, s * sizeof(UChar));
e = (UErrorCode)0;
sz = ucnv_toUChars(cc, (UChar*)(PIDeque<PIChar>::data()), s, c, s, &e);
sz = ucnv_toUChars(cc, (UChar*)(PIDeque<PIChar>::data(old_sz)), s, c, s, &e);
//printf("appendFromChars %d -> %d\n", s, sz);
//printf("PIString %d -> %d\n", c[0], ucs[0]);
resize(sz);
resize(sz+sz);
// for (int i = 0; i < sz; ++i) {
// push_back(PIChar((ushort)ucs[i]));
// }
@@ -224,7 +225,6 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
# ifdef WINDOWS
sz = MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, 0, 0);
if (sz <= 0) return;
int old_sz = size_s();
enlarge(sz);
MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, (LPWSTR)PIDeque<PIChar>::data(old_sz), sz);
return;
@@ -235,8 +235,8 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
size_t len = mbsrtowcs(NULL, &c, 0, &state);
wchar_t wstr[len+1];
mbsrtowcs(&wstr[0], &c, len+1, &state);
resize(len);
for (int i=0; i<len; ++i) (*this)[i] = wstr[i];
enlarge(len);
for (size_t i=0; i<len; ++i) (*this)[old_sz+i] = wstr[i];
// //qDebug() << "FromChars done" << size();
# endif
#endif