Implemented RtlUnicodeStringToInteger.

This commit is contained in:
Robert Shearman 2002-11-12 02:17:34 +00:00 committed by Alexandre Julliard
parent 7daf45a6f6
commit 59e81ec15a
2 changed files with 74 additions and 1 deletions

View File

@ -528,7 +528,7 @@
@ stdcall RtlUnicodeStringToAnsiSize(ptr) RtlUnicodeStringToAnsiSize
@ stdcall RtlUnicodeStringToAnsiString(ptr ptr long) RtlUnicodeStringToAnsiString
@ stub RtlUnicodeStringToCountedOemString
@ stub RtlUnicodeStringToInteger
@ stdcall RtlUnicodeStringToInteger(ptr long ptr) RtlUnicodeStringToInteger
@ stdcall RtlUnicodeStringToOemSize(ptr) RtlUnicodeStringToOemSize
@ stdcall RtlUnicodeStringToOemString(ptr ptr long) RtlUnicodeStringToOemString
@ stub RtlUnicodeToCustomCPN

View File

@ -835,3 +835,76 @@ out:
*pf = out_flags;
return len;
}
/**************************************************************************
* RtlUnicodeStringToInteger (NTDLL.@)
*
* Convert a text buffer into its integer form
*/
NTSTATUS WINAPI RtlUnicodeStringToInteger(
const UNICODE_STRING *str,
int base,
int * pdest)
{
LPWSTR lpwstr = str->Buffer;
WCHAR wchCurrent = 0;
int CharsParsed = 0;
int RunningTotal = 0;
char bMinus = 0;
/* no checking done on UNICODE_STRING and int* in native DLL either */
TRACE("(%p, %d, %p)", str, base, pdest);
switch (base)
{
case 0:
base = 10;
break;
case 2:
case 8:
case 10:
case 16:
break;
default:
return STATUS_INVALID_PARAMETER;
}
if ((str->Length) >= 4 && (base == 10) && (*lpwstr == '0') && (*(lpwstr+1) == 'x'))
{
lpwstr+=2;
base = 16;
}
*pdest = 0;
for (; (CharsParsed*sizeof(WCHAR) < str->Length) && (*lpwstr <= ' '); lpwstr++)
CharsParsed++;
if (*lpwstr == '+')
lpwstr++;
else if (*lpwstr == '-')
{
bMinus = 1;
lpwstr++;
}
for (; (CharsParsed*sizeof(WCHAR) < str->Length) && (*lpwstr != '\0'); lpwstr++)
{
CharsParsed++;
wchCurrent = *lpwstr;
if (wchCurrent >= 'A')
wchCurrent = '0' + 10 + wchCurrent - 'A';
if ((wchCurrent - '0') >= base || wchCurrent < '0')
{
*pdest = bMinus ? -RunningTotal: RunningTotal;
return STATUS_SUCCESS;
}
/*
* increase significance of previous digits each time
* we find another valid one and add on this valid one
*/
RunningTotal = wchCurrent - '0' + RunningTotal * base;
}
*pdest = bMinus ? -RunningTotal : RunningTotal;
return STATUS_SUCCESS;
}