Author: leo
Date: Tue Jan 10 08:51:12 2006
New Revision: 11042

Modified:
   trunk/CREDITS
   trunk/src/string.c
   trunk/t/op/string.t
Log:
[perl #38176] [PATCH] Fix string-to-integer conversion with multiple leading 
spaces 

Until r10938, string-to-integer conversion was possible even when the
string contained more than one space before the start of the integer.

This patch modifies src/string.t to make this work again.

This patch also modifies t/op/string.t to add a test for this case, and
for other corner-cases of string-to-integer conversion.

Courtesy of Roger Browne <[EMAIL PROTECTED]>


Modified: trunk/CREDITS
==============================================================================
--- trunk/CREDITS       (original)
+++ trunk/CREDITS       Tue Jan 10 08:51:12 2006
@@ -373,6 +373,9 @@ N: Ritz Daniel
 N: Robert Spier
 D: Keeps us running
 
+N: Roger Browne 
+D: Author of Amber; bug fixes and tests
+
 N: Roland Illing
 D: Building Parrot with pkgsrc
 

Modified: trunk/src/string.c
==============================================================================
--- trunk/src/string.c  (original)
+++ trunk/src/string.c  Tue Jan 10 08:51:12 2006
@@ -1930,8 +1930,10 @@ string_to_int(Interp *interpreter, const
                     sign = -1;
                     in_number = 1;
                 }
-                else if (c == '+' || isspace(c))
+                else if (c == '+')
                     in_number = 1;
+                else if (isspace(c))
+                    ;
                 else
                     break;
             }

Modified: trunk/t/op/string.t
==============================================================================
--- trunk/t/op/string.t (original)
+++ trunk/t/op/string.t Tue Jan 10 08:51:12 2006
@@ -2824,11 +2824,23 @@ CODE
 Cannot get character before beginning of string
 OUTPUT
 
-pir_output_is(<<'CODE', <<'OUT', 'string_to_int --4');
+pir_output_is(<<'CODE', <<'OUT', 'more string_to_int');
    .sub 'main' :main
       print_as_integer('-4')
       print_as_integer('X-4')
       print_as_integer('--4')
+      print_as_integer('+')
+      print_as_integer('++')
+      print_as_integer('+2')
+      print_as_integer(' +3')
+      print_as_integer('++4')
+      print_as_integer('+ 5')
+      print_as_integer('-')
+      print_as_integer('--56')
+      print_as_integer('  -+67')
+      print_as_integer('+-78')
+      print_as_integer('  -089xyz')
+      print_as_integer('- 89')
    .end
 
    .sub 'print_as_integer'
@@ -2841,6 +2853,18 @@ CODE
 -4
 0
 0
+0
+0
+2
+3
+0
+0
+0
+0
+0
+0
+-89
+0
 OUT
 
 ## remember to change the number of tests :-)

Reply via email to