Fix another surrogate-related bug in UTF-8 build in wxString
This is similar to the fix in the previous commit and is needed for the same reason.
This commit is contained in:
parent
aea45196ab
commit
fab541a8ff
1 changed files with 10 additions and 0 deletions
|
|
@ -987,7 +987,17 @@ public:
|
|||
// This is logically equivalent to strlen(str.mb_str()) but avoids
|
||||
// actually converting the string to multibyte and just computes the
|
||||
// length that it would have after conversion.
|
||||
|
||||
// Note that in UTF-8 build we need to use the actual wide character
|
||||
// buffer length and not the string length, as it may be different when
|
||||
// using surrogates, but in wchar_t build they're the same by definition
|
||||
// and we can avoid creating an extra buffer.
|
||||
#if wxUSE_UNICODE_UTF8
|
||||
const wxScopedWCharBuffer wbuf(str.wc_str());
|
||||
const size_t ofs = wxConvLibc.FromWChar(nullptr, 0, wbuf.data(), wbuf.length());
|
||||
#else // wxUSE_UNICODE_WCHAR
|
||||
const size_t ofs = wxConvLibc.FromWChar(nullptr, 0, str.wc_str(), str.length());
|
||||
#endif
|
||||
return ofs == wxCONV_FAILED ? 0 : static_cast<ptrdiff_t>(ofs);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue