- wxASSERT(pOutSize != NULL);
-
- const char* szEnd = szString + nStringLen + 1;
- const char* szPos = szString;
- const char* szStart = szPos;
-
- size_t nActualLength = 0;
- size_t nCurrentSize = nStringLen; //try normal size first (should never resize?)
-
- wxWCharBuffer theBuffer(nCurrentSize);
+ // the currently accumulated wide characters
+ wxWCharBuffer wbuf;
+
+ // the current length of wbuf
+ size_t lenBuf = 0;
+
+ // we need to know the representation of L'\0' for this conversion
+ size_t nulLen;
+ const char * const nul = GetMBNul(&nulLen);
+ if ( nulLen == (size_t)-1 || nulLen == 0 )
+ return wxWCharBuffer();
+
+ // make a copy of the input string unless it is already properly
+ // NUL-terminated
+ wxCharBuffer bufTmp;
+
+ // now we can compute the input size if we were not given it: notice that
+ // in this case the string must be properly NUL-terminated, of course, as
+ // otherwise we have no way of knowing how long it is
+ if ( inLen == (size_t)-1 )
+ {
+ // not the most efficient algorithm but it shouldn't matter as normally
+ // there are not many NULs in the string and so normally memcmp()
+ // should stop on the first character
+ for ( const char *p = in; ; p++ )
+ {
+ if ( memcmp(p, nul, nulLen) == 0 )
+ break;
+ }