|
From: <sv...@va...> - 2007-10-28 14:51:23
|
Author: sewardj
Date: 2007-10-28 14:51:23 +0000 (Sun, 28 Oct 2007)
New Revision: 7046
Log:
Add VG_(atoll16) for ascii-hex to signed Long conversions.
Modified:
branches/THRCHECK/coregrind/m_libcbase.c
branches/THRCHECK/include/pub_tool_libcbase.h
Modified: branches/THRCHECK/coregrind/m_libcbase.c
===================================================================
--- branches/THRCHECK/coregrind/m_libcbase.c 2007-10-28 01:46:12 UTC (rev 7045)
+++ branches/THRCHECK/coregrind/m_libcbase.c 2007-10-28 14:51:23 UTC (rev 7046)
@@ -63,6 +63,36 @@
return n;
}
+Long VG_(atoll16) ( Char* str )
+{
+ Bool neg = False;
+ Long n = 0;
+ if (*str == '-') { str++; neg = True; };
+ if (*str == '0' && (*(str+1) == 'x' || *(str+1) == 'X')) {
+ str += 2;
+ }
+ 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;
Modified: branches/THRCHECK/include/pub_tool_libcbase.h
===================================================================
--- branches/THRCHECK/include/pub_tool_libcbase.h 2007-10-28 01:46:12 UTC (rev 7045)
+++ branches/THRCHECK/include/pub_tool_libcbase.h 2007-10-28 14:51:23 UTC (rev 7046)
@@ -42,8 +42,9 @@
Converting strings to numbers
------------------------------------------------------------------ */
-extern Long VG_(atoll) ( Char* str ); // base 10
-extern Long VG_(atoll36) ( Char* str ); // base 36
+extern Long VG_(atoll) ( Char* str ); // base 10
+extern Long VG_(atoll16) ( Char* str ); // base 16; leading 0x accepted
+extern Long VG_(atoll36) ( Char* str ); // base 36
/* ---------------------------------------------------------------------
String functions and macros
|