From 1c61fe6bafb4153f9f4fc662d80d9d95f71287d6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 13 Dec 2020 01:11:47 +0100 Subject: [PATCH] Remove wxWebResponse::AsString() conversion parameter It doesn't make much sense to specify the conversion here, it would ideally be taken from the response Content-Type header itself and currently is just assumed to be UTF-8 anyhow. Also implement fallback to Latin-1 to avoid losing the data entirely if it's not in UTF-8. --- include/wx/webrequest.h | 2 +- interface/wx/webrequest.h | 6 ++---- src/common/webrequest.cpp | 9 +++------ 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/include/wx/webrequest.h b/include/wx/webrequest.h index 65d371975c..c7a430f2c2 100644 --- a/include/wx/webrequest.h +++ b/include/wx/webrequest.h @@ -152,7 +152,7 @@ public: virtual wxString GetSuggestedFileName() const; - wxString AsString(wxMBConv* conv = NULL) const; + wxString AsString() const; bool Init(); diff --git a/interface/wx/webrequest.h b/interface/wx/webrequest.h index 777a5c4a77..8cf37b8b02 100644 --- a/interface/wx/webrequest.h +++ b/interface/wx/webrequest.h @@ -450,11 +450,9 @@ public: /** Returns all response data as a string. - @param conv wxMBConv used to convert the response to a string. - If @c NULL, the conversion will be determined by - response headers. The default is UTF-8. + This is mostly useful for debugging or diagnostics. */ - wxString AsString(wxMBConv* conv = NULL) const; + wxString AsString() const; }; /** diff --git a/src/common/webrequest.cpp b/src/common/webrequest.cpp index 943146671b..564ea457a5 100644 --- a/src/common/webrequest.cpp +++ b/src/common/webrequest.cpp @@ -345,16 +345,13 @@ wxString wxWebResponse::GetSuggestedFileName() const return suggestedFilename; } -wxString wxWebResponse::AsString(wxMBConv * conv) const +wxString wxWebResponse::AsString() const { - // TODO: try to determine encoding type from content-type header - if ( !conv ) - conv = &wxConvUTF8; - if ( m_request.GetStorage() == wxWebRequest::Storage_Memory ) { + // TODO: try to determine encoding type from content-type header size_t outLen = 0; - return conv->cMB2WC((const char*)m_readBuffer.GetData(), m_readBuffer.GetDataLen(), &outLen); + return wxConvWhateverWorks.cMB2WC((const char*)m_readBuffer.GetData(), m_readBuffer.GetDataLen(), &outLen); } else return wxString();