d1a0b69c16818169de5e16d7dee70230410888f4
[reactos.git] / lib / crtdll / wchar / wcstol.c
1 #include <msvcrt/wchar.h>
2
3
4 /*
5  * @implemented
6  */
7 long wcstol(const wchar_t* cp, wchar_t** endp, int base)
8 {
9         long result = 0, value;
10         int sign = 1;
11
12         if (*cp == L'-') {
13                 sign = -1;
14                 cp++;
15         }
16
17         if (!base) {
18                 base = 10;
19                 if (*cp == L'0') {
20                         base = 8;
21                         cp++;
22                         if ((*cp == L'x') && iswxdigit(cp[1])) {
23                                 cp++;
24                                 base = 16;
25                         }
26                 }
27         }
28         while (iswxdigit(*cp) && (value = iswdigit(*cp) ? *cp-L'0' : (iswlower(*cp)
29             ? towupper(*cp) : *cp)-L'A'+10) < base) {
30                 result = result*base + value;
31                 cp++;
32         }
33         if (endp)
34                 *endp = (wchar_t*)cp;
35         return result * sign;
36 }
37
38 /*
39  * @implemented
40  */
41 unsigned long wcstoul(const wchar_t* cp, wchar_t** endp, int base)
42 {
43         unsigned long result = 0, value;
44
45         if (!base) {
46                 base = 10;
47                 if (*cp == L'0') {
48                         base = 8;
49                         cp++;
50                         if ((*cp == L'x') && iswxdigit(cp[1])) {
51                                 cp++;
52                                 base = 16;
53                         }
54                 }
55         }
56         while (iswxdigit(*cp) && (value = iswdigit(*cp) ? *cp-L'0' : (iswlower(*cp)
57             ? towupper(*cp) : *cp)-L'A'+10) < base) {
58                 result = result*base + value;
59                 cp++;
60         }
61         if (endp)
62                 *endp = (wchar_t*)cp;
63         return result;
64 }