diff --git a/docs/changes.txt b/docs/changes.txt index 740b6fa096..ccd78eff58 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -97,8 +97,8 @@ All: - Fix wxStringOutputStream::Write() in Unicode build when the argument overlaps UTF-8 characters boundary - Account for lines without newline at the end in wxExecute() -- Added wxString::char_str() and wchar_str() methods for forward - compatiblity with wxWidgets 3 +- Added wxString::char_str(), wchar_str(), From8BitData() and To8BitData() + methods for forward compatiblity with wxWidgets 3 All (Unix): diff --git a/docs/latex/wx/wxstring.tex b/docs/latex/wx/wxstring.tex index b8c3091f56..c3d8bd01f6 100644 --- a/docs/latex/wx/wxstring.tex +++ b/docs/latex/wx/wxstring.tex @@ -749,6 +749,24 @@ Returns the number of occurrences of {\it ch} in the string. This is a wxWidgets 1.xx compatibility function; you should not use it in new code. +\membersection{wxString::From8BitData}\label{wxstringfrom8bitdata} + +\func{static wxString }{From8BitData}{\param{const char*}{ buf}, \param{size\_t}{len}} + +\func{static wxString }{From8BitData}{\param{const char*}{ buf}} + +Converts given buffer of binary data from 8-bit string to wxString. In Unicode +build, the string is interpreted as being in ISO-8859-1 encoding. The version +without \arg{len} parameter takes NUL-terminated data. + +This is a convenience method useful when storing binary data in wxString. + +\newsince{2.8.4} + +\wxheading{See also} + +\helpref{To8BitData}{wxstringto8bitdata} + \membersection{wxString::FromAscii}\label{wxstringfromascii} @@ -1122,6 +1140,26 @@ This is a wxWidgets 1.xx compatibility function, use \helpref{Mid}{wxstringmid} instead (but note that parameters have different meaning). +\membersection{wxString::To8BitData}\label{wxstringto8bitdata} + +\constfunc{const char*}{To8BitData}{\void} + +Converts the string to an 8-bit string (ANSI builds only). + +\constfunc{const wxCharBuffer}{To8BitData}{\void} + +Converts the string to an 8-bit string in ISO-8859-1 encoding in the form of +a wxCharBuffer (Unicode builds only). + +This is a convenience method useful when storing binary data in wxString. + +\newsince{2.8.4} + +\wxheading{See also} + +\helpref{From8BitData}{wxstringfrom8bitdata} + + \membersection{wxString::ToAscii}\label{wxstringtoascii} \constfunc{const char*}{ToAscii}{\void} diff --git a/include/wx/string.h b/include/wx/string.h index 1c5f303b90..cf081fd7de 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -863,6 +863,25 @@ public: const char *ToAscii() const { return c_str(); } #endif // Unicode/!Unicode +#if wxABI_VERSION >= 20804 + // functions for storing binary data in wxString: +#if wxUSE_UNICODE + static wxString From8BitData(const char *data, size_t len) + { return wxString(data, wxConvISO8859_1, len); } + // version for NUL-terminated data: + static wxString From8BitData(const char *data) + { return wxString(data, wxConvISO8859_1); } + const wxCharBuffer To8BitData() const { return mb_str(wxConvISO8859_1); } +#else // ANSI + static wxString From8BitData(const char *data, size_t len) + { return wxString(data, len); } + // version for NUL-terminated data: + static wxString From8BitData(const char *data) + { return wxString(data); } + const char *To8BitData() const { return c_str(); } +#endif // Unicode/ANSI +#endif // wxABI_VERSION >= 20804 + // conversions with (possible) format conversions: have to return a // buffer with temporary data // diff --git a/version-script.in b/version-script.in index 43e9c4bc35..6f51b00728 100644 --- a/version-script.in +++ b/version-script.in @@ -27,6 +27,9 @@ # public symbols added in 2.8.4 (please keep in alphabetical order): @WX_VERSION_TAG@.4 { global: + # wxString::To/From8BitData() + *wxString*To8BitData*; + *wxString*From8BitData*; # wxString::[w]char_str() *wxString*char_str*; # wxWritable[W]CharBuffer