2000-06-09 07:27:21 +02:00
|
|
|
/*
|
|
|
|
* Wine internal Unicode definitions
|
|
|
|
*
|
|
|
|
* Copyright 2000 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2000-06-09 07:27:21 +02:00
|
|
|
*/
|
|
|
|
|
2006-05-25 20:07:57 +02:00
|
|
|
#ifndef __WINE_WINE_UNICODE_H
|
|
|
|
#define __WINE_WINE_UNICODE_H
|
2000-06-09 07:27:21 +02:00
|
|
|
|
2003-06-27 21:02:23 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
|
2003-08-28 23:43:34 +02:00
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <winnls.h>
|
2020-11-29 21:35:16 +01:00
|
|
|
#include <winternl.h>
|
2000-06-12 03:16:11 +02:00
|
|
|
|
2019-04-01 12:21:25 +02:00
|
|
|
#ifdef __WINE_USE_MSVCRT
|
|
|
|
#error This file should not be used with msvcrt headers
|
|
|
|
#endif
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
#ifndef WINE_UNICODE_INLINE
|
2020-11-29 21:21:49 +01:00
|
|
|
#define WINE_UNICODE_INLINE static FORCEINLINE
|
2007-02-23 20:40:09 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
WINE_UNICODE_INLINE WCHAR tolowerW( WCHAR ch )
|
2000-06-12 03:16:11 +02:00
|
|
|
{
|
2020-11-29 21:35:16 +01:00
|
|
|
return RtlDowncaseUnicodeChar( ch );
|
2000-06-12 03:16:11 +02:00
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE WCHAR toupperW( WCHAR ch )
|
2000-06-12 03:16:11 +02:00
|
|
|
{
|
2020-11-29 21:35:16 +01:00
|
|
|
return RtlUpcaseUnicodeChar( ch );
|
2000-06-12 03:16:11 +02:00
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int isspaceW( WCHAR wc )
|
2001-11-08 20:16:34 +01:00
|
|
|
{
|
2020-12-02 12:19:09 +01:00
|
|
|
unsigned short type;
|
|
|
|
GetStringTypeW( CT_CTYPE1, &wc, 1, &type );
|
|
|
|
return type & C1_SPACE;
|
2001-11-08 20:16:34 +01:00
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE unsigned int strlenW( const WCHAR *str )
|
2000-06-10 06:29:16 +02:00
|
|
|
{
|
2000-06-12 03:16:11 +02:00
|
|
|
const WCHAR *s = str;
|
2000-06-10 06:29:16 +02:00
|
|
|
while (*s) s++;
|
|
|
|
return s - str;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE WCHAR *strcpyW( WCHAR *dst, const WCHAR *src )
|
2000-06-12 03:16:11 +02:00
|
|
|
{
|
|
|
|
WCHAR *p = dst;
|
|
|
|
while ((*p++ = *src++));
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE WCHAR *strcatW( WCHAR *dst, const WCHAR *src )
|
2000-06-12 03:16:11 +02:00
|
|
|
{
|
|
|
|
strcpyW( dst + strlenW(dst), src );
|
|
|
|
return dst;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE WCHAR *strrchrW( const WCHAR *str, WCHAR ch )
|
2000-08-02 01:33:37 +02:00
|
|
|
{
|
|
|
|
WCHAR *ret = NULL;
|
2007-07-04 21:53:40 +02:00
|
|
|
do { if (*str == ch) ret = (WCHAR *)(ULONG_PTR)str; } while (*str++);
|
2000-08-02 01:33:37 +02:00
|
|
|
return ret;
|
2002-06-01 01:06:46 +02:00
|
|
|
}
|
2000-06-12 03:16:11 +02:00
|
|
|
|
2020-11-28 21:49:20 +01:00
|
|
|
WINE_UNICODE_INLINE int strcmpiW( const WCHAR *str1, const WCHAR *str2 )
|
|
|
|
{
|
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
int ret = tolowerW(*str1) - tolowerW(*str2);
|
|
|
|
if (ret || !*str1) return ret;
|
|
|
|
str1++;
|
|
|
|
str2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WINE_UNICODE_INLINE int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n )
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
for ( ; n > 0; n--, str1++, str2++)
|
|
|
|
if ((ret = tolowerW(*str1) - tolowerW(*str2)) || !*str1) break;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
WINE_UNICODE_INLINE LONG strtolW( LPCWSTR s, LPWSTR *end, INT base )
|
|
|
|
{
|
|
|
|
BOOL negative = FALSE, empty = TRUE;
|
|
|
|
LONG ret = 0;
|
|
|
|
|
|
|
|
if (base < 0 || base == 1 || base > 36) return 0;
|
|
|
|
if (end) *end = (WCHAR *)s;
|
|
|
|
while (isspaceW(*s)) s++;
|
|
|
|
|
|
|
|
if (*s == '-')
|
|
|
|
{
|
|
|
|
negative = TRUE;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
else if (*s == '+') s++;
|
|
|
|
|
|
|
|
if ((base == 0 || base == 16) && s[0] == '0' && (s[1] == 'x' || s[1] == 'X'))
|
|
|
|
{
|
|
|
|
base = 16;
|
|
|
|
s += 2;
|
|
|
|
}
|
|
|
|
if (base == 0) base = s[0] != '0' ? 10 : 8;
|
|
|
|
|
|
|
|
while (*s)
|
|
|
|
{
|
|
|
|
int v;
|
|
|
|
|
|
|
|
if ('0' <= *s && *s <= '9') v = *s - '0';
|
|
|
|
else if ('A' <= *s && *s <= 'Z') v = *s - 'A' + 10;
|
|
|
|
else if ('a' <= *s && *s <= 'z') v = *s - 'a' + 10;
|
|
|
|
else break;
|
|
|
|
if (v >= base) break;
|
|
|
|
if (negative) v = -v;
|
|
|
|
s++;
|
|
|
|
empty = FALSE;
|
|
|
|
|
|
|
|
if (!negative && (ret > MAXLONG / base || ret * base > MAXLONG - v))
|
|
|
|
ret = MAXLONG;
|
|
|
|
else if (negative && (ret < (LONG)MINLONG / base || ret * base < (LONG)(MINLONG - v)))
|
|
|
|
ret = MINLONG;
|
|
|
|
else
|
|
|
|
ret = ret * base + v;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (end && !empty) *end = (WCHAR *)s;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-11-29 21:21:49 +01:00
|
|
|
NTSYSAPI int __cdecl _vsnwprintf(WCHAR*,size_t,const WCHAR*,__ms_va_list);
|
|
|
|
|
|
|
|
static inline int WINAPIV snprintfW( WCHAR *str, size_t len, const WCHAR *format, ...)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
__ms_va_list valist;
|
|
|
|
__ms_va_start(valist, format);
|
|
|
|
retval = _vsnwprintf(str, len, format, valist);
|
|
|
|
__ms_va_end(valist);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int WINAPIV sprintfW( WCHAR *str, const WCHAR *format, ...)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
__ms_va_list valist;
|
|
|
|
__ms_va_start(valist, format);
|
|
|
|
retval = _vsnwprintf(str, MAXLONG, format, valist);
|
|
|
|
__ms_va_end(valist);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
#undef WINE_UNICODE_INLINE
|
|
|
|
|
2006-05-25 20:07:57 +02:00
|
|
|
#endif /* __WINE_WINE_UNICODE_H */
|