+
+ // buffer for holding temporary substring when using any of the methods
+ // that take (char*,size_t) or (wchar_t*,size_t) arguments:
+ // FIXME-UTF8: This will need changes when UTF8 build is introduced
+ template<typename T>
+ struct SubstrBufFromType
+ {
+ T data;
+ size_t len;
+
+ SubstrBufFromType() {}
+ SubstrBufFromType(const T& data_, size_t len_)
+ : data(data_), len(len_) {}
+ };
+
+#if wxUSE_UNICODE_UTF8
+ // FIXME-UTF8: this will have to use slightly different type
+#elif wxUSE_UNICODE_WCHAR
+ typedef SubstrBufFromType<const wchar_t*> SubstrBufFromWC;
+ typedef SubstrBufFromType<wxWCharBuffer> SubstrBufFromMB;
+#else
+ typedef SubstrBufFromType<const char*> SubstrBufFromMB;
+ typedef SubstrBufFromType<wxCharBuffer> SubstrBufFromWC;
+#endif
+
+
+ // Functions implementing primitive operations on string data; wxString
+ // methods and iterators are implemented in terms of it. The differences
+ // between UTF-8 and wchar_t* representations of the string are mostly
+ // contained here.
+
+#if wxUSE_UNICODE
+ // FIXME-UTF8: This will need changes when UTF8 build is introduced
+ static SubstrBufFromMB ConvertStr(const char *psz, size_t nLength,
+ const wxMBConv& conv);
+#else
+ static SubstrBufFromWC ConvertStr(const wchar_t *pwz, size_t nLength,
+ const wxMBConv& conv);
+#endif
+
+#if !wxUSE_UNICODE_UTF8 // wxUSE_UNICODE_WCHAR or !wxUSE_UNICODE
+ // returns C string encoded as the implementation expects:
+ #if wxUSE_UNICODE
+ static const wchar_t* ImplStr(const wchar_t* str)
+ { return str ? str : wxT(""); }
+ static const SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
+ { return SubstrBufFromWC(str, (str && n == npos) ? wxWcslen(str) : n); }
+ static wxWCharBuffer ImplStr(const char* str,
+ const wxMBConv& conv = wxConvLibc)
+ { return ConvertStr(str, npos, conv).data; }
+ static SubstrBufFromMB ImplStr(const char* str, size_t n,
+ const wxMBConv& conv = wxConvLibc)
+ { return ConvertStr(str, n, conv); }
+ #else
+ static const char* ImplStr(const char* str,
+ const wxMBConv& WXUNUSED(conv) = wxConvLibc)
+ { return str ? str : ""; }
+ static const SubstrBufFromMB ImplStr(const char* str, size_t n,
+ const wxMBConv& WXUNUSED(conv) = wxConvLibc)
+ { return SubstrBufFromMB(str, (str && n == npos) ? wxStrlen(str) : n); }
+ static wxCharBuffer ImplStr(const wchar_t* str)
+ { return ConvertStr(str, npos, wxConvLibc).data; }
+ static SubstrBufFromWC ImplStr(const wchar_t* str, size_t n)
+ { return ConvertStr(str, n, wxConvLibc); }
+ #endif
+
+ // moves the iterator to the next Unicode character
+ static void IncIter(wxStringImpl::iterator& i) { ++i; }
+ static void IncIter(wxStringImpl::const_iterator& i) { ++i; }
+ // moves the iterator to the previous Unicode character
+ static void DecIter(wxStringImpl::iterator& i) { --i; }
+ static void DecIter(wxStringImpl::const_iterator& i) { --i; }
+ // moves the iterator by n Unicode characters
+ static wxStringImpl::iterator AddToIter(wxStringImpl::iterator i, int n)
+ { return i + n; }
+ static wxStringImpl::const_iterator AddToIter(wxStringImpl::const_iterator i, int n)
+ { return i + n; }
+ // returns distance of the two iterators in Unicode characters
+ static int DiffIters(wxStringImpl::iterator i1, wxStringImpl::iterator i2)
+ { return i1 - i2; }
+ static int DiffIters(wxStringImpl::const_iterator i1, wxStringImpl::const_iterator i2)
+ { return i1 - i2; }
+
+ // encodes the character to a form used to represent it in internal
+ // representation (returns a string in UTF8 version)
+ static wxChar EncodeChar(wxUniChar ch) { return (wxChar)ch; }
+
+ // translates position index in wxString to/from index in underlying
+ // wxStringImpl:
+ static size_t PosToImpl(size_t pos) { return pos; }
+ static void PosLenToImpl(size_t pos, size_t len,
+ size_t *implPos, size_t *implLen)
+ { *implPos = pos; *implLen = len; }
+ static size_t LenToImpl(size_t len) { return len; }
+ static size_t PosFromImpl(size_t pos) { return pos; }
+
+#else // wxUSE_UNICODE_UTF8
+
+ typedef char Utf8CharBuffer[5];
+ static Utf8CharBuffer EncodeChar(wxUniChar ch);
+ // returns n copies of ch encoded in UTF-8 string
+ static wxCharBuffer EncodeNChars(size_t n, wxUniChar ch);
+
+ size_t PosToImpl(size_t pos) const
+ {
+ if ( pos == 0 || pos == npos )
+ return pos;
+ else
+ return wxStringImpl::const_iterator(begin() + pos) - m_impl.begin();
+ }
+
+ size_t PosFromImpl(size_t pos) const
+ {
+ if ( pos == 0 || pos == npos )
+ return pos;
+ else
+ return const_iterator(m_impl.begin() + pos) - begin();
+ }
+
+ // FIXME: return as-is without copying under UTF8 locale, return
+ // converted string under other locales - needs wxCharBuffer
+ // changes
+ static wxCharBuffer ImplStr(const char* str);
+
+ static wxCharBuffer ImplStr(const wchar_t* str)
+ { return wxConvUTF8.cWC2MB(str); }
+#endif // !wxUSE_UNICODE_UTF8/wxUSE_UNICODE_UTF8
+
+