+ // although new conversion classes are supposed to implement this function
+ // directly, the existins ones only implement the old MB2WC() and so, to
+ // avoid to have to rewrite all conversion classes at once, we provide a
+ // default (but not efficient) implementation of this one in terms of the
+ // old function by copying the input to ensure that it's NUL-terminated and
+ // then using MB2WC() to convert it
+
+ // the number of chars [which would be] written to dst [if it were not NULL]
+ size_t dstWritten = 0;
+
+ // the number of NULs terminating this string
+ size_t nulLen = 0; // not really needed, but just to avoid warnings
+
+ // if we were not given the input size we just have to assume that the
+ // string is properly terminated as we have no way of knowing how long it
+ // is anyhow, but if we do have the size check whether there are enough
+ // NULs at the end
+ wxCharBuffer bufTmp;
+ const char *srcEnd;
+ if ( srcLen != wxNO_LEN )
+ {
+ // we need to know how to find the end of this string
+ nulLen = GetMBNulLen();
+ if ( nulLen == wxCONV_FAILED )
+ return wxCONV_FAILED;
+
+ // if there are enough NULs we can avoid the copy
+ if ( srcLen < nulLen || NotAllNULs(src + srcLen - nulLen, nulLen) )
+ {
+ // make a copy in order to properly NUL-terminate the string
+ bufTmp = wxCharBuffer(srcLen + nulLen - 1 /* 1 will be added */);
+ char * const p = bufTmp.data();
+ memcpy(p, src, srcLen);
+ for ( char *s = p + srcLen; s < p + srcLen + nulLen; s++ )
+ *s = '\0';
+
+ src = bufTmp;
+ }