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

View File

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