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>
|
2000-06-12 03:16:11 +02:00
|
|
|
|
2006-05-25 20:07:57 +02:00
|
|
|
#ifdef __WINE_WINE_TEST_H
|
|
|
|
#error This file should not be used in Wine tests
|
|
|
|
#endif
|
|
|
|
|
2008-11-06 10:43:31 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2003-12-13 01:02:31 +01:00
|
|
|
#ifndef WINE_UNICODE_API
|
2007-11-07 12:30:51 +01:00
|
|
|
# if defined(_MSC_VER) || defined(__MINGW32__)
|
|
|
|
# define WINE_UNICODE_API DECLSPEC_IMPORT
|
|
|
|
# else
|
|
|
|
# define WINE_UNICODE_API
|
|
|
|
# endif
|
2003-12-13 01:02:31 +01:00
|
|
|
#endif
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
#ifndef WINE_UNICODE_INLINE
|
2010-04-15 11:56:32 +02:00
|
|
|
#define WINE_UNICODE_INLINE static inline
|
2007-02-23 20:40:09 +01:00
|
|
|
#endif
|
|
|
|
|
2000-06-09 07:27:21 +02:00
|
|
|
/* code page info common to SBCS and DBCS */
|
|
|
|
struct cp_info
|
|
|
|
{
|
|
|
|
unsigned int codepage; /* codepage id */
|
|
|
|
unsigned int char_size; /* char size (1 or 2 bytes) */
|
2000-06-12 03:16:11 +02:00
|
|
|
WCHAR def_char; /* default char value (can be double-byte) */
|
|
|
|
WCHAR def_unicode_char; /* default Unicode char value */
|
2000-06-09 07:27:21 +02:00
|
|
|
const char *name; /* code page name */
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sbcs_table
|
|
|
|
{
|
|
|
|
struct cp_info info;
|
2000-06-12 03:16:11 +02:00
|
|
|
const WCHAR *cp2uni; /* code page -> Unicode map */
|
2007-05-29 23:31:14 +02:00
|
|
|
const WCHAR *cp2uni_glyphs; /* code page -> Unicode map with glyph chars */
|
2000-06-09 07:27:21 +02:00
|
|
|
const unsigned char *uni2cp_low; /* Unicode -> code page map */
|
|
|
|
const unsigned short *uni2cp_high;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct dbcs_table
|
|
|
|
{
|
|
|
|
struct cp_info info;
|
2000-06-12 03:16:11 +02:00
|
|
|
const WCHAR *cp2uni; /* code page -> Unicode map */
|
2000-06-09 07:27:21 +02:00
|
|
|
const unsigned char *cp2uni_leadbytes;
|
|
|
|
const unsigned short *uni2cp_low; /* Unicode -> code page map */
|
|
|
|
const unsigned short *uni2cp_high;
|
|
|
|
unsigned char lead_bytes[12]; /* lead bytes ranges */
|
|
|
|
};
|
|
|
|
|
|
|
|
union cptable
|
|
|
|
{
|
|
|
|
struct cp_info info;
|
|
|
|
struct sbcs_table sbcs;
|
|
|
|
struct dbcs_table dbcs;
|
|
|
|
};
|
|
|
|
|
2003-03-21 22:30:51 +01:00
|
|
|
extern const union cptable *wine_cp_get_table( unsigned int codepage );
|
|
|
|
extern const union cptable *wine_cp_enum_table( unsigned int index );
|
|
|
|
|
|
|
|
extern int wine_cp_mbstowcs( const union cptable *table, int flags,
|
|
|
|
const char *src, int srclen,
|
|
|
|
WCHAR *dst, int dstlen );
|
|
|
|
extern int wine_cp_wcstombs( const union cptable *table, int flags,
|
|
|
|
const WCHAR *src, int srclen,
|
|
|
|
char *dst, int dstlen, const char *defchar, int *used );
|
2004-01-20 23:39:06 +01:00
|
|
|
extern int wine_cpsymbol_mbstowcs( const char *src, int srclen, WCHAR *dst, int dstlen );
|
|
|
|
extern int wine_cpsymbol_wcstombs( const WCHAR *src, int srclen, char *dst, int dstlen );
|
2003-03-21 22:30:51 +01:00
|
|
|
extern int wine_utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int dstlen );
|
2007-03-14 15:57:50 +01:00
|
|
|
extern int wine_utf8_wcstombs( int flags, const WCHAR *src, int srclen, char *dst, int dstlen );
|
2000-06-10 06:29:16 +02:00
|
|
|
|
2003-11-22 01:00:53 +01:00
|
|
|
extern int wine_compare_string( int flags, const WCHAR *str1, int len1, const WCHAR *str2, int len2 );
|
2003-06-27 21:02:23 +02:00
|
|
|
extern int wine_get_sortkey( int flags, const WCHAR *src, int srclen, char *dst, int dstlen );
|
2003-10-15 22:52:28 +02:00
|
|
|
extern int wine_fold_string( int flags, const WCHAR *src, int srclen , WCHAR *dst, int dstlen );
|
2003-06-27 21:02:23 +02:00
|
|
|
|
2002-05-16 20:58:47 +02:00
|
|
|
extern int strcmpiW( const WCHAR *str1, const WCHAR *str2 );
|
|
|
|
extern int strncmpiW( const WCHAR *str1, const WCHAR *str2, int n );
|
2004-04-02 21:40:31 +02:00
|
|
|
extern int memicmpW( const WCHAR *str1, const WCHAR *str2, int n );
|
2002-05-16 20:58:47 +02:00
|
|
|
extern WCHAR *strstrW( const WCHAR *str, const WCHAR *sub );
|
|
|
|
extern long int strtolW( const WCHAR *nptr, WCHAR **endptr, int base );
|
|
|
|
extern unsigned long int strtoulW( const WCHAR *nptr, WCHAR **endptr, int base );
|
2003-03-21 00:40:41 +01:00
|
|
|
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 );
|
2002-05-16 20:58:47 +02:00
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int wine_is_dbcs_leadbyte( const union cptable *table, unsigned char ch )
|
2000-06-09 07:27:21 +02:00
|
|
|
{
|
|
|
|
return (table->info.char_size == 2) && (table->dbcs.cp2uni_leadbytes[ch]);
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE WCHAR tolowerW( WCHAR ch )
|
2000-06-12 03:16:11 +02:00
|
|
|
{
|
2003-12-13 01:02:31 +01:00
|
|
|
extern WINE_UNICODE_API const WCHAR wine_casemap_lower[];
|
2003-03-21 22:30:51 +01:00
|
|
|
return ch + wine_casemap_lower[wine_casemap_lower[ch >> 8] + (ch & 0xff)];
|
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
|
|
|
{
|
2003-12-13 01:02:31 +01:00
|
|
|
extern WINE_UNICODE_API const WCHAR wine_casemap_upper[];
|
2003-03-21 22:30:51 +01:00
|
|
|
return ch + wine_casemap_upper[wine_casemap_upper[ch >> 8] + (ch & 0xff)];
|
2000-06-12 03:16:11 +02:00
|
|
|
}
|
|
|
|
|
2000-08-11 22:53:40 +02:00
|
|
|
/* the character type contains the C1_* flags in the low 12 bits */
|
|
|
|
/* and the C2_* type in the high 4 bits */
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE unsigned short get_char_typeW( WCHAR ch )
|
2000-08-11 22:53:40 +02:00
|
|
|
{
|
2003-12-13 01:02:31 +01:00
|
|
|
extern WINE_UNICODE_API const unsigned short wine_wctype_table[];
|
2003-03-21 22:30:51 +01:00
|
|
|
return wine_wctype_table[wine_wctype_table[ch >> 8] + (ch & 0xff)];
|
2000-08-11 22:53:40 +02:00
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int iscntrlW( WCHAR wc )
|
2001-11-08 20:16:34 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_CNTRL;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int ispunctW( WCHAR wc )
|
2001-11-08 20:16:34 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_PUNCT;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int isspaceW( WCHAR wc )
|
2001-11-08 20:16:34 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_SPACE;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int isdigitW( WCHAR wc )
|
2001-11-08 20:16:34 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_DIGIT;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int isxdigitW( WCHAR wc )
|
2001-11-08 20:16:34 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_XDIGIT;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int islowerW( WCHAR wc )
|
2001-11-08 20:16:34 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_LOWER;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int isupperW( WCHAR wc )
|
2001-11-08 20:16:34 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & C1_UPPER;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int isalnumW( WCHAR wc )
|
2001-11-08 20:16:34 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & (C1_ALPHA|C1_DIGIT|C1_LOWER|C1_UPPER);
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int isalphaW( WCHAR wc )
|
2001-11-08 20:16:34 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & (C1_ALPHA|C1_LOWER|C1_UPPER);
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int isgraphW( WCHAR wc )
|
2001-11-08 20:16:34 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & (C1_ALPHA|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int isprintW( WCHAR wc )
|
2001-11-08 20:16:34 +01:00
|
|
|
{
|
|
|
|
return get_char_typeW(wc) & (C1_ALPHA|C1_BLANK|C1_PUNCT|C1_DIGIT|C1_LOWER|C1_UPPER);
|
|
|
|
}
|
|
|
|
|
2000-06-12 03:16:11 +02:00
|
|
|
/* some useful string manipulation routines */
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-04-28 14:01:37 +02:00
|
|
|
/* strncpy doesn't do what you think, don't use it */
|
|
|
|
#define strncpyW(d,s,n) error do_not_use_strncpyW_use_lstrcpynW_or_memcpy_instead
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int strcmpW( const WCHAR *str1, const WCHAR *str2 )
|
2000-06-12 03:16:11 +02:00
|
|
|
{
|
|
|
|
while (*str1 && (*str1 == *str2)) { str1++; str2++; }
|
|
|
|
return *str1 - *str2;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int strncmpW( const WCHAR *str1, const WCHAR *str2, int n )
|
2000-06-12 03:16:11 +02:00
|
|
|
{
|
2000-06-13 03:08:29 +02:00
|
|
|
if (n <= 0) return 0;
|
2000-06-12 03:16:11 +02:00
|
|
|
while ((--n > 0) && *str1 && (*str1 == *str2)) { str1++; str2++; }
|
|
|
|
return *str1 - *str2;
|
|
|
|
}
|
|
|
|
|
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 *strchrW( const WCHAR *str, WCHAR ch )
|
2000-06-12 03:16:11 +02:00
|
|
|
{
|
2007-07-04 21:53:40 +02:00
|
|
|
do { if (*str == ch) return (WCHAR *)(ULONG_PTR)str; } while (*str++);
|
2000-06-12 03:16:11 +02:00
|
|
|
return NULL;
|
|
|
|
}
|
2002-06-01 01:06:46 +02:00
|
|
|
|
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
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE WCHAR *strpbrkW( const WCHAR *str, const WCHAR *accept )
|
2003-01-02 20:25:44 +01:00
|
|
|
{
|
2007-07-04 21:53:40 +02:00
|
|
|
for ( ; *str; str++) if (strchrW( accept, *str )) return (WCHAR *)(ULONG_PTR)str;
|
2003-01-02 20:25:44 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE size_t strspnW( const WCHAR *str, const WCHAR *accept )
|
2003-09-27 05:48:40 +02:00
|
|
|
{
|
|
|
|
const WCHAR *ptr;
|
|
|
|
for (ptr = str; *ptr; ptr++) if (!strchrW( accept, *ptr )) break;
|
|
|
|
return ptr - str;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE size_t strcspnW( const WCHAR *str, const WCHAR *reject )
|
2003-09-27 05:48:40 +02:00
|
|
|
{
|
|
|
|
const WCHAR *ptr;
|
|
|
|
for (ptr = str; *ptr; ptr++) if (strchrW( reject, *ptr )) break;
|
|
|
|
return ptr - str;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE WCHAR *strlwrW( WCHAR *str )
|
2000-06-12 03:16:11 +02:00
|
|
|
{
|
2011-09-08 11:16:51 +02:00
|
|
|
WCHAR *ret;
|
|
|
|
for (ret = str; *str; str++) *str = tolowerW(*str);
|
2000-06-13 03:08:29 +02:00
|
|
|
return ret;
|
2000-06-12 03:16:11 +02:00
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE WCHAR *struprW( WCHAR *str )
|
2000-06-13 03:08:29 +02:00
|
|
|
{
|
2011-09-08 11:16:51 +02:00
|
|
|
WCHAR *ret;
|
|
|
|
for (ret = str; *str; str++) *str = toupperW(*str);
|
2000-06-13 03:08:29 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE WCHAR *memchrW( const WCHAR *ptr, WCHAR ch, size_t n )
|
2004-02-07 03:24:15 +01:00
|
|
|
{
|
|
|
|
const WCHAR *end;
|
2007-07-04 21:53:40 +02:00
|
|
|
for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) return (WCHAR *)(ULONG_PTR)ptr;
|
2004-02-07 03:24:15 +01:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE WCHAR *memrchrW( const WCHAR *ptr, WCHAR ch, size_t n )
|
2004-02-07 03:24:15 +01:00
|
|
|
{
|
2007-07-04 21:53:40 +02:00
|
|
|
const WCHAR *end;
|
|
|
|
WCHAR *ret = NULL;
|
|
|
|
for (end = ptr + n; ptr < end; ptr++) if (*ptr == ch) ret = (WCHAR *)(ULONG_PTR)ptr;
|
|
|
|
return ret;
|
2004-02-07 03:24:15 +01:00
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE long int atolW( const WCHAR *str )
|
2002-05-16 20:58:47 +02:00
|
|
|
{
|
|
|
|
return strtolW( str, (WCHAR **)0, 10 );
|
|
|
|
}
|
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
WINE_UNICODE_INLINE int atoiW( const WCHAR *str )
|
2002-05-16 20:58:47 +02:00
|
|
|
{
|
|
|
|
return (int)atolW( str );
|
|
|
|
}
|
2000-06-13 03:08:29 +02:00
|
|
|
|
2007-02-23 20:40:09 +01:00
|
|
|
#undef WINE_UNICODE_INLINE
|
|
|
|
|
2008-11-06 10:43:31 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-05-25 20:07:57 +02:00
|
|
|
#endif /* __WINE_WINE_UNICODE_H */
|