+ if (s.Len() < min_width)
+ s.Pad(min_width - s.Len(), wxT(' '), adj_left);
+ *this += s;
+ } else {
+ wxChar *val = va_arg(argptr, wxChar *);
+ size_t len = wxSTRING_MAXLEN;
+ if (val) {
+ for (len = 0; val[len] && (len<max_width); len++);
+ } else val = wxT("(null)");
+ wxString s(val, len);
+ if (s.Len() < min_width)
+ s.Pad(min_width - s.Len(), wxT(' '), adj_left);
+ *this += s;
+ }
+ done = TRUE;
+ break;
+ case wxT('n'):
+ if (ilen == 0) {
+ int *val = va_arg(argptr, int *);
+ *val = Len();
+ }
+ else if (ilen == -1) {
+ short int *val = va_arg(argptr, short int *);
+ *val = Len();
+ }
+ else if (ilen >= 1) {
+ long int *val = va_arg(argptr, long int *);
+ *val = Len();
+ }
+ done = TRUE;
+ break;
+ default:
+ if (wxIsalpha(pszFormat[n]))
+ // probably some flag not taken care of here yet
+ s_szFlags[flagofs++] = pszFormat[n];
+ else {
+ // bad format
+ *this += wxT('%'); // just to pass the glibc tst-printf.c
+ n--;
+ done = TRUE;
+ }
+ break;
+ }
+#undef CHECK_PREC
+ } while (!done);
+ } else *this += pszFormat[n];
+
+#else
+ // buffer to avoid dynamic memory allocation each time for small strings
+ char szScratch[1024];
+
+ // NB: wxVsnprintf() may return either less than the buffer size or -1 if
+ // there is not enough place depending on implementation
+ int iLen = wxVsnprintfA(szScratch, WXSIZEOF(szScratch), (char *)pszFormat, argptr);
+ if ( iLen != -1 ) {
+ // the whole string is in szScratch
+ *this = szScratch;
+ }
+ else {
+ bool outOfMemory = FALSE;
+ int size = 2*WXSIZEOF(szScratch);
+ while ( !outOfMemory ) {
+ char *buf = GetWriteBuf(size);
+ if ( buf )
+ iLen = wxVsnprintfA(buf, size, pszFormat, argptr);
+ else
+ outOfMemory = TRUE;
+
+ UngetWriteBuf();
+
+ if ( iLen != -1 ) {
+ // ok, there was enough space
+ break;
+ }
+
+ // still not enough, double it again
+ size *= 2;
+ }
+
+ if ( outOfMemory ) {
+ // out of memory
+ return -1;
+ }
+ }
+#endif // wxUSE_EXPERIMENTAL_PRINTF/!wxUSE_EXPERIMENTAL_PRINTF
+
+ return Len();
+}
+
+// ----------------------------------------------------------------------------
+// misc other operations
+// ----------------------------------------------------------------------------
+
+// returns TRUE if the string matches the pattern which may contain '*' and
+// '?' metacharacters (as usual, '?' matches any character and '*' any number
+// of them)
+bool wxString::Matches(const wxChar *pszMask) const
+{
+#if wxUSE_REGEX
+ // first translate the shell-like mask into a regex
+ wxString pattern;
+ pattern.reserve(wxStrlen(pszMask));
+
+ pattern += _T('^');
+ while ( *pszMask )
+ {
+ switch ( *pszMask )
+ {
+ case _T('?'):
+ pattern += _T('.');
+ break;
+
+ case _T('*'):
+ pattern += _T(".*");
+ break;
+
+ case _T('^'):
+ case _T('.'):
+ case _T('$'):
+ case _T('('):
+ case _T(')'):
+ case _T('|'):
+ case _T('+'):
+ case _T('\\'):
+ // these characters are special in a RE, quote them
+ // (however note that we don't quote '[' and ']' to allow
+ // using them for Unix shell like matching)
+ pattern += _T('\\');
+ // fall through
+
+ default:
+ pattern += *pszMask;
+ }
+
+ pszMask++;
+ }
+ pattern += _T('$');
+
+ // and now use it
+ return wxRegEx(pattern, wxRE_NOSUB | wxRE_EXTENDED).Matches(c_str());
+#else // !wxUSE_REGEX
+ // TODO: this is, of course, awfully inefficient...
+
+ // the char currently being checked
+ const wxChar *pszTxt = c_str();
+
+ // the last location where '*' matched
+ const wxChar *pszLastStarInText = NULL;
+ const wxChar *pszLastStarInMask = NULL;
+
+match:
+ for ( ; *pszMask != wxT('\0'); pszMask++, pszTxt++ ) {
+ switch ( *pszMask ) {
+ case wxT('?'):
+ if ( *pszTxt == wxT('\0') )
+ return FALSE;
+
+ // pszTxt and pszMask will be incremented in the loop statement
+
+ break;
+
+ case wxT('*'):
+ {
+ // remember where we started to be able to backtrack later
+ pszLastStarInText = pszTxt;
+ pszLastStarInMask = pszMask;
+
+ // ignore special chars immediately following this one
+ // (should this be an error?)
+ while ( *pszMask == wxT('*') || *pszMask == wxT('?') )
+ pszMask++;
+
+ // if there is nothing more, match
+ if ( *pszMask == wxT('\0') )
+ return TRUE;
+
+ // are there any other metacharacters in the mask?
+ size_t uiLenMask;
+ const wxChar *pEndMask = wxStrpbrk(pszMask, wxT("*?"));
+
+ if ( pEndMask != NULL ) {
+ // we have to match the string between two metachars
+ uiLenMask = pEndMask - pszMask;
+ }
+ else {
+ // we have to match the remainder of the string
+ uiLenMask = wxStrlen(pszMask);
+ }
+
+ wxString strToMatch(pszMask, uiLenMask);
+ const wxChar* pMatch = wxStrstr(pszTxt, strToMatch);
+ if ( pMatch == NULL )
+ return FALSE;
+
+ // -1 to compensate "++" in the loop
+ pszTxt = pMatch + uiLenMask - 1;
+ pszMask += uiLenMask - 1;
+ }
+ break;
+
+ default:
+ if ( *pszMask != *pszTxt )
+ return FALSE;
+ break;
+ }
+ }
+
+ // match only if nothing left
+ if ( *pszTxt == wxT('\0') )
+ return TRUE;
+
+ // if we failed to match, backtrack if we can
+ if ( pszLastStarInText ) {
+ pszTxt = pszLastStarInText + 1;
+ pszMask = pszLastStarInMask;
+
+ pszLastStarInText = NULL;
+
+ // don't bother resetting pszLastStarInMask, it's unnecessary
+
+ goto match;
+ }
+
+ return FALSE;
+#endif // wxUSE_REGEX/!wxUSE_REGEX
+}
+
+// Count the number of chars
+int wxString::Freq(wxChar ch) const
+{
+ int count = 0;
+ int len = Len();
+ for (int i = 0; i < len; i++)
+ {
+ if (GetChar(i) == ch)
+ count ++;
+ }
+ return count;