linux mb test
This commit is contained in:
@@ -27,7 +27,9 @@
|
|||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
# include <stringapiset.h>
|
# include <stringapiset.h>
|
||||||
#endif
|
#endif
|
||||||
#include <cuchar>
|
#include <string>
|
||||||
|
#include <locale>
|
||||||
|
#include <codecvt>
|
||||||
|
|
||||||
//! \addtogroup Core
|
//! \addtogroup Core
|
||||||
//! \{
|
//! \{
|
||||||
@@ -207,17 +209,9 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
|||||||
UConverter * cc = ucnv_open(codepage, &e);
|
UConverter * cc = ucnv_open(codepage, &e);
|
||||||
if (cc) {
|
if (cc) {
|
||||||
enlarge(s);
|
enlarge(s);
|
||||||
// UChar * ucs = new UChar[s];
|
|
||||||
// memset(ucs, 0, s * sizeof(UChar));
|
|
||||||
e = (UErrorCode)0;
|
e = (UErrorCode)0;
|
||||||
int 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("PIString %d -> %d\n", c[0], ucs[0]);
|
|
||||||
resize(old_sz+sz);
|
resize(old_sz+sz);
|
||||||
// for (int i = 0; i < sz; ++i) {
|
|
||||||
// push_back(PIChar((ushort)ucs[i]));
|
|
||||||
// }
|
|
||||||
// delete[] ucs;
|
|
||||||
ucnv_close(cc);
|
ucnv_close(cc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -227,40 +221,11 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) {
|
|||||||
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);
|
||||||
return;
|
|
||||||
//printf("request %d\n", sz);
|
|
||||||
# else
|
# else
|
||||||
std::mbstate_t state{};
|
std::wstring_convert<std::codecvt_utf8<char16_t>, char16_t> ucs2conv;
|
||||||
PIChar c16;
|
std::u16string ucs2 = ucs2conv.from_bytes(c, c+s);
|
||||||
int sz = 0;
|
enlarge(ucs2.size());
|
||||||
while(std::size_t rc = std::mbrtoc16((char16_t*)&c16, c+sz, s - sz, &state)) {
|
ucs2.copy((char16_t *)PIDeque<PIChar>::data(old_sz), ucs2.size());
|
||||||
if(rc == (std::size_t)-3)
|
|
||||||
append(c16);
|
|
||||||
else if(rc == (std::size_t)-2)
|
|
||||||
break;
|
|
||||||
else if(rc == (std::size_t)-1)
|
|
||||||
break;
|
|
||||||
else {
|
|
||||||
sz += rc;
|
|
||||||
append(c16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// const char ** pc;
|
|
||||||
// char * c_ = nullptr;
|
|
||||||
// if (s > 0) {
|
|
||||||
// c_ = (char*)malloc(s+1);
|
|
||||||
// memcpy(c_, c, s);
|
|
||||||
// c_[s] = '\0';
|
|
||||||
// pc = (const char **)&c_;
|
|
||||||
// } else {
|
|
||||||
// pc = &c;
|
|
||||||
// }
|
|
||||||
// size_t len = mbsrtowcs(NULL, pc, 0, &state);
|
|
||||||
// wchar_t wstr[len+1];
|
|
||||||
// mbsrtowcs(&wstr[0], pc, len+1, &state);
|
|
||||||
// if (c_) free(c_);
|
|
||||||
// d.enlarge(len);
|
|
||||||
// for (size_t i=0; i<len; ++i) d[old_sz+i] = PIChar(wstr[i]);
|
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user