diff --git a/libs/main/core/pistring.cpp b/libs/main/core/pistring.cpp index 2448e0ed..fd90b325 100644 --- a/libs/main/core/pistring.cpp +++ b/libs/main/core/pistring.cpp @@ -85,7 +85,7 @@ const float PIString::ElideCenter = .5f; const float PIString::ElideRight = 1.f; -#define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); snprintf(ch, 256, f, v); return PIString(ch); +#define pisprintf(f, v) char ch[256]; memset(ch, 0, 256); snprintf(ch, 256, f, v); return PIStringAscii(ch); PIString PIString::itos(const int num) {pisprintf("%d", num);} PIString PIString::ltos(const long num) {pisprintf("%ld", num);} @@ -95,14 +95,14 @@ PIString PIString::ultos(const ulong num) {pisprintf("%lu", num);} PIString PIString::ulltos(const ullong num) {pisprintf("%llu", num);} PIString PIString::ftos(const float num, char format, int precision) { char f[8] = "%."; - int wr = sprintf(&(f[2]), "%d", precision); + int wr = snprintf(&(f[2]), 8, "%d", precision); f[2 + wr] = format; f[3 + wr] = 0; pisprintf(f, num); } PIString PIString::dtos(const double num, char format, int precision) { char f[8] = "%."; - int wr = sprintf(&(f[2]), "%d", precision); + int wr = snprintf(&(f[2]), 8, "%d", precision); f[2 + wr] = format; f[3 + wr] = 0; pisprintf(f, num); @@ -113,7 +113,7 @@ PIString PIString::dtos(const double num, char format, int precision) { PIString PIString::fromNumberBaseS(const llong value, int base, bool * ok) { if (value == 0LL) return PIString('0'); - if (base < 2 || base > 40) { + if ((base < 2) || (base > 40)) { if (ok != 0) *ok = false; return PIString(); } @@ -135,7 +135,7 @@ PIString PIString::fromNumberBaseS(const llong value, int base, bool * ok) { PIString PIString::fromNumberBaseU(const ullong value, int base, bool * ok) { if (value == 0ULL) return PIString('0'); - if (base < 2 || base > 40) { + if ((base < 2) || (base > 40)) { if (ok != 0) *ok = false; return PIString(); } @@ -166,7 +166,7 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) { } else { base = 10; } - } else if (base < 2 || base > 40) { + } else if ((base < 2) || (base > 40)) { if (ok != 0) *ok = false; return 0; } @@ -197,6 +197,7 @@ llong PIString::toNumberBase(const PIString & value, int base, bool * ok) { void PIString::appendFromChars(const char * c, int s, const char * codepage) { +// piCout << "appendFromChars"; if (s == 0) return; int old_sz = size_s(); if (s == -1) s = strlen(c); @@ -221,7 +222,7 @@ void PIString::appendFromChars(const char * c, int s, const char * codepage) { std::wstring_convert, char16_t> ucs2conv; std::u16string ucs2 = ucs2conv.from_bytes(c, c+s); enlarge(ucs2.size()); - ucs2.copy((char16_t *)PIDeque::data(old_sz), ucs2.size()); + ucs2.copy((char16_t *)d.data(old_sz), ucs2.size()); # endif #endif } @@ -311,21 +312,20 @@ PIString PIString::readableSize(llong bytes) { void PIString::buildData(const char * cp) const { deleteData(); - int sz = 0; #ifdef PIP_ICU UErrorCode e((UErrorCode)0); UConverter * cc = ucnv_open(cp, &e); if (cc) { const size_t len = MB_CUR_MAX*size()+1; data_ = (char *)malloc(len); - sz = ucnv_fromUChars(cc, data_, len, (const UChar*)(d.data()), d.size_s(), &e); + int sz = ucnv_fromUChars(cc, data_, len, (const UChar*)(d.data()), d.size_s(), &e); ucnv_close(cc); data_[sz] = '\0'; return; } #else # ifdef WINDOWS - sz = WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)d.data(), d.size_s(), 0, 0, NULL, NULL); + int sz = WideCharToMultiByte((uint)(uintptr_t)cp, 0, (LPCWCH)d.data(), d.size_s(), 0, 0, NULL, NULL); if (sz <= 0) { data_ = (char *)malloc(1); data_[0] = '\0'; @@ -337,7 +337,7 @@ void PIString::buildData(const char * cp) const { return; # else std::wstring_convert, char16_t> ucs2conv; - std::string u8str = ucs2conv.to_bytes((char16_t*)PIDeque::data(), (char16_t*)PIDeque::data()+size()); + std::string u8str = ucs2conv.to_bytes((char16_t*)d.data(), (char16_t*)d.data() + d.size()); data_ = (char *)malloc(u8str.size()+1); strcpy(data_, u8str.c_str()); # endif diff --git a/main.cpp b/main.cpp index 38a223b9..057e06ab 100644 --- a/main.cpp +++ b/main.cpp @@ -130,7 +130,13 @@ int main(int argc, char * argv[]) { } piCout << l << "PIString::fromNumber" << tm.elapsed_m(); tm.reset(); + for(int i=0; i