# New Ticket Created by  Roger Browne 
# Please include the string:  [perl #38176]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/rt3/Ticket/Display.html?id=38176 >


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.

$ diffstat s2i.patch
 src/string.c  |    4 +++-
 t/op/string.t |   26 +++++++++++++++++++++++++-
 2 files changed, 28 insertions(+), 2 deletions(-)

Regards,
Roger Browne
Index: src/string.c
===================================================================
--- src/string.c	(revision 10939)
+++ src/string.c	(working copy)
@@ -1930,8 +1930,10 @@
                     sign = -1;
                     in_number = 1;
                 }
-                else if (c == '+' || isspace(c))
+                else if (c == '+')
                     in_number = 1;
+                else if (isspace(c))
+                    ;
                 else
                     break;
             }
Index: t/op/string.t
===================================================================
--- t/op/string.t	(revision 10939)
+++ t/op/string.t	(working copy)
@@ -2824,11 +2824,23 @@
 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 @@
 -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