Implement strtok() utility function for wide char strings that is globally available like strlenW() and lstrcpyW()
Signed-off-by: Aaro Altonen a.altonen@hotmail.com --- dlls/msvcrt/wcs.c | 16 +--------------- include/wine/unicode.h | 1 + libs/port/string.c | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c index 17d06eed3c..2ad6ed92bf 100644 --- a/dlls/msvcrt/wcs.c +++ b/dlls/msvcrt/wcs.c @@ -1616,21 +1616,7 @@ MSVCRT_wchar_t* CDECL MSVCRT_wcspbrk( const MSVCRT_wchar_t* str, const MSVCRT_wc MSVCRT_wchar_t * CDECL MSVCRT_wcstok_s( MSVCRT_wchar_t *str, const MSVCRT_wchar_t *delim, MSVCRT_wchar_t **next_token ) { - MSVCRT_wchar_t *ret; - - if (!MSVCRT_CHECK_PMT(delim != NULL)) return NULL; - if (!MSVCRT_CHECK_PMT(next_token != NULL)) return NULL; - if (!MSVCRT_CHECK_PMT(str != NULL || *next_token != NULL)) return NULL; - - if (!str) str = *next_token; - - while (*str && strchrW( delim, *str )) str++; - if (!*str) return NULL; - ret = str++; - while (*str && !strchrW( delim, *str )) str++; - if (*str) *str++ = 0; - *next_token = str; - return ret; + return strtok_sW(str, delim, next_token); }
/********************************************************************* diff --git a/include/wine/unicode.h b/include/wine/unicode.h index 8d30e9f447..3ee98c611d 100644 --- a/include/wine/unicode.h +++ b/include/wine/unicode.h @@ -89,6 +89,7 @@ extern int sprintfW( WCHAR *str, const WCHAR *format, ... ); extern int snprintfW( WCHAR *str, size_t len, const WCHAR *format, ... ); extern int vsprintfW( WCHAR *str, const WCHAR *format, va_list valist ); extern int vsnprintfW( WCHAR *str, size_t len, const WCHAR *format, va_list valist ); +extern WCHAR *strtok_sW( WCHAR *str, const WCHAR *delim, WCHAR **saveptr );
WINE_UNICODE_INLINE WCHAR tolowerW( WCHAR ch ) { diff --git a/libs/port/string.c b/libs/port/string.c index c3388bcc7d..ceb5ab67cf 100644 --- a/libs/port/string.c +++ b/libs/port/string.c @@ -528,3 +528,22 @@ int sprintfW( WCHAR *str, const WCHAR *format, ...) va_end(valist); return retval; } + +WCHAR *strtok_sW(WCHAR *str, const WCHAR *delim, WCHAR **saveptr) +{ + WCHAR *ret; + + if (delim == NULL) return NULL; + if (saveptr == NULL) return NULL; + if (str == NULL && *saveptr == NULL) return NULL; + + if (!str) str = *saveptr; + + while (*str && strchrW( delim, *str )) str++; + if (!*str) return NULL; + ret = str++; + while (*str && !strchrW( delim, *str )) str++; + if (*str) *str++ = 0; + *saveptr = str; + return ret; +}