Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenwcstoul.c
Go to the documentation of this file.
00001 #include <precomp.h> 00002 00003 00004 /* 00005 * Convert a unicode string to an unsigned long integer. 00006 * 00007 * Ignores `locale' stuff. Assumes that the upper and lower case 00008 * alphabets and digits are each contiguous. 00009 * 00010 * @implemented 00011 */ 00012 unsigned long 00013 wcstoul(const wchar_t *nptr, wchar_t **endptr, int base) 00014 { 00015 const wchar_t *s = nptr; 00016 unsigned long acc; 00017 int c; 00018 unsigned long cutoff; 00019 int neg = 0, any, cutlim; 00020 00021 /* 00022 * See strtol for comments as to the logic used. 00023 */ 00024 do { 00025 c = *s++; 00026 } while (iswctype(c, _SPACE)); 00027 if (c == L'-') 00028 { 00029 neg = 1; 00030 c = *s++; 00031 } 00032 else if (c == L'+') 00033 c = *s++; 00034 if ((base == 0 || base == 16) && 00035 c == L'0' && (*s == L'x' || *s == L'X')) 00036 { 00037 c = s[1]; 00038 s += 2; 00039 base = 16; 00040 } 00041 if (base == 0) 00042 base = c == L'0' ? 8 : 10; 00043 cutoff = (unsigned long)ULONG_MAX / (unsigned long)base; 00044 cutlim = (unsigned long)ULONG_MAX % (unsigned long)base; 00045 for (acc = 0, any = 0;; c = *s++) 00046 { 00047 if (iswctype(c, _DIGIT)) 00048 c -= L'0'; 00049 else if (iswctype(c, _ALPHA)) 00050 c -= iswctype(c, _UPPER) ? L'A' - 10 : L'a' - 10; 00051 else 00052 break; 00053 if (c >= base) 00054 break; 00055 if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim)) 00056 any = -1; 00057 else { 00058 any = 1; 00059 acc *= base; 00060 acc += c; 00061 } 00062 } 00063 if (any < 0) 00064 { 00065 acc = ULONG_MAX; 00066 } 00067 else if (neg) 00068 acc = 0-acc; 00069 if (endptr != 0) 00070 *endptr = any ? (wchar_t *)((size_t)(s - 1)) : (wchar_t *)((size_t)nptr); 00071 return acc; 00072 } Generated on Sat May 26 2012 04:35:36 for ReactOS by
1.7.6.1
|