From 509da4510f4e8d99b0780460adf53188f72aa101 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Tue, 4 Apr 2006 13:04:47 +0000 Subject: [PATCH] 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 --- include/wx/strconv.h | 10 ++++++++-- src/common/strconv.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/include/wx/strconv.h b/include/wx/strconv.h index 61738e0cff..877c44d122 100644 --- a/include/wx/strconv.h +++ b/include/wx/strconv.h @@ -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 diff --git a/src/common/strconv.cpp b/src/common/strconv.cpp index f610bf76e0..01e0dc358c 100644 --- a/src/common/strconv.cpp +++ b/src/common/strconv.cpp @@ -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) -- 2.47.2