7 * Convert a unicode string to an unsigned long integer.
9 * Ignores `locale' stuff. Assumes that the upper and lower case
10 * alphabets and digits are each contiguous.
15 wcstoul(const wchar_t *nptr
, wchar_t **endptr
, int base
)
17 const wchar_t *s
= nptr
;
21 int neg
= 0, any
, cutlim
;
24 * See strtol for comments as to the logic used.
28 } while (iswctype(c
, _SPACE
));
36 if ((base
== 0 || base
== 16) &&
37 c
== L
'0' && (*s
== L
'x' || *s
== L
'X'))
44 base
= c
== L
'0' ? 8 : 10;
45 cutoff
= (unsigned long)ULONG_MAX
/ (unsigned long)base
;
46 cutlim
= (unsigned long)ULONG_MAX
% (unsigned long)base
;
47 for (acc
= 0, any
= 0;; c
= *s
++)
49 if (iswctype(c
, _DIGIT
))
51 else if (iswctype(c
, _ALPHA
))
52 c
-= iswctype(c
, _UPPER
) ? L
'A' - 10 : L
'a' - 10;
57 if (any
< 0 || acc
> cutoff
|| (acc
== cutoff
&& c
> cutlim
))
72 *endptr
= any
? (wchar_t *)s
- 1 : (wchar_t *)nptr
;