This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pp.c: oct() now skips "0o" and "o" prefix.
authorTAKAI Kousuke <62541129+t-a-k@users.noreply.github.com>
Thu, 22 Oct 2020 17:14:57 +0000 (02:14 +0900)
committerKarl Williamson <khw@cpan.org>
Tue, 8 Dec 2020 04:52:14 +0000 (21:52 -0700)
t/op/oct.t: Add test for oct() with 0o and o prefix.

pp.c
t/op/oct.t

diff --git a/pp.c b/pp.c
index 5b5e163..5e17063 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -3099,8 +3099,12 @@ PP(pp_oct)
         flags |= PERL_SCAN_DISALLOW_PREFIX;
         result_uv = grok_bin (tmps, &len, &flags, &result_nv);
     }
-    else
+    else {
+        if (isALPHA_FOLD_EQ(*tmps, 'o')) {
+            tmps++, len--;
+        }
         result_uv = grok_oct (tmps, &len, &flags, &result_nv);
+    }
 
     if (flags & PERL_SCAN_GREATER_THAN_UV_MAX) {
         SETn(result_nv);
index 84814b1..6d16ed0 100644 (file)
@@ -1,12 +1,12 @@
 #!./perl
 
-# Tests 51 onwards are intentionally not all-warnings-clean
+# Tests 53 onwards are intentionally not all-warnings-clean
 
 chdir 't' if -d 't';
 require './test.pl';
 use strict;
 
-plan(tests => 77);
+plan(tests => 79);
 
 foreach(['0b1_0101', 0b101_01],
        ['0b10_101', 0_2_5],
@@ -55,6 +55,9 @@ foreach(['0b1_0101', 0b101_01],
        ["XCAFE", 0xCAFE],
        ["0B101001", 0b101001],
        ["B101001", 0b101001],
+        # Additional syntax for octals
+        ["0o7_654_321", 2054353],
+        ["O4567", 0o4_567],
        ) {
     my ($string, $value) = @$_;
     my $result = oct $string;