Patch 8.2.0886
Problem:    Cannot use octal numbers in scriptversion 4.
Solution:   Add the "0o" notation. (Ken Takata, closes #5304)
Files:      runtime/doc/eval.txt, src/charset.c, src/evalfunc.c,
            src/testdir/test_eval_stuff.vim, src/testdir/test_functions.vim,
            src/vim.h


*** ../vim-8.2.0885/runtime/doc/eval.txt        2020-06-01 18:39:14.040317510 
+0200
--- runtime/doc/eval.txt        2020-06-02 21:14:32.503192380 +0200
***************
*** 95,109 ****
        Number -1       -->     String "-1" ~
                                                        *octal*
  Conversion from a String to a Number is done by converting the first digits to
! a number.  Hexadecimal "0xf9", Octal "017", and Binary "0b10" numbers are
! recognized (NOTE: when using |scriptversion-4| octal is not recognized).  If
! the String doesn't start with digits, the result is zero.
  Examples:
        String "456"    -->     Number 456 ~
        String "6bar"   -->     Number 6 ~
        String "foo"    -->     Number 0 ~
        String "0xf1"   -->     Number 241 ~
        String "0100"   -->     Number 64 ~
        String "0b101"  -->     Number 5 ~
        String "-8"     -->     Number -8 ~
        String "+8"     -->     Number 0 ~
--- 95,111 ----
        Number -1       -->     String "-1" ~
                                                        *octal*
  Conversion from a String to a Number is done by converting the first digits to
! a number.  Hexadecimal "0xf9", Octal "017" or "0o17", and Binary "0b10"
! numbers are recognized (NOTE: when using |scriptversion-4| octal with a
! leading "0" is not recognized).  If the String doesn't start with digits, the
! result is zero.
  Examples:
        String "456"    -->     Number 456 ~
        String "6bar"   -->     Number 6 ~
        String "foo"    -->     Number 0 ~
        String "0xf1"   -->     Number 241 ~
        String "0100"   -->     Number 64 ~
+       String "0o100"  -->     Number 64 ~
        String "0b101"  -->     Number 5 ~
        String "-8"     -->     Number -8 ~
        String "+8"     -->     Number 0 ~
***************
*** 1262,1268 ****
                                *hex-number* *octal-number* *binary-number*
  
  Decimal, Hexadecimal (starting with 0x or 0X), Binary (starting with 0b or 0B)
! and Octal (starting with 0).
  
                                                *floating-point-format*
  Floating point numbers can be written in two forms:
--- 1266,1272 ----
                                *hex-number* *octal-number* *binary-number*
  
  Decimal, Hexadecimal (starting with 0x or 0X), Binary (starting with 0b or 0B)
! and Octal (starting with 0, 0o or 0O).
  
                                                *floating-point-format*
  Floating point numbers can be written in two forms:
***************
*** 9634,9641 ****
  <
                When {base} is 16 a leading "0x" or "0X" is ignored.  With a
                different base the result will be zero.  Similarly, when
!               {base} is 8 a leading "0" is ignored, and when {base} is 2 a
!               leading "0b" or "0B" is ignored.
                Text after the number is silently ignored.
  
                Can also be used as a |method|: >
--- 9644,9651 ----
  <
                When {base} is 16 a leading "0x" or "0X" is ignored.  With a
                different base the result will be zero.  Similarly, when
!               {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
!               {base} is 2 a leading "0b" or "0B" is ignored.
                Text after the number is silently ignored.
  
                Can also be used as a |method|: >
***************
*** 13575,13587 ****
  <
                                                        *scriptversion-4*  >
   :scriptversion 4
! <     Numbers with a leading zero are not recognized as octal.  With the
        previous version you get: >
!               echo 017   " displays 15
!               echo 018   " displays 18
  <     with script version 4: >
!               echo 017   " displays 17
!               echo 018   " displays 18
  <     Also, it is possible to use single quotes inside numbers to make them
        easier to read: >
                echo 1'000'000
--- 13595,13610 ----
  <
                                                        *scriptversion-4*  >
   :scriptversion 4
! <     Numbers with a leading zero are not recognized as octal.  "0o" or "0O"
!       is still recognized as octal.  With the
        previous version you get: >
!               echo 017   " displays 15 (octal)
!               echo 0o17  " displays 15 (octal)
!               echo 018   " displays 18 (decimal)
  <     with script version 4: >
!               echo 017   " displays 17 (decimal)
!               echo 0o17  " displays 15 (octal)
!               echo 018   " displays 18 (decimal)
  <     Also, it is possible to use single quotes inside numbers to make them
        easier to read: >
                echo 1'000'000
*** ../vim-8.2.0885/src/charset.c       2020-04-12 19:37:13.506297291 +0200
--- src/charset.c       2020-06-02 21:14:32.503192380 +0200
***************
*** 1764,1769 ****
--- 1764,1771 ----
   * If "prep" is not NULL, returns a flag to indicate the type of the number:
   *  0     decimal
   *  '0'           octal
+  *  'O'           octal
+  *  'o'           octal
   *  'B'           bin
   *  'b'           bin
   *  'X'           hex
***************
*** 1783,1790 ****
  vim_str2nr(
      char_u            *start,
      int                       *prep,      // return: type of number 0 = 
decimal, 'x'
!                                   // or 'X' is hex, '0' = octal, 'b' or 'B'
!                                   // is bin
      int                       *len,       // return: detected length of number
      int                       what,       // what numbers to recognize
      varnumber_T               *nptr,      // return: signed result
--- 1785,1792 ----
  vim_str2nr(
      char_u            *start,
      int                       *prep,      // return: type of number 0 = 
decimal, 'x'
!                                   // or 'X' is hex, '0', 'o' or 'O' is octal,
!                                   // 'b' or 'B' is bin
      int                       *len,       // return: detected length of number
      int                       what,       // what numbers to recognize
      varnumber_T               *nptr,      // return: signed result
***************
*** 1822,1827 ****
--- 1824,1834 ----
                && (maxlen == 0 || maxlen > 2))
            // binary
            ptr += 2;
+       else if ((what & STR2NR_OOCT)
+               && (pre == 'O' || pre == 'o') && vim_isbdigit(ptr[2])
+               && (maxlen == 0 || maxlen > 2))
+           // octal with prefix "0o"
+           ptr += 2;
        else
        {
            // decimal or octal, default is decimal
***************
*** 1869,1877 ****
            }
        }
      }
!     else if (pre == '0' || ((what & STR2NR_OCT) && (what & STR2NR_FORCE)))
      {
        // octal
        while ('0' <= *ptr && *ptr <= '7')
        {
            // avoid ubsan error for overflow
--- 1876,1887 ----
            }
        }
      }
!     else if (pre == 'O' || pre == 'o' ||
!               pre == '0' || ((what & STR2NR_OCT) && (what & STR2NR_FORCE)))
      {
        // octal
+       if (pre != 0 && pre != '0')
+           n += 2;         // skip over "0o"
        while ('0' <= *ptr && *ptr <= '7')
        {
            // avoid ubsan error for overflow
*** ../vim-8.2.0885/src/evalfunc.c      2020-06-01 18:39:14.040317510 +0200
--- src/evalfunc.c      2020-06-02 21:14:32.503192380 +0200
***************
*** 7737,7743 ****
      switch (base)
      {
        case 2: what |= STR2NR_BIN + STR2NR_FORCE; break;
!       case 8: what |= STR2NR_OCT + STR2NR_FORCE; break;
        case 16: what |= STR2NR_HEX + STR2NR_FORCE; break;
      }
      vim_str2nr(p, NULL, NULL, what, &n, NULL, 0, FALSE);
--- 7737,7743 ----
      switch (base)
      {
        case 2: what |= STR2NR_BIN + STR2NR_FORCE; break;
!       case 8: what |= STR2NR_OCT + STR2NR_OOCT + STR2NR_FORCE; break;
        case 16: what |= STR2NR_HEX + STR2NR_FORCE; break;
      }
      vim_str2nr(p, NULL, NULL, what, &n, NULL, 0, FALSE);
*** ../vim-8.2.0885/src/testdir/test_eval_stuff.vim     2020-04-29 
22:01:18.156649911 +0200
--- src/testdir/test_eval_stuff.vim     2020-06-02 21:14:32.503192380 +0200
***************
*** 199,207 ****
--- 199,210 ----
  func Test_vvar_scriptversion4()
    call assert_true(has('vimscript-4'))
    call assert_equal(17, 017)
+   call assert_equal(15, 0o17)
+   call assert_equal(15, 0O17)
    call assert_equal(18, 018)
    call assert_equal(64, 0b1'00'00'00)
    call assert_equal(1048576, 0x10'00'00)
+   call assert_equal(32768, 0o10'00'00)
    call assert_equal(1000000, 1'000'000)
    call assert_equal("1234", execute("echo 1'234")->trim())
    call assert_equal('1  234', execute("echo 1''234")->trim())
***************
*** 211,216 ****
--- 214,221 ----
  scriptversion 1
  func Test_vvar_scriptversion1()
    call assert_equal(15, 017)
+   call assert_equal(15, 0o17)
+   call assert_equal(15, 0O17)
    call assert_equal(18, 018)
  endfunc
  
*** ../vim-8.2.0885/src/testdir/test_functions.vim      2020-06-01 
16:09:30.266292734 +0200
--- src/testdir/test_functions.vim      2020-06-02 21:14:32.503192380 +0200
***************
*** 189,194 ****
--- 189,198 ----
    call assert_equal(65, str2nr('0101', 8))
    call assert_equal(-65, str2nr('-101', 8))
    call assert_equal(-65, str2nr('-0101', 8))
+   call assert_equal(65, str2nr('0o101', 8))
+   call assert_equal(65, str2nr('0O0101', 8))
+   call assert_equal(-65, str2nr('-0O101', 8))
+   call assert_equal(-65, str2nr('-0o0101', 8))
  
    call assert_equal(11259375, str2nr('abcdef', 16))
    call assert_equal(11259375, str2nr('ABCDEF', 16))
***************
*** 207,212 ****
--- 211,217 ----
  
    call assert_equal(0, str2nr('0x10'))
    call assert_equal(0, str2nr('0b10'))
+   call assert_equal(0, str2nr('0o10'))
    call assert_equal(1, str2nr('12', 2))
    call assert_equal(1, str2nr('18', 8))
    call assert_equal(1, str2nr('1g', 16))
*** ../vim-8.2.0885/src/vim.h   2020-05-31 22:06:48.085779425 +0200
--- src/vim.h   2020-06-02 21:14:32.503192380 +0200
***************
*** 312,322 ****
  #define NUMBUFLEN 65
  
  // flags for vim_str2nr()
! #define STR2NR_BIN 0x01
! #define STR2NR_OCT 0x02
! #define STR2NR_HEX 0x04
! #define STR2NR_ALL (STR2NR_BIN + STR2NR_OCT + STR2NR_HEX)
! #define STR2NR_NO_OCT (STR2NR_BIN + STR2NR_HEX)
  
  #define STR2NR_FORCE 0x80   // only when ONE of the above is used
  
--- 312,323 ----
  #define NUMBUFLEN 65
  
  // flags for vim_str2nr()
! #define STR2NR_BIN  0x01
! #define STR2NR_OCT  0x02
! #define STR2NR_HEX  0x04
! #define STR2NR_OOCT 0x08    // Octal with prefix "0o": 0o777
! #define STR2NR_ALL (STR2NR_BIN + STR2NR_OCT + STR2NR_HEX + STR2NR_OOCT)
! #define STR2NR_NO_OCT (STR2NR_BIN + STR2NR_HEX + STR2NR_OOCT)
  
  #define STR2NR_FORCE 0x80   // only when ONE of the above is used
  
*** ../vim-8.2.0885/src/version.c       2020-06-02 20:25:33.164477793 +0200
--- src/version.c       2020-06-02 21:16:10.162835575 +0200
***************
*** 748,749 ****
--- 748,751 ----
  {   /* Add new patch number below this line */
+ /**/
+     886,
  /**/

-- 
hundred-and-one symptoms of being an internet addict:
258. When you want to see your girlfriend, you surf to her homepage.

 /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/202006021939.052Jdc97312764%40masaka.moolenaar.net.

Raspunde prin e-mail lui