linux mb test

This commit is contained in:
Andrey
2022-04-26 16:41:04 +03:00
parent 06c8e6af10
commit 186c71d973

View File

@@ -324,21 +324,8 @@ void PIString::buildData(const char * cp) const {
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_[sz] = '\0';
// data_.push_back('\0');
return;
}
#else
@@ -357,23 +344,10 @@ void PIString::buildData(const char * cp) const {
data_[sz] = '\0';
return;
# else
wchar_t wc;
//char tc[MB_CUR_MAX];
mbstate_t state;
memset(&state, 0, sizeof(state));
data_ = (char *)malloc(MB_CUR_MAX*size()+1);
char *p = data_;
for (int i = 0; i < size_s(); ++i) {
// if (at(i).isAscii()) {
// data_.push_back(uchar(at(i).toAscii()));
// continue;
// }
wc = at(i).toWChar();
sz = wcrtomb(p, wc, &state);
if (sz < 0) break;
p += sz;
}
p[0] = '\0';
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> ucs2conv;
std::string u8str = ucs2conv.to_bytes((char16_t*)PIDeque<PIChar>::data(), (char16_t*)PIDeque<PIChar>::data()+size());
data_ = (char *)malloc(u8str.size()+1);
strcpy(data_, u8str.c_str());
# endif
#endif
}