Use Scintilla's functions for Unicode/UTF8 conversions
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29932 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -3109,36 +3109,26 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&);
|
|||||||
// Utility functions used within wxSTC
|
// Utility functions used within wxSTC
|
||||||
|
|
||||||
#ifndef SWIG
|
#ifndef SWIG
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
|
||||||
|
wxString stc2wx(const char* str);
|
||||||
|
wxString stc2wx(const char* str, size_t len);
|
||||||
|
const wxWX2MBbuf wx2stc(const wxString& str);
|
||||||
|
|
||||||
|
#else // not UNICODE
|
||||||
|
|
||||||
inline wxString stc2wx(const char* str) {
|
inline wxString stc2wx(const char* str) {
|
||||||
#if wxUSE_UNICODE
|
|
||||||
return wxString(str, wxConvUTF8);
|
|
||||||
#else
|
|
||||||
return wxString(str);
|
return wxString(str);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
|
||||||
wxString stc2wx(const char* str, size_t len);
|
|
||||||
#else
|
|
||||||
inline wxString stc2wx(const char* str, size_t len) {
|
inline wxString stc2wx(const char* str, size_t len) {
|
||||||
return wxString(str, len);
|
return wxString(str, len);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
|
||||||
inline const wxWX2MBbuf wx2stc(const wxString& str) {
|
|
||||||
return str.mb_str(wxConvUTF8);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
inline const wxWX2MBbuf wx2stc(const wxString& str) {
|
inline const wxWX2MBbuf wx2stc(const wxString& str) {
|
||||||
return str.mbc_str();
|
return str.mbc_str();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif // UNICODE
|
||||||
|
#endif // SWIG
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1249,25 +1249,47 @@ double ElapsedTime::Duration(bool reset) {
|
|||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
|
|
||||||
|
#include "UniConversion.h"
|
||||||
|
|
||||||
|
// Convert using Scintilla's functions instead of wx's, Scintilla's are more
|
||||||
|
// forgiving and won't assert...
|
||||||
|
|
||||||
wxString stc2wx(const char* str, size_t len)
|
wxString stc2wx(const char* str, size_t len)
|
||||||
{
|
{
|
||||||
// note: we assume that str is of length len not including the terminating null.
|
|
||||||
|
|
||||||
if (!len)
|
if (!len)
|
||||||
return wxEmptyString;
|
return wxEmptyString;
|
||||||
else if (str[len-1] == 0)
|
|
||||||
// It's already terminated correctly.
|
|
||||||
return wxString(str, wxConvUTF8, len);
|
|
||||||
|
|
||||||
char *buffer=new char[len+1];
|
size_t wclen = UCS2Length(str, len);
|
||||||
strncpy(buffer, str, len);
|
wxWCharBuffer buffer(wclen+1);
|
||||||
buffer[len]=0;
|
|
||||||
|
|
||||||
wxString cstr(buffer, wxConvUTF8, len);
|
size_t actualLen = UCS2FromUTF8(str, len, buffer.data(), wclen+1);
|
||||||
|
return wxString(buffer.data(), actualLen);
|
||||||
delete[] buffer;
|
|
||||||
return cstr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxString stc2wx(const char* str)
|
||||||
|
{
|
||||||
|
return stc2wx(str, strlen(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const wxWX2MBbuf wx2stc(const wxString& str)
|
||||||
|
{
|
||||||
|
const wchar_t* wcstr = str.c_str();
|
||||||
|
size_t wclen = str.length();
|
||||||
|
size_t len = UTF8Length(wcstr, wclen);
|
||||||
|
|
||||||
|
wxCharBuffer buffer(len+1);
|
||||||
|
UTF8FromUCS2(wcstr, wclen, buffer.data(), len);
|
||||||
|
|
||||||
|
// TODO check NULL termination!!
|
||||||
|
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@@ -463,36 +463,26 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&);
|
|||||||
// Utility functions used within wxSTC
|
// Utility functions used within wxSTC
|
||||||
|
|
||||||
#ifndef SWIG
|
#ifndef SWIG
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
|
||||||
|
wxString stc2wx(const char* str);
|
||||||
|
wxString stc2wx(const char* str, size_t len);
|
||||||
|
const wxWX2MBbuf wx2stc(const wxString& str);
|
||||||
|
|
||||||
|
#else // not UNICODE
|
||||||
|
|
||||||
inline wxString stc2wx(const char* str) {
|
inline wxString stc2wx(const char* str) {
|
||||||
#if wxUSE_UNICODE
|
|
||||||
return wxString(str, wxConvUTF8);
|
|
||||||
#else
|
|
||||||
return wxString(str);
|
return wxString(str);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
|
||||||
wxString stc2wx(const char* str, size_t len);
|
|
||||||
#else
|
|
||||||
inline wxString stc2wx(const char* str, size_t len) {
|
inline wxString stc2wx(const char* str, size_t len) {
|
||||||
return wxString(str, len);
|
return wxString(str, len);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
|
||||||
inline const wxWX2MBbuf wx2stc(const wxString& str) {
|
|
||||||
return str.mb_str(wxConvUTF8);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
inline const wxWX2MBbuf wx2stc(const wxString& str) {
|
inline const wxWX2MBbuf wx2stc(const wxString& str) {
|
||||||
return str.mbc_str();
|
return str.mbc_str();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif // UNICODE
|
||||||
|
#endif // SWIG
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
#endif
|
#endif
|
||||||
|
@@ -3109,36 +3109,26 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&);
|
|||||||
// Utility functions used within wxSTC
|
// Utility functions used within wxSTC
|
||||||
|
|
||||||
#ifndef SWIG
|
#ifndef SWIG
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
|
||||||
|
wxString stc2wx(const char* str);
|
||||||
|
wxString stc2wx(const char* str, size_t len);
|
||||||
|
const wxWX2MBbuf wx2stc(const wxString& str);
|
||||||
|
|
||||||
|
#else // not UNICODE
|
||||||
|
|
||||||
inline wxString stc2wx(const char* str) {
|
inline wxString stc2wx(const char* str) {
|
||||||
#if wxUSE_UNICODE
|
|
||||||
return wxString(str, wxConvUTF8);
|
|
||||||
#else
|
|
||||||
return wxString(str);
|
return wxString(str);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
|
||||||
wxString stc2wx(const char* str, size_t len);
|
|
||||||
#else
|
|
||||||
inline wxString stc2wx(const char* str, size_t len) {
|
inline wxString stc2wx(const char* str, size_t len) {
|
||||||
return wxString(str, len);
|
return wxString(str, len);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
|
||||||
inline const wxWX2MBbuf wx2stc(const wxString& str) {
|
|
||||||
return str.mb_str(wxConvUTF8);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
inline const wxWX2MBbuf wx2stc(const wxString& str) {
|
inline const wxWX2MBbuf wx2stc(const wxString& str) {
|
||||||
return str.mbc_str();
|
return str.mbc_str();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif // UNICODE
|
||||||
|
#endif // SWIG
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
#endif
|
#endif
|
||||||
|
@@ -1249,25 +1249,47 @@ double ElapsedTime::Duration(bool reset) {
|
|||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
#if wxUSE_UNICODE
|
||||||
|
|
||||||
|
#include "UniConversion.h"
|
||||||
|
|
||||||
|
// Convert using Scintilla's functions instead of wx's, Scintilla's are more
|
||||||
|
// forgiving and won't assert...
|
||||||
|
|
||||||
wxString stc2wx(const char* str, size_t len)
|
wxString stc2wx(const char* str, size_t len)
|
||||||
{
|
{
|
||||||
// note: we assume that str is of length len not including the terminating null.
|
|
||||||
|
|
||||||
if (!len)
|
if (!len)
|
||||||
return wxEmptyString;
|
return wxEmptyString;
|
||||||
else if (str[len-1] == 0)
|
|
||||||
// It's already terminated correctly.
|
|
||||||
return wxString(str, wxConvUTF8, len);
|
|
||||||
|
|
||||||
char *buffer=new char[len+1];
|
size_t wclen = UCS2Length(str, len);
|
||||||
strncpy(buffer, str, len);
|
wxWCharBuffer buffer(wclen+1);
|
||||||
buffer[len]=0;
|
|
||||||
|
|
||||||
wxString cstr(buffer, wxConvUTF8, len);
|
size_t actualLen = UCS2FromUTF8(str, len, buffer.data(), wclen+1);
|
||||||
|
return wxString(buffer.data(), actualLen);
|
||||||
delete[] buffer;
|
|
||||||
return cstr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
wxString stc2wx(const char* str)
|
||||||
|
{
|
||||||
|
return stc2wx(str, strlen(str));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const wxWX2MBbuf wx2stc(const wxString& str)
|
||||||
|
{
|
||||||
|
const wchar_t* wcstr = str.c_str();
|
||||||
|
size_t wclen = str.length();
|
||||||
|
size_t len = UTF8Length(wcstr, wclen);
|
||||||
|
|
||||||
|
wxCharBuffer buffer(len+1);
|
||||||
|
UTF8FromUCS2(wcstr, wclen, buffer.data(), len);
|
||||||
|
|
||||||
|
// TODO check NULL termination!!
|
||||||
|
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@@ -463,36 +463,26 @@ typedef void (wxEvtHandler::*wxStyledTextEventFunction)(wxStyledTextEvent&);
|
|||||||
// Utility functions used within wxSTC
|
// Utility functions used within wxSTC
|
||||||
|
|
||||||
#ifndef SWIG
|
#ifndef SWIG
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
|
||||||
|
wxString stc2wx(const char* str);
|
||||||
|
wxString stc2wx(const char* str, size_t len);
|
||||||
|
const wxWX2MBbuf wx2stc(const wxString& str);
|
||||||
|
|
||||||
|
#else // not UNICODE
|
||||||
|
|
||||||
inline wxString stc2wx(const char* str) {
|
inline wxString stc2wx(const char* str) {
|
||||||
#if wxUSE_UNICODE
|
|
||||||
return wxString(str, wxConvUTF8);
|
|
||||||
#else
|
|
||||||
return wxString(str);
|
return wxString(str);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
|
||||||
wxString stc2wx(const char* str, size_t len);
|
|
||||||
#else
|
|
||||||
inline wxString stc2wx(const char* str, size_t len) {
|
inline wxString stc2wx(const char* str, size_t len) {
|
||||||
return wxString(str, len);
|
return wxString(str, len);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if wxUSE_UNICODE
|
|
||||||
inline const wxWX2MBbuf wx2stc(const wxString& str) {
|
|
||||||
return str.mb_str(wxConvUTF8);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
inline const wxWX2MBbuf wx2stc(const wxString& str) {
|
inline const wxWX2MBbuf wx2stc(const wxString& str) {
|
||||||
return str.mbc_str();
|
return str.mbc_str();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
#endif // UNICODE
|
||||||
|
#endif // SWIG
|
||||||
|
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user