IMPLEMENT_DYNAMIC_CLASS(wxString, wxObject)
#endif //WXSTRING_IS_WXOBJECT
+#if wxUSE_UNICODE
+#undef wxUSE_EXPERIMENTAL_PRINTF
+#define wxUSE_EXPERIMENTAL_PRINTF 1
+#endif
+
// allocating extra space for each string consumes more memory but speeds up
// the concatenation operations (nLen is the current string's length)
// NB: EXTRA_ALLOC must be >= 0!
// conditional compilation
// ----------------------------------------------------------------------------
+#if !defined(__WXSW__) && wxUSE_UNICODE
+ #ifdef wxUSE_EXPERIMENTAL_PRINTF
+ #undef wxUSE_EXPERIMENTAL_PRINTF
+ #endif
+ #define wxUSE_EXPERIMENTAL_PRINTF 1
+#endif
+
// we want to find out if the current platform supports vsnprintf()-like
// function: for Unix this is done with configure, for Windows we test the
// compiler explicitly.
int wxString::PrintfV(const wxChar* pszFormat, va_list argptr)
{
// static buffer to avoid dynamic memory allocation each time
- static char s_szScratch[1024];
+ char s_szScratch[1024]; // using static buffer causes internal compiler err
+#if 0
#if wxUSE_THREADS
// protect the static buffer
static wxCriticalSection critsect;
wxCriticalSectionLocker lock(critsect);
#endif
+#endif
-#if 1 // the new implementation
+#if wxUSE_EXPERIMENTAL_PRINTF
+// the new implementation
Reinit();
for (size_t n = 0; pszFormat[n]; n++)
wxASSERT( str.GetStringData()->IsValid() );
wxASSERT( nStart <= Len() );
- // # could be quicker than that
+ // TODO could be made much quicker than that
const wxChar *p = c_str() + (nStart == npos ? Len() : nStart);
while ( p >= c_str() + str.Len() ) {
if ( wxStrncmp(p - str.Len(), str, str.Len()) == 0 )
#if !defined(__VISUALC__) || defined(__WIN32__)
size_t wxString::rfind(const wxChar* sz, size_t nStart, size_t n) const
{
- return rfind(wxString(sz, n == npos ? 0 : n), nStart);
+ return rfind(wxString(sz, n == npos ? 0 : n), nStart);
}
size_t wxString::rfind(wxChar ch, size_t nStart) const
{
- wxASSERT( nStart <= Len() );
+ if ( nStart == npos )
+ {
+ nStart = Len();
+ }
+ else
+ {
+ wxASSERT( nStart <= Len() );
+ }
- const wxChar *p = wxStrrchr(c_str() + nStart, ch);
+ const wxChar *p = wxStrrchr(c_str(), ch);
- return p == NULL ? npos : p - c_str();
+ if ( p == NULL )
+ return npos;
+
+ size_t result = p - c_str();
+ return ( result > nStart ) ? npos : result;
}
#endif // VC++ 1.5
+size_t wxString::find_first_of(const wxChar* sz, size_t nStart) const
+{
+ const wxChar *start = c_str() + nStart;
+ const wxChar *firstOf = wxStrpbrk(start, sz);
+ if ( firstOf )
+ return firstOf - start;
+ else
+ return npos;
+}
+
+size_t wxString::find_last_of(const wxChar* sz, size_t nStart) const
+{
+ if ( nStart == npos )
+ {
+ nStart = Len();
+ }
+ else
+ {
+ wxASSERT( nStart <= Len() );
+ }
+
+ for ( const wxChar *p = c_str() + length() - 1; p >= c_str(); p-- )
+ {
+ if ( wxStrchr(sz, *p) )
+ return p - c_str();
+ }
+
+ return npos;
+}
+
+size_t wxString::find_first_not_of(const wxChar* sz, size_t nStart) const
+{
+ if ( nStart == npos )
+ {
+ nStart = Len();
+ }
+ else
+ {
+ wxASSERT( nStart <= Len() );
+ }
+
+ size_t nAccept = wxStrspn(c_str() + nStart, sz);
+ if ( nAccept >= length() - nStart )
+ return npos;
+ else
+ return nAccept;
+}
+
+size_t wxString::find_first_not_of(wxChar ch, size_t nStart) const
+{
+ wxASSERT( nStart <= Len() );
+
+ for ( const wxChar *p = c_str() + nStart; *p; p++ )
+ {
+ if ( *p != ch )
+ return p - c_str();
+ }
+
+ return npos;
+}
+
+size_t wxString::find_last_not_of(const wxChar* sz, size_t nStart) const
+{
+ if ( nStart == npos )
+ {
+ nStart = Len();
+ }
+ else
+ {
+ wxASSERT( nStart <= Len() );
+ }
+
+ for ( const wxChar *p = c_str() + nStart - 1; p >= c_str(); p-- )
+ {
+ if ( !wxStrchr(sz, *p) )
+ return p - c_str();
+ }
+
+ return npos;
+}
+
+size_t wxString::find_last_not_of(wxChar ch, size_t nStart) const
+{
+ if ( nStart == npos )
+ {
+ nStart = Len();
+ }
+ else
+ {
+ wxASSERT( nStart <= Len() );
+ }
+
+ for ( const wxChar *p = c_str() + nStart - 1; p >= c_str(); p-- )
+ {
+ if ( *p != ch )
+ return p - c_str();
+ }
+
+ return npos;
+}
+
wxString wxString::substr(size_t nStart, size_t nLen) const
{
// npos means 'take all'
#endif
// TODO: write actual implementations of UTF-7 here
-size_t wxMBConvUTF7::MB2WC(wchar_t *buf, const char *psz, size_t n) const
+size_t wxMBConvUTF7::MB2WC(wchar_t * WXUNUSED(buf),
+ const char * WXUNUSED(psz),
+ size_t WXUNUSED(n)) const
{
return 0;
}
-size_t wxMBConvUTF7::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+size_t wxMBConvUTF7::WC2MB(char * WXUNUSED(buf),
+ const wchar_t * WXUNUSED(psz),
+ size_t WXUNUSED(n)) const
{
return 0;
}
if (already_loaded) return;
already_loaded = TRUE;
-#if defined(__UNIX__)
+#if defined(__UNIX__) && wxUSE_TEXTFILE
// search through files in /usr/share/i18n/charmaps
wxString fname;
for (fname = ::wxFindFirstFile(_T("/usr/share/i18n/charmaps/*"));
wxString uni = token.GetNextToken();
// skip whitespace again
while (wxIsEmpty(uni) && token.HasMoreTokens()) uni = token.GetNextToken();
-
- if ((hex.Len() > 2) && (hex.GetChar(0) == escchar) && (hex.GetChar(1) == _T('x')) &&
+ if ((hex.Len() > 2) && (wxString(hex.GetChar(0)) == escchar) && (hex.GetChar(1) == _T('x')) &&
(uni.Left(2) == _T("<U"))) {
hex.MakeUpper(); uni.MakeUpper();
int pos = ::wxHexToDec(hex.Mid(2,2));