Update of /cvsroot/plib/plib/src/pui
In directory usw-pr-cvs1:/tmp/cvs-serv13615
Modified Files:
pu.h puValue.cxx
Log Message:
Made conversion of string values into integers more intelligent
Index: pu.h
===================================================================
RCS file: /cvsroot/plib/plib/src/pui/pu.h,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -d -r1.104 -r1.105
--- pu.h 11 May 2002 14:49:31 -0000 1.104
+++ pu.h 10 Jun 2002 19:16:55 -0000 1.105
@@ -541,21 +541,7 @@
puPostRefresh () ;
}
- void setValue ( const char *s )
- {
- if ( s == NULL )
- s = "" ;
-
- copy_stringval ( s ) ;
-
- if ( convert == TRUE )
- {
- *getIntegerp () = (int) strtol ( s, NULL, 0 ) ;
- *getFloaterp () = (float) strtod ( s, NULL ) ;
- }
-
- puPostRefresh () ;
- }
+ void setValue ( const char *s ) ;
void getValue ( int *i ) { re_eval () ; *i = *getIntegerp () ; }
void getValue ( float *f ) { re_eval () ; *f = *getFloaterp () ; }
Index: puValue.cxx
===================================================================
RCS file: /cvsroot/plib/plib/src/pui/puValue.cxx,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- puValue.cxx 4 Jun 2002 22:21:19 -0000 1.16
+++ puValue.cxx 10 Jun 2002 19:16:55 -0000 1.17
@@ -24,6 +24,24 @@
#include "puLocal.h"
+static int strtoint ( const char *str )
+{
+ while ( isspace ( *str ) != 0 )
+ str++ ;
+
+ if ( *str == '\0')
+ return 0 ;
+ else if ( ulStrNEqual ( str, "0x", 2 ) == TRUE )
+ return (int) strtol ( str + 2, NULL, 16 ) ; /* try hexadecimal */
+ else if ( ulStrNEqual ( str, "0o", 2 ) == TRUE )
+ return (int) strtol ( str + 2, NULL, 8 ) ; /* try octal */
+ else if ( ulStrNEqual ( str, "0b", 2 ) == TRUE )
+ return (int) strtol ( str + 2, NULL, 2 ) ; /* try binary */
+ else
+ return (int) strtol ( str, NULL, 10 ) ; /* try decimal */
+}
+
+
void puValue::re_eval ( void )
{
if ( convert == FALSE )
@@ -37,7 +55,7 @@
Needed for puInput / puLargeInput:
Do not modify the string value unless necessary
*/
- if ( *res_integer != strtol ( string, NULL, 0 ) )
+ if ( *res_integer != strtoint ( string ) )
sprintf ( string, "%d", *res_integer ) ;
puPostRefresh () ;
@@ -57,7 +75,7 @@
}
else if ( res_string != NULL )
{
- integer = (int) strtol ( res_string, NULL, 0 ) ;
+ integer = strtoint ( res_string ) ;
floater = (float) strtod ( res_string, NULL ) ;
puPostRefresh () ;
}
@@ -95,6 +113,22 @@
memcpy ( string, str, str_len + 1 ) ;
}
+}
+
+void puValue::setValue ( const char *s )
+{
+ if ( s == NULL )
+ s = "" ;
+
+ copy_stringval ( s ) ;
+
+ if ( convert == TRUE )
+ {
+ *getIntegerp () = strtoint ( s ) ;
+ *getFloaterp () = (float) strtod ( s, NULL ) ;
+ }
+
+ puPostRefresh () ;
}
|