Add VG_(atoll).

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6899
This commit is contained in:
Nicholas Nethercote 2007-09-22 06:23:07 +00:00
parent ac244a2023
commit 2455b7eaf8
2 changed files with 29 additions and 0 deletions

View File

@ -63,6 +63,33 @@ Long VG_(atoll) ( Char* str )
return n;
}
Long VG_(atoll16) ( Char* str )
{
Bool neg = False;
Long n = 0;
if (*str == '-') { str++; neg = True; };
while (True) {
Char c = *str;
if (c >= '0' && c <= (Char)'9') {
n = 16*n + (Long)(c - '0');
}
else
if (c >= 'A' && c <= (Char)'F') {
n = 16*n + (Long)((c - 'A') + 10);
}
else
if (c >= 'a' && c <= (Char)'f') {
n = 16*n + (Long)((c - 'a') + 10);
}
else {
break;
}
str++;
}
if (neg) n = -n;
return n;
}
Long VG_(atoll36) ( Char* str )
{
Bool neg = False;

View File

@ -42,7 +42,9 @@ extern Bool VG_(isdigit) ( Char c );
Converting strings to numbers
------------------------------------------------------------------ */
// Nb: atoll16 doesn't handle a "0x" prefix.
extern Long VG_(atoll) ( Char* str ); // base 10
extern Long VG_(atoll16) ( Char* str ); // base 16
extern Long VG_(atoll36) ( Char* str ); // base 36
/* ---------------------------------------------------------------------