fixed wxStrrchr(s, '\0') bug, added const and non const versions of wxStrchr, wxStrrchr, wxStrstr, ...

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@16175 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2002-07-14 19:55:08 +00:00
parent 1fd1922a49
commit 109c7768eb
2 changed files with 42 additions and 21 deletions

View File

@ -606,7 +606,9 @@ WXDLLEXPORT int wxToupper(wxChar ch);
#ifdef wxNEED_WX_STRING_H
WXDLLEXPORT wxChar * wxStrcat(wxChar *dest, const wxChar *src);
WXDLLEXPORT wxChar * wxStrchr(const wxChar *s, wxChar c);
WXDLLEXPORT const wxChar * wxStrchr(const wxChar *s, wxChar c);
WXDLLEXPORT wxChar * wxStrchr(wxChar *s, wxChar c)
{ return (wxChar *)wxStrchr((const wxChar *)s, c); }
WXDLLEXPORT int wxStrcmp(const wxChar *s1, const wxChar *s2);
WXDLLEXPORT int wxStrcoll(const wxChar *s1, const wxChar *s2);
WXDLLEXPORT wxChar * wxStrcpy(wxChar *dest, const wxChar *src);
@ -615,10 +617,16 @@ WXDLLEXPORT size_t wxStrlen(const wxChar *s);
WXDLLEXPORT wxChar * wxStrncat(wxChar *dest, const wxChar *src, size_t n);
WXDLLEXPORT int wxStrncmp(const wxChar *s1, const wxChar *s2, size_t n);
WXDLLEXPORT wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n);
WXDLLEXPORT wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
WXDLLEXPORT wxChar * wxStrrchr(const wxChar *s, wxChar c);
WXDLLEXPORT const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept);
WXDLLEXPORT wxChar * wxStrpbrk(wxChar *s, const wxChar *accept)
{ return (wxChar *)wxStrpbrk((const wxChar *)s, accept); }
WXDLLEXPORT const wxChar * wxStrrchr(const wxChar *s, wxChar c);
WXDLLEXPORT wxChar * wxStrrchr(wxChar *s, wxChar c)
{ return (wxChar *)wxStrrchr((const wxChar *)s, c); }
WXDLLEXPORT size_t wxStrspn(const wxChar *s, const wxChar *accept);
WXDLLEXPORT wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
WXDLLEXPORT const wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle);
WXDLLEXPORT wxChar *wxStrstr(wxChar *haystack, const wxChar *needle)
{ return (wxChar *)wxStrstr((const wxChar *)haystack, needle); }
WXDLLEXPORT double wxStrtod(const wxChar *nptr, wxChar **endptr);
WXDLLEXPORT long int wxStrtol(const wxChar *nptr, wxChar **endptr, int base);
WXDLLEXPORT unsigned long int wxStrtoul(const wxChar *nptr, wxChar **endptr, int base);

View File

@ -213,10 +213,16 @@ WXDLLEXPORT wxChar * wxStrcat(wxChar *dest, const wxChar *src)
return ret;
}
WXDLLEXPORT wxChar * wxStrchr(const wxChar *s, wxChar c)
WXDLLEXPORT const wxChar * wxStrchr(const wxChar *s, wxChar c)
{
while (*s && *s != c) s++;
return (*s) ? (wxChar *)s : (wxChar *)NULL;
// be careful here as the terminating NUL makes part of the string
while ( *s != c )
{
if ( !*s++ )
return NULL;
}
return s;
}
WXDLLEXPORT int wxStrcmp(const wxChar *s1, const wxChar *s2)
@ -260,20 +266,26 @@ WXDLLEXPORT wxChar * wxStrncpy(wxChar *dest, const wxChar *src, size_t n)
return ret;
}
WXDLLEXPORT wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept)
WXDLLEXPORT const wxChar * wxStrpbrk(const wxChar *s, const wxChar *accept)
{
while (*s && !wxStrchr(accept, *s)) s++;
return (*s) ? (wxChar *)s : (wxChar *)NULL;
while (*s && !wxStrchr(accept, *s))
s++;
return *s ? s : NULL;
}
WXDLLEXPORT wxChar * wxStrrchr(const wxChar *s, wxChar c)
WXDLLEXPORT const wxChar * wxStrrchr(const wxChar *s, wxChar c)
{
wxChar *ret = (wxChar *)NULL;
while (*s) {
if (*s == c) ret = (wxChar *)s;
s++;
}
return ret;
const wxChar *ret = NULL;
do
{
if ( *s == c )
ret = s;
s++;
}
while ( *s );
return ret;
}
WXDLLEXPORT size_t wxStrspn(const wxChar *s, const wxChar *accept)
@ -283,14 +295,15 @@ WXDLLEXPORT size_t wxStrspn(const wxChar *s, const wxChar *accept)
return len;
}
WXDLLEXPORT wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle)
WXDLLEXPORT const wxChar *wxStrstr(const wxChar *haystack, const wxChar *needle)
{
wxCHECK_RET( needle, NULL, _T("NULL argument in wxStrstr") );
// VZ: this is not exactly the most efficient string search algorithm...
const size_t len = wxStrlen(needle);
wxChar *fnd;
while ( (fnd = wxStrchr(haystack, *needle)) )
while ( const wxChar *fnd = wxStrchr(haystack, *needle) )
{
if ( !wxStrncmp(fnd, needle, len) )
return fnd;
@ -298,7 +311,7 @@ WXDLLEXPORT wxChar * wxStrstr(const wxChar *haystack, const wxChar *needle)
haystack = fnd + 1;
}
return (wxChar *)NULL;
return NULL;
}
WXDLLEXPORT double wxStrtod(const wxChar *nptr, wxChar **endptr)