Merge branch 'file-readall-len'
See https://github.com/wxWidgets/wxWidgets/pull/629
This commit is contained in:
@@ -73,6 +73,32 @@ namespace Catch
|
|||||||
return wxString(ucr).ToStdString(wxConvUTF8);
|
return wxString(ucr).ToStdString(wxConvUTF8);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// While this conversion already works due to the existence of the stream
|
||||||
|
// insertion operator for wxString, define a custom one making it more
|
||||||
|
// obvious when strings containing non-printable characters differ.
|
||||||
|
template <>
|
||||||
|
struct StringMaker<wxString>
|
||||||
|
{
|
||||||
|
static std::string convert(const wxString& wxs)
|
||||||
|
{
|
||||||
|
std::string s;
|
||||||
|
s.reserve(wxs.length());
|
||||||
|
for ( wxString::const_iterator i = wxs.begin();
|
||||||
|
i != wxs.end();
|
||||||
|
++i )
|
||||||
|
{
|
||||||
|
#if wxUSE_UNICODE
|
||||||
|
if ( !iswprint(*i) )
|
||||||
|
s += wxString::Format("\\u%04X", *i).ToStdString();
|
||||||
|
else
|
||||||
|
#endif // wxUSE_UNICODE
|
||||||
|
s += *i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use a different namespace for our mock ups of the real declarations in
|
// Use a different namespace for our mock ups of the real declarations in
|
||||||
|
@@ -1162,6 +1162,9 @@ public:
|
|||||||
wxString(const wxScopedWCharBuffer& buf)
|
wxString(const wxScopedWCharBuffer& buf)
|
||||||
{ assign(buf.data(), buf.length()); }
|
{ assign(buf.data(), buf.length()); }
|
||||||
|
|
||||||
|
wxString(const wxScopedCharBuffer& buf, const wxMBConv& conv)
|
||||||
|
{ assign(buf, conv); }
|
||||||
|
|
||||||
// NB: this version uses m_impl.c_str() to force making a copy of the
|
// NB: this version uses m_impl.c_str() to force making a copy of the
|
||||||
// string, so that "wxString(str.c_str())" idiom for passing strings
|
// string, so that "wxString(str.c_str())" idiom for passing strings
|
||||||
// between threads works
|
// between threads works
|
||||||
@@ -2539,6 +2542,13 @@ public:
|
|||||||
{ return assign(str.AsString()); }
|
{ return assign(str.AsString()); }
|
||||||
wxString& assign(const wxScopedCharBuffer& str)
|
wxString& assign(const wxScopedCharBuffer& str)
|
||||||
{ return assign(str.data(), str.length()); }
|
{ return assign(str.data(), str.length()); }
|
||||||
|
wxString& assign(const wxScopedCharBuffer& buf, const wxMBConv& conv)
|
||||||
|
{
|
||||||
|
SubstrBufFromMB str(ImplStr(buf.data(), buf.length(), conv));
|
||||||
|
m_impl.assign(str.data, str.len);
|
||||||
|
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
wxString& assign(const wxScopedWCharBuffer& str)
|
wxString& assign(const wxScopedWCharBuffer& str)
|
||||||
{ return assign(str.data(), str.length()); }
|
{ return assign(str.data(), str.length()); }
|
||||||
wxString& assign(const wxCStrData& str, size_t len)
|
wxString& assign(const wxCStrData& str, size_t len)
|
||||||
|
@@ -281,8 +281,7 @@ bool wxFile::ReadAll(wxString *str, const wxMBConv& conv)
|
|||||||
length -= nread;
|
length -= nread;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString strTmp(buf, conv, length);
|
str->assign(buf, conv);
|
||||||
str->swap(strTmp);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@@ -116,6 +116,16 @@ void FileTestCase::DoRoundTripTest(const wxMBConv& conv)
|
|||||||
wxString dataReadBack(buf, conv, len);
|
wxString dataReadBack(buf, conv, len);
|
||||||
CPPUNIT_ASSERT_EQUAL( data, dataReadBack );
|
CPPUNIT_ASSERT_EQUAL( data, dataReadBack );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
wxFile fin(tf.GetName(), wxFile::read);
|
||||||
|
CPPUNIT_ASSERT( fin.IsOpened() );
|
||||||
|
|
||||||
|
wxString dataReadBack;
|
||||||
|
CPPUNIT_ASSERT( fin.ReadAll(&dataReadBack, conv) );
|
||||||
|
|
||||||
|
CPPUNIT_ASSERT_EQUAL( data, dataReadBack );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_UNICODE
|
#endif // wxUSE_UNICODE
|
||||||
|
Reference in New Issue
Block a user