fix appendFromChars
This commit is contained in:
@@ -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) {
|
void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
||||||
if (s <= 0) return;
|
if (s <= 0) return;
|
||||||
|
int old_sz = size_s();
|
||||||
int sz;
|
int sz;
|
||||||
#ifdef PIP_ICU
|
#ifdef PIP_ICU
|
||||||
UErrorCode e((UErrorCode)0);
|
UErrorCode e((UErrorCode)0);
|
||||||
UConverter * cc = ucnv_open(codepage, &e);
|
UConverter * cc = ucnv_open(codepage, &e);
|
||||||
if (cc) {
|
if (cc) {
|
||||||
resize(s);
|
enlarge(s);
|
||||||
// UChar * ucs = new UChar[s];
|
// UChar * ucs = new UChar[s];
|
||||||
// memset(ucs, 0, s * sizeof(UChar));
|
// memset(ucs, 0, s * sizeof(UChar));
|
||||||
e = (UErrorCode)0;
|
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("appendFromChars %d -> %d\n", s, sz);
|
||||||
//printf("PIString %d -> %d\n", c[0], ucs[0]);
|
//printf("PIString %d -> %d\n", c[0], ucs[0]);
|
||||||
resize(sz);
|
resize(sz+sz);
|
||||||
// for (int i = 0; i < sz; ++i) {
|
// for (int i = 0; i < sz; ++i) {
|
||||||
// push_back(PIChar((ushort)ucs[i]));
|
// push_back(PIChar((ushort)ucs[i]));
|
||||||
// }
|
// }
|
||||||
@@ -224,7 +225,6 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
|||||||
# ifdef WINDOWS
|
# ifdef WINDOWS
|
||||||
sz = MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, 0, 0);
|
sz = MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, 0, 0);
|
||||||
if (sz <= 0) return;
|
if (sz <= 0) return;
|
||||||
int old_sz = size_s();
|
|
||||||
enlarge(sz);
|
enlarge(sz);
|
||||||
MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, (LPWSTR)PIDeque<PIChar>::data(old_sz), sz);
|
MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, (LPWSTR)PIDeque<PIChar>::data(old_sz), sz);
|
||||||
return;
|
return;
|
||||||
@@ -235,8 +235,8 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
|||||||
size_t len = mbsrtowcs(NULL, &c, 0, &state);
|
size_t len = mbsrtowcs(NULL, &c, 0, &state);
|
||||||
wchar_t wstr[len+1];
|
wchar_t wstr[len+1];
|
||||||
mbsrtowcs(&wstr[0], &c, len+1, &state);
|
mbsrtowcs(&wstr[0], &c, len+1, &state);
|
||||||
resize(len);
|
enlarge(len);
|
||||||
for (int i=0; i<len; ++i) (*this)[i] = wstr[i];
|
for (size_t i=0; i<len; ++i) (*this)[old_sz+i] = wstr[i];
|
||||||
// //qDebug() << "FromChars done" << size();
|
// //qDebug() << "FromChars done" << size();
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user