The string to number conversion stuff should really be done by the string encodings... I think this is the right way to get this happening, comments?
Alex Gough
Index: string.c =================================================================== RCS file: /home/perlcvs/parrot/string.c,v retrieving revision 1.20 diff -u -r1.20 string.c --- string.c 2001/11/28 15:22:51 1.20 +++ string.c 2001/12/03 17:36:57 @@ -332,6 +332,24 @@ return cmp; } +INTVAL string_to_int (struct Parrot_Interp *interpreter, STRING *s) { + if (s == NULL) { + return 0; + } + else { + return s->encoding->extract_int(s->bufstart); + } +} + +FLOATVAL string_to_num (struct Parrot_Interp *interpreter, STRING *s) { + if (s == NULL) { + return 0.0; + } + else { + return s->encoding->extract_num(s->bufstart); + } +} + /* * Local variables: * c-indentation-style: bsd Index: classes/perlstring.pmc =================================================================== RCS file: /home/perlcvs/parrot/classes/perlstring.pmc,v retrieving revision 1.4 diff -u -r1.4 perlstring.pmc --- classes/perlstring.pmc 2001/11/30 06:20:00 1.4 +++ classes/perlstring.pmc 2001/12/03 17:36:58 @@ -45,12 +45,12 @@ INTVAL get_integer () { STRING* s = (STRING*) SELF->cache.struct_val; - return strtol(s->bufstart,NULL,10); + return string_to_int(interpreter, s); } FLOATVAL get_number () { STRING* s = (STRING*) SELF->cache.struct_val; - return strtod(s->bufstart,NULL); + return string_to_num(interpreter, s); } STRING* get_string () { Index: encodings/singlebyte.c =================================================================== RCS file: /home/perlcvs/parrot/encodings/singlebyte.c,v retrieving revision 1.1 diff -u -r1.1 singlebyte.c --- encodings/singlebyte.c 2001/10/31 22:51:31 1.1 +++ encodings/singlebyte.c 2001/12/03 17:36:58 @@ -26,6 +26,18 @@ return *bptr; } +static INTVAL +singlebyte_extract_int (const void *ptr) { + char *s = (char*)ptr; + return (INTVAL)strtol(s, NULL, 10); /* XXX: Fixme! */ +} + +static FLOATVAL +singlebyte_extract_num (const void*ptr) { + char *s = (char*)ptr; + return strtod(s, NULL); /* XXX: Fixme! */ +} + static void * singlebyte_encode (void *ptr, INTVAL c) { byte_t *bptr = ptr; @@ -59,6 +71,8 @@ 1, singlebyte_characters, singlebyte_decode, + singlebyte_extract_int, + singlebyte_extract_num, singlebyte_encode, singlebyte_skip_forward, singlebyte_skip_backward Index: encodings/utf16.c =================================================================== RCS file: /home/perlcvs/parrot/encodings/utf16.c,v retrieving revision 1.1 diff -u -r1.1 utf16.c --- encodings/utf16.c 2001/10/31 22:51:31 1.1 +++ encodings/utf16.c 2001/12/03 17:36:58 @@ -56,6 +56,16 @@ return c; } +static INTVAL +utf16_extract_int (const void *ptr) { + return 0; /* XXX: Write me! */ +} + +static FLOATVAL +utf16_extract_num (const void *ptr) { + return 0.0; /* XXX: Write me! */ +} + static void * utf16_encode (void *ptr, INTVAL c) { utf16_t *u16ptr = ptr; @@ -127,6 +137,8 @@ UTF16_MAXLEN, utf16_characters, utf16_decode, + utf16_extract_int, + utf16_extract_num, utf16_encode, utf16_skip_forward, utf16_skip_backward Index: encodings/utf8.c =================================================================== RCS file: /home/perlcvs/parrot/encodings/utf8.c,v retrieving revision 1.1 diff -u -r1.1 utf8.c --- encodings/utf8.c 2001/10/31 22:51:31 1.1 +++ encodings/utf8.c 2001/12/03 17:36:59 @@ -76,6 +76,16 @@ return c; } +static INTVAL +utf8_extract_int (const void *ptr) { + return 0;/* XXX: write me! */ +} + +static FLOATVAL +utf8_extract_num (const void *ptr) { + return 0.0; /* XXX: write me! */ +} + static void * utf8_encode (void *ptr, INTVAL c) { utf8_t *u8ptr = ptr; @@ -124,6 +134,8 @@ UTF8_MAXLEN, utf8_characters, utf8_decode, + utf8_extract_int, + utf8_extract_num, utf8_encode, utf8_skip_forward, utf8_skip_backward Index: include/parrot/encoding.h =================================================================== RCS file: /home/perlcvs/parrot/include/parrot/encoding.h,v retrieving revision 1.1 diff -u -r1.1 encoding.h --- include/parrot/encoding.h 2001/10/31 22:51:32 1.1 +++ include/parrot/encoding.h 2001/12/03 17:36:59 @@ -18,6 +18,8 @@ INTVAL max_bytes; INTVAL (*characters)(const void *ptr, INTVAL bytes); INTVAL (*decode)(const void *ptr); + INTVAL (*extract_int)(const void *ptr); + FLOATVAL (*extract_num)(const void *ptr); void *(*encode)(void *ptr, INTVAL c); void *(*skip_forward)(void *ptr, INTVAL n); void *(*skip_backward)(void *ptr, INTVAL n); Index: include/parrot/string.h =================================================================== RCS file: /home/perlcvs/parrot/include/parrot/string.h,v retrieving revision 1.11 diff -u -r1.11 string.h --- include/parrot/string.h 2001/11/15 22:10:31 1.11 +++ include/parrot/string.h 2001/12/03 17:37:00 @@ -47,6 +47,10 @@ string_length(STRING*); INTVAL string_ord(STRING* s, INTVAL index); +FLOATVAL +string_to_num (struct Parrot_Interp *interpreter, STRING *s); +INTVAL +string_to_int (struct Parrot_Interp *interpreter, STRING *s); void string_grow(STRING* s, INTVAL newsize); void