PIString ICU

This commit is contained in:
2022-04-25 22:54:46 +03:00
parent cea7a7c121
commit a6cea11911
2 changed files with 27 additions and 23 deletions

View File

@@ -205,17 +205,18 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
UErrorCode e((UErrorCode)0);
UConverter * cc = ucnv_open(codepage, &e);
if (cc) {
UChar * ucs = new UChar[s];
memset(ucs, 0, s * sizeof(UChar));
resize(s);
// UChar * ucs = new UChar[s];
// memset(ucs, 0, s * sizeof(UChar));
e = (UErrorCode)0;
sz = ucnv_toUChars(cc, ucs, s, c, s, &e);
sz = ucnv_toUChars(cc, (UChar*)(PIDeque<PIChar>::data()), s, c, s, &e);
//printf("appendFromChars %d -> %d\n", s, sz);
//printf("PIString %d -> %d\n", c[0], ucs[0]);
reserve(size_s() + sz);
for (int i = 0; i < sz; ++i) {
push_back(PIChar((ushort)ucs[i]));
}
delete[] ucs;
resize(sz);
// for (int i = 0; i < sz; ++i) {
// push_back(PIChar((ushort)ucs[i]));
// }
// delete[] ucs;
ucnv_close(cc);
return;
}
@@ -332,21 +333,24 @@ void PIString::buildData(const char * cp) const {
UErrorCode e((UErrorCode)0);
UConverter * cc = ucnv_open(cp, &e);
if (cc) {
char uc[8];
data_.reserve(size_s());
for (int i = 0; i < size_s(); ++i) {
if (at(i).isAscii()) {
data_.push_back(uchar(at(i).unicode16Code()));
} else {
e = (UErrorCode)0;
sz = ucnv_fromUChars(cc, uc, 8, (const UChar*)(PIDeque<PIChar>::data(i)), 1, &e);
for (int j = 0; j < sz; ++j) {
data_.push_back(uc[j]);
}
}
}
const size_t len = MB_CUR_MAX*size()+1;
data_ = (char *)malloc(len);
sz = ucnv_fromUChars(cc, data_, len, (const UChar*)(PIDeque<PIChar>::data()), size_s(), &e);
// char uc[8];
// data_.reserve(size_s());
// for (int i = 0; i < size_s(); ++i) {
// if (at(i).isAscii()) {
// data_.push_back(uchar(at(i).unicode16Code()));
// } else {
// e = (UErrorCode)0;
// for (int j = 0; j < sz; ++j) {
// data_.push_back(uc[j]);
// }
// }
// }
ucnv_close(cc);
data_.push_back('\0');
data_[sz] = '\0';
// data_.push_back('\0');
return;
}
#else

View File

@@ -205,7 +205,7 @@ void PIProcess::startProc(bool detached) {
if (execve(str.data(), (char * const *)argscc, (char * const *)envcc) < 0)
piCoutObj << "\"execve" << str << args << "\" error :" << errorString();
} else {
piMinSleep;
piMinSleep();
//cout << "wait" << endl;
if (!detached) {
wait(&exit_code);