Update of /cvsroot/plib/plib/src/pui
In directory usw-pr-cvs1:/tmp/cvs-serv16933
Modified Files:
puValue.cxx
Log Message:
Changed strtoint () to handle negative hex / binary / octal numbers
Index: puValue.cxx
===================================================================
RCS file: /cvsroot/plib/plib/src/pui/puValue.cxx,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- puValue.cxx 10 Jun 2002 19:16:55 -0000 1.17
+++ puValue.cxx 11 Jun 2002 18:58:15 -0000 1.18
@@ -31,14 +31,27 @@
if ( *str == '\0')
return 0 ;
- else if ( ulStrNEqual ( str, "0x", 2 ) == TRUE )
- return (int) strtol ( str + 2, NULL, 16 ) ; /* try hexadecimal */
+
+ int result ;
+
+ if ( *str == '-' )
+ {
+ result = -1 ;
+ str++ ;
+ }
+ else
+ result = 1 ;
+
+ if ( ulStrNEqual ( str, "0x", 2 ) == TRUE )
+ result *= (int) strtol ( str + 2, NULL, 16 ) ; /* try hexadecimal */
else if ( ulStrNEqual ( str, "0o", 2 ) == TRUE )
- return (int) strtol ( str + 2, NULL, 8 ) ; /* try octal */
+ result *= (int) strtol ( str + 2, NULL, 8 ) ; /* try octal */
else if ( ulStrNEqual ( str, "0b", 2 ) == TRUE )
- return (int) strtol ( str + 2, NULL, 2 ) ; /* try binary */
+ result *= (int) strtol ( str + 2, NULL, 2 ) ; /* try binary */
else
- return (int) strtol ( str, NULL, 10 ) ; /* try decimal */
+ result *= (int) strtol ( str, NULL, 10 ) ; /* try decimal */
+
+ return result ;
}
|