2 * Unicode string manipulation functions
4 * Copyright 2000 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/unicode.h"
25 int strcmpiW( const WCHAR
*str1
, const WCHAR
*str2
)
29 int ret
= toupperW(*str1
) - toupperW(*str2
);
30 if (ret
|| !*str1
) return ret
;
36 int strncmpiW( const WCHAR
*str1
, const WCHAR
*str2
, int n
)
39 for ( ; n
> 0; n
--, str1
++, str2
++)
40 if ((ret
= toupperW(*str1
) - toupperW(*str2
)) || !*str1
) break;
44 WCHAR
*strstrW( const WCHAR
*str
, const WCHAR
*sub
)
48 const WCHAR
*p1
= str
, *p2
= sub
;
49 while (*p1
&& *p2
&& *p1
== *p2
) { p1
++; p2
++; }
50 if (!*p2
) return (WCHAR
*)str
;
56 /* strtolW and strtoulW implementation based on the GNU C library code */
57 /* Copyright (C) 1991,92,94,95,96,97,98,99,2000,2001 Free Software Foundation, Inc. */
59 long int strtolW( const WCHAR
*nptr
, WCHAR
**endptr
, int base
)
62 register unsigned long int cutoff
;
63 register unsigned int cutlim
;
64 register unsigned long int i
;
65 register const WCHAR
*s
;
67 const WCHAR
*save
, *end
;
70 if (base
< 0 || base
== 1 || base
> 36) return 0;
74 /* Skip white space. */
79 /* Check for a sign. */
89 /* Recognize number prefix and if BASE is zero, figure it out ourselves. */
92 if ((base
== 0 || base
== 16) && toupperW(s
[1]) == 'X')
103 /* Save the pointer so we can check later if anything happened. */
107 cutoff
= ULONG_MAX
/ (unsigned long int) base
;
108 cutlim
= ULONG_MAX
% (unsigned long int) base
;
113 for (;c
!= '\0'; c
= *++s
)
117 if (c
>= '0' && c
<= '9')
119 else if (isalphaW (c
))
120 c
= toupperW (c
) - 'A' + 10;
125 /* Check for overflow. */
126 if (i
> cutoff
|| (i
== cutoff
&& c
> cutlim
))
130 i
*= (unsigned long int) base
;
135 /* Check if anything actually happened. */
139 /* Store in ENDPTR the address of one character
140 past the last character we converted. */
142 *endptr
= (WCHAR
*)s
;
144 /* Check for a value that is within the range of
145 `unsigned LONG int', but outside the range of `LONG int'. */
148 ? -((unsigned long int) (LONG_MIN
+ 1)) + 1
149 : (unsigned long int) LONG_MAX
))
154 return negative
? LONG_MIN
: LONG_MAX
;
157 /* Return the result of the appropriate sign. */
158 return negative
? -i
: i
;
161 /* We must handle a special case here: the base is 0 or 16 and the
162 first two characters are '0' and 'x', but the rest are no
163 hexadecimal digits. This is no error case. We return 0 and
164 ENDPTR points to the `x`. */
167 if (save
- nptr
>= 2 && toupperW (save
[-1]) == 'X'
169 *endptr
= (WCHAR
*)&save
[-1];
171 /* There was no number to convert. */
172 *endptr
= (WCHAR
*)nptr
;
179 unsigned long int strtoulW( const WCHAR
*nptr
, WCHAR
**endptr
, int base
)
182 register unsigned long int cutoff
;
183 register unsigned int cutlim
;
184 register unsigned long int i
;
185 register const WCHAR
*s
;
187 const WCHAR
*save
, *end
;
190 if (base
< 0 || base
== 1 || base
> 36) return 0;
194 /* Skip white space. */
195 while (isspaceW (*s
))
197 if (!*s
) goto noconv
;
199 /* Check for a sign. */
209 /* Recognize number prefix and if BASE is zero, figure it out ourselves. */
212 if ((base
== 0 || base
== 16) && toupperW(s
[1]) == 'X')
223 /* Save the pointer so we can check later if anything happened. */
227 cutoff
= ULONG_MAX
/ (unsigned long int) base
;
228 cutlim
= ULONG_MAX
% (unsigned long int) base
;
233 for (;c
!= '\0'; c
= *++s
)
237 if (c
>= '0' && c
<= '9')
239 else if (isalphaW (c
))
240 c
= toupperW (c
) - 'A' + 10;
245 /* Check for overflow. */
246 if (i
> cutoff
|| (i
== cutoff
&& c
> cutlim
))
250 i
*= (unsigned long int) base
;
255 /* Check if anything actually happened. */
259 /* Store in ENDPTR the address of one character
260 past the last character we converted. */
262 *endptr
= (WCHAR
*)s
;
269 /* Return the result of the appropriate sign. */
270 return negative
? -i
: i
;
273 /* We must handle a special case here: the base is 0 or 16 and the
274 first two characters are '0' and 'x', but the rest are no
275 hexadecimal digits. This is no error case. We return 0 and
276 ENDPTR points to the `x`. */
279 if (save
- nptr
>= 2 && toupperW (save
[-1]) == 'X'
281 *endptr
= (WCHAR
*)&save
[-1];
283 /* There was no number to convert. */
284 *endptr
= (WCHAR
*)nptr
;