2 * msvcrt.dll wide-char functions
4 * Copyright 1999 Alexandre Julliard
5 * Copyright 2000 Jon Griffiths
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/unicode.h"
27 #include "msvcrt/stdio.h"
28 #include "msvcrt/stdlib.h"
29 #include "msvcrt/string.h"
30 #include "msvcrt/wctype.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(msvcrt
);
37 /* INTERNAL: MSVCRT_malloc() based wstrndup */
38 MSVCRT_wchar_t
* msvcrt_wstrndup(const MSVCRT_wchar_t
*buf
, unsigned int size
)
41 unsigned int len
= strlenW(buf
), max_len
;
43 max_len
= size
<= len
? size
: len
+ 1;
45 ret
= MSVCRT_malloc(max_len
* sizeof (MSVCRT_wchar_t
));
48 memcpy(ret
,buf
,max_len
* sizeof (MSVCRT_wchar_t
));
54 /*********************************************************************
57 MSVCRT_wchar_t
* _wcsdup( const MSVCRT_wchar_t
* str
)
59 MSVCRT_wchar_t
* ret
= NULL
;
62 int size
= (strlenW(str
) + 1) * sizeof(MSVCRT_wchar_t
);
63 ret
= MSVCRT_malloc( size
);
64 if (ret
) memcpy( ret
, str
, size
);
69 /*********************************************************************
70 * _wcsicoll (MSVCRT.@)
72 INT
_wcsicoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
74 /* FIXME: handle collates */
75 return strcmpiW( str1
, str2
);
78 /*********************************************************************
81 MSVCRT_wchar_t
* _wcsnset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
, MSVCRT_size_t n
)
83 MSVCRT_wchar_t
* ret
= str
;
84 while ((n
-- > 0) && *str
) *str
++ = c
;
88 /*********************************************************************
91 MSVCRT_wchar_t
* _wcsrev( MSVCRT_wchar_t
* str
)
93 MSVCRT_wchar_t
* ret
= str
;
94 MSVCRT_wchar_t
* end
= str
+ strlenW(str
) - 1;
97 MSVCRT_wchar_t t
= *end
;
104 /*********************************************************************
107 MSVCRT_wchar_t
* _wcsset( MSVCRT_wchar_t
* str
, MSVCRT_wchar_t c
)
109 MSVCRT_wchar_t
* ret
= str
;
110 while (*str
) *str
++ = c
;
114 /*********************************************************************
115 * _vsnwprintf (MSVCRT.@)
117 int _vsnwprintf(MSVCRT_wchar_t
*str
, unsigned int len
,
118 const MSVCRT_wchar_t
*format
, va_list valist
)
120 /* If you fix a bug in this function, fix it in ntdll/wcstring.c also! */
121 unsigned int written
= 0;
122 const MSVCRT_wchar_t
*iter
= format
;
123 char bufa
[256], fmtbufa
[64], *fmta
;
125 TRACE("(%d,%s)\n",len
,debugstr_w(format
));
129 while (*iter
&& *iter
!= '%')
131 if (written
++ >= len
)
139 while (*iter
== '0' ||
149 char *buffiter
= bufa
;
150 int fieldlen
= va_arg(valist
, int);
151 sprintf(buffiter
, "%d", fieldlen
);
153 *fmta
++ = *buffiter
++;
160 while (isdigit(*iter
))
168 char *buffiter
= bufa
;
169 int fieldlen
= va_arg(valist
, int);
170 sprintf(buffiter
, "%d", fieldlen
);
172 *fmta
++ = *buffiter
++;
175 while (isdigit(*iter
))
186 static const MSVCRT_wchar_t none
[] = { '(', 'n', 'u', 'l', 'l', ')', 0 };
187 const MSVCRT_wchar_t
*wstr
= va_arg(valist
, const MSVCRT_wchar_t
*);
188 const MSVCRT_wchar_t
*striter
= wstr
? wstr
: none
;
191 if (written
++ >= len
)
200 if (written
++ >= len
)
202 *str
++ = (MSVCRT_wchar_t
)va_arg(valist
, int);
208 /* For non wc types, use system sprintf and append to wide char output */
209 /* FIXME: for unrecognised types, should ignore % when printing */
210 char *bufaiter
= bufa
;
212 sprintf(bufaiter
, "%08lX", va_arg(valist
, long));
218 sprintf(bufaiter
, fmtbufa
, va_arg(valist
, double));
220 sprintf(bufaiter
, fmtbufa
, va_arg(valist
, void *));
224 if (written
++ >= len
)
226 *str
++ = *bufaiter
++;
240 /*********************************************************************
241 * vswprintf (MSVCRT.@)
243 int MSVCRT_vswprintf( MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* format
, va_list args
)
245 return _vsnwprintf( str
, INT_MAX
, format
, args
);
248 /*********************************************************************
251 int MSVCRT_wcscoll( const MSVCRT_wchar_t
* str1
, const MSVCRT_wchar_t
* str2
)
253 /* FIXME: handle collates */
254 return strcmpW( str1
, str2
);
257 /*********************************************************************
260 MSVCRT_wchar_t
* MSVCRT_wcspbrk( const MSVCRT_wchar_t
* str
, const MSVCRT_wchar_t
* accept
)
262 const MSVCRT_wchar_t
* p
;
265 for (p
= accept
; *p
; p
++) if (*p
== *str
) return (MSVCRT_wchar_t
*)str
;
271 /*********************************************************************
274 INT
MSVCRT_wctomb( char *dst
, MSVCRT_wchar_t ch
)
276 return WideCharToMultiByte( CP_ACP
, 0, &ch
, 1, dst
, 6, NULL
, NULL
);
279 /*********************************************************************
280 * iswalnum (MSVCRT.@)
282 INT
MSVCRT_iswalnum( MSVCRT_wchar_t wc
)
284 return isalnumW( wc
);
287 /*********************************************************************
288 * iswalpha (MSVCRT.@)
290 INT
MSVCRT_iswalpha( MSVCRT_wchar_t wc
)
292 return isalphaW( wc
);
295 /*********************************************************************
296 * iswcntrl (MSVCRT.@)
298 INT
MSVCRT_iswcntrl( MSVCRT_wchar_t wc
)
300 return iscntrlW( wc
);
303 /*********************************************************************
304 * iswdigit (MSVCRT.@)
306 INT
MSVCRT_iswdigit( MSVCRT_wchar_t wc
)
308 return isdigitW( wc
);
311 /*********************************************************************
312 * iswgraph (MSVCRT.@)
314 INT
MSVCRT_iswgraph( MSVCRT_wchar_t wc
)
316 return isgraphW( wc
);
319 /*********************************************************************
320 * iswlower (MSVCRT.@)
322 INT
MSVCRT_iswlower( MSVCRT_wchar_t wc
)
324 return islowerW( wc
);
327 /*********************************************************************
328 * iswprint (MSVCRT.@)
330 INT
MSVCRT_iswprint( MSVCRT_wchar_t wc
)
332 return isprintW( wc
);
335 /*********************************************************************
336 * iswpunct (MSVCRT.@)
338 INT
MSVCRT_iswpunct( MSVCRT_wchar_t wc
)
340 return ispunctW( wc
);
343 /*********************************************************************
344 * iswspace (MSVCRT.@)
346 INT
MSVCRT_iswspace( MSVCRT_wchar_t wc
)
348 return isspaceW( wc
);
351 /*********************************************************************
352 * iswupper (MSVCRT.@)
354 INT
MSVCRT_iswupper( MSVCRT_wchar_t wc
)
356 return isupperW( wc
);
359 /*********************************************************************
360 * iswxdigit (MSVCRT.@)
362 INT
MSVCRT_iswxdigit( MSVCRT_wchar_t wc
)
364 return isxdigitW( wc
);
367 /*********************************************************************
370 MSVCRT_wchar_t
* _itow(int value
,MSVCRT_wchar_t
* out
,int base
)
373 _itoa(value
, buf
, base
);
374 MultiByteToWideChar(CP_ACP
, MB_PRECOMPOSED
, buf
, -1, out
, 128);
378 /*********************************************************************
381 MSVCRT_wchar_t
* _ltow(long value
,MSVCRT_wchar_t
* out
,int base
)
384 _ltoa(value
, buf
, base
);
385 MultiByteToWideChar (CP_ACP
, MB_PRECOMPOSED
, buf
, -1, out
, 128);