MB2WC/WC2MB are not pure virtual any longer, implement them in terms of To/FromWChar()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38542 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2006-04-04 13:04:47 +00:00
parent 483b0434bf
commit 509da4510f
2 changed files with 32 additions and 2 deletions

View File

@@ -35,6 +35,12 @@
// wxMBConv (abstract base class for conversions)
// ----------------------------------------------------------------------------
// When deriving a new class from wxMBConv you must reimplement ToWChar() and
// FromWChar() methods which are not pure virtual only for historical reasons,
// don't let the fact that the existing classes implement MB2WC/WC2MB() instead
// confuse you.
//
// And you might need to override GetMBNulLen() as well.
class WXDLLIMPEXP_BASE wxMBConv
{
public:
@@ -137,8 +143,8 @@ public:
// Note that outLen is the length of the output buffer, not the length of
// the input (which is always supposed to be terminated by one or more
// NULs, as appropriate for the encoding)!
virtual size_t MB2WC(wchar_t *out, const char *in, size_t outLen) const = 0;
virtual size_t WC2MB(char *out, const wchar_t *in, size_t outLen) const = 0;
virtual size_t MB2WC(wchar_t *out, const char *in, size_t outLen) const;
virtual size_t WC2MB(char *out, const wchar_t *in, size_t outLen) const;
// virtual dtor for any base class

View File

@@ -316,6 +316,30 @@ wxMBConv::FromWChar(char *dst, size_t dstLen,
return dstWritten;
}
size_t wxMBConv::MB2WC(wchar_t *out, const char *in, size_t outLen) const
{
size_t rc = ToWChar(out, outLen, in);
if ( rc != wxCONV_FAILED )
{
// ToWChar() returns the buffer length, i.e. including the trailing
// NUL, while this method doesn't take it into account
rc--;
}
return rc;
}
size_t wxMBConv::WC2MB(char *out, const wchar_t *in, size_t outLen) const
{
size_t rc = FromWChar(out, outLen, in);
if ( rc != wxCONV_FAILED )
{
rc -= GetMBNulLen();
}
return rc;
}
wxMBConv::~wxMBConv()
{
// nothing to do here (necessary for Darwin linking probably)