linux PIString fix
This commit is contained in:
@@ -199,21 +199,21 @@ 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 old_sz = size_s();
|
||||||
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) {
|
||||||
|
if (s == -1) s = strlen(s);
|
||||||
enlarge(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(old_sz)), s, c, s, &e);
|
int 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+sz);
|
resize(old_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]));
|
||||||
// }
|
// }
|
||||||
@@ -223,7 +223,8 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
# ifdef WINDOWS
|
# ifdef WINDOWS
|
||||||
sz = MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, 0, 0);
|
if (s == -1) s = strlen(s);
|
||||||
|
int sz = MultiByteToWideChar((uint)(uintptr_t)codepage, MB_ERR_INVALID_CHARS, c, s, 0, 0);
|
||||||
if (sz <= 0) return;
|
if (sz <= 0) return;
|
||||||
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);
|
||||||
@@ -232,9 +233,18 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
|||||||
# else
|
# else
|
||||||
mbstate_t state;
|
mbstate_t state;
|
||||||
memset(&state, 0, sizeof(state));
|
memset(&state, 0, sizeof(state));
|
||||||
size_t len = mbsrtowcs(NULL, &c, 0, &state);
|
char * pc;
|
||||||
|
if (s > 0) {
|
||||||
|
char c_ [s+1];
|
||||||
|
memcpy(c_, c, s);
|
||||||
|
c_[s] = '\0';
|
||||||
|
pc = c_;
|
||||||
|
} else {
|
||||||
|
pc = c;
|
||||||
|
}
|
||||||
|
size_t len = mbsrtowcs(NULL, &pc, 0, &state);
|
||||||
wchar_t wstr[len+1];
|
wchar_t wstr[len+1];
|
||||||
mbsrtowcs(&wstr[0], &c, len+1, &state);
|
mbsrtowcs(&wstr[0], &pc, len+1, &state);
|
||||||
enlarge(len);
|
enlarge(len);
|
||||||
for (size_t i=0; i<len; ++i) (*this)[old_sz+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();
|
||||||
@@ -246,7 +256,7 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
|||||||
PIString PIString::fromConsole(const char * s) {
|
PIString PIString::fromConsole(const char * s) {
|
||||||
PIString ret;
|
PIString ret;
|
||||||
if (!s) return ret;
|
if (!s) return ret;
|
||||||
if (s[0] != '\0') ret.appendFromChars(s, strlen(s), __sysoemname__);
|
if (s[0] != '\0') ret.appendFromChars(s, -1, __sysoemname__);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -255,7 +265,7 @@ PIString PIString::fromConsole(const char * s) {
|
|||||||
PIString PIString::fromSystem(const char * s) {
|
PIString PIString::fromSystem(const char * s) {
|
||||||
PIString ret;
|
PIString ret;
|
||||||
if (!s) return ret;
|
if (!s) return ret;
|
||||||
if (s[0] != '\0') ret.appendFromChars(s, strlen(s), __syslocname__);
|
if (s[0] != '\0') ret.appendFromChars(s, -1, __syslocname__);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -263,7 +273,7 @@ PIString PIString::fromSystem(const char * s) {
|
|||||||
PIString PIString::fromUTF8(const char * s) {
|
PIString PIString::fromUTF8(const char * s) {
|
||||||
PIString ret;
|
PIString ret;
|
||||||
if (!s) return ret;
|
if (!s) return ret;
|
||||||
if (s[0] != '\0') ret.appendFromChars(s, strlen(s), __utf8name__);
|
if (s[0] != '\0') ret.appendFromChars(s, -1, __utf8name__);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,7 +302,7 @@ PIString PIString::fromAscii(const char * s, int len) {
|
|||||||
|
|
||||||
PIString PIString::fromCodepage(const char * s, const char * c) {
|
PIString PIString::fromCodepage(const char * s, const char * c) {
|
||||||
PIString ret;
|
PIString ret;
|
||||||
if (s[0] > '\0') ret.appendFromChars(s, strlen(s)
|
if (s[0] > '\0') ret.appendFromChars(s, -1
|
||||||
#ifdef PIP_ICU
|
#ifdef PIP_ICU
|
||||||
, c
|
, c
|
||||||
#else
|
#else
|
||||||
@@ -444,7 +454,7 @@ PIByteArray PIString::toCharset(const char * c) const {
|
|||||||
|
|
||||||
PIString & PIString::operator +=(const char * str) {
|
PIString & PIString::operator +=(const char * str) {
|
||||||
if (!str) return *this;
|
if (!str) return *this;
|
||||||
appendFromChars(str, strlen(str), __syslocname__);
|
appendFromChars(str, -1, __syslocname__);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user