To: vim-dev@vim.org Subject: Patch 6.0.261 Fcc: outbox From: Bram Moolenaar MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.0.261 Problem: nr2char() and char2nr() don't work with multi-byte characters. Solution: Use 'encoding' for these functions. (Yasuhiro Matsumoto) Files: runtime/doc/eval.txt, src/eval.c *** ../vim60.260/runtime/doc/eval.txt Mon Feb 18 12:58:16 2002 --- runtime/doc/eval.txt Fri Feb 22 14:14:08 2002 *************** *** 1,4 **** ! *eval.txt* For Vim version 6.0. Last change: 2002 Feb 18 VIM REFERENCE MANUAL by Bram Moolenaar --- 1,4 ---- ! *eval.txt* For Vim version 6.0. Last change: 2002 Feb 22 VIM REFERENCE MANUAL by Bram Moolenaar *************** *** 969,978 **** feature} char2nr({expr}) *char2nr()* ! Return ASCII value of the first char in {expr}. Examples: > char2nr(" ") returns 32 char2nr("ABC") returns 65 ! < cindent({lnum}) *cindent()* Get the amount of indent for line {lnum} according the C indenting rules, as with 'cindent'. --- 991,1003 ---- feature} char2nr({expr}) *char2nr()* ! Return number value of the first char in {expr}. Examples: > char2nr(" ") returns 32 char2nr("ABC") returns 65 ! < The current 'encoding' is used. Example for "utf-8": > ! char2nr("á") returns 225 ! char2nr("á"[0]) returns 195 ! cindent({lnum}) *cindent()* Get the amount of indent for line {lnum} according the C indenting rules, as with 'cindent'. *************** *** 1874,1884 **** See also |prevnonblank()|. nr2char({expr}) *nr2char()* ! Return a string with a single character, which has the ASCII value {expr}. Examples: > nr2char(64) returns "@" nr2char(32) returns " " ! < prevnonblank({lnum}) *prevnonblank()* Return the line number of the first line at or above {lnum} that is not blank. Example: > --- 1893,1905 ---- See also |prevnonblank()|. nr2char({expr}) *nr2char()* ! Return a string with a single character, which has the number value {expr}. Examples: > nr2char(64) returns "@" nr2char(32) returns " " ! < The current 'encoding' is used. Example for "utf-8": > ! nr2char(300) returns I with bow character ! prevnonblank({lnum}) *prevnonblank()* Return the line number of the first line at or above {lnum} that is not blank. Example: > *** ../vim60.260/src/eval.c Thu Feb 21 16:37:34 2002 --- src/eval.c Fri Feb 22 14:03:05 2002 *************** *** 3047,3052 **** --- 3047,3058 ---- VAR argvars; VAR retvar; { + #ifdef FEAT_MBYTE + if (has_mbyte) + retvar->var_val.var_number = + (*mb_ptr2char)(get_var_string(&argvars[0])); + else + #endif retvar->var_val.var_number = get_var_string(&argvars[0])[0]; } *************** *** 5126,5136 **** VAR argvars; VAR retvar; { ! char_u buf[2]; ! buf[0] = (char_u)get_var_number(&argvars[0]); retvar->var_type = VAR_STRING; ! retvar->var_val.var_string = vim_strnsave(buf, 1); } /* --- 5132,5150 ---- VAR argvars; VAR retvar; { ! char_u buf[NUMBUFLEN]; ! #ifdef FEAT_MBYTE ! if (has_mbyte) ! buf[(*mb_char2bytes)((int)get_var_number(&argvars[0]), buf)] = NUL; ! else ! #endif ! { ! buf[0] = (char_u)get_var_number(&argvars[0]); ! buf[1] = NUL; ! } retvar->var_type = VAR_STRING; ! retvar->var_val.var_string = vim_strsave(buf); } /* *** ../vim60.260/src/version.c Fri Feb 22 12:33:04 2002 --- src/version.c Fri Feb 22 13:06:17 2002 *************** *** 608,609 **** --- 608,611 ---- { /* Add new patch number below this line */ + /**/ + 261, /**/ -- The average life of an organization chart is six months. You can safely ignore any order from your boss that would take six months to complete. (Scott Adams - The Dilbert principle) /// Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net \\\ /// Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim \\\ \\\ Project leader for A-A-P -- http://www.a-a-p.org /// \\\ Help me helping AIDS orphans in Uganda - http://iccf-holland.org ///