public
Created

  • Download Gist
gistfile1.diff
Diff
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
diff -r 54d621a3b561 runtime/doc/eval.txt
--- a/runtime/doc/eval.txt Thu Jan 26 20:58:26 2012 +0100
+++ b/runtime/doc/eval.txt Fri Jan 27 09:44:06 2012 +0900
@@ -1713,7 +1713,7 @@
any call {func} with arguments {arglist}
ceil( {expr}) Float round {expr} up
changenr() Number current change number
-char2nr( {expr}) Number ASCII value of first char in {expr}
+char2nr( {expr}[, {utf8}]) Number ASCII/UTF8 value of first char in {expr}
cindent( {lnum}) Number C indent for line {lnum}
clearmatches() none clear all matches
col( {expr}) Number column nr of cursor or mark
@@ -1867,7 +1867,7 @@
mode( [expr]) String current editing mode
mzeval( {expr}) any evaluate |MzScheme| expression
nextnonblank( {lnum}) Number line nr of non-blank line >= {lnum}
-nr2char( {expr}) String single char with ASCII value {expr}
+nr2char( {expr}[, {utf8}]) String single char with ASCII/UTF8 value {expr}
or( {expr}, {expr}) Number bitwise OR
pathshorten( {expr}) String shorten directory names in a path
pow( {x}, {y}) Float {x} to the power of {y}
@@ -2283,14 +2283,16 @@
redo it is the number of the redone change. After undo it is
one less than the number of the undone change.
-char2nr({expr}) *char2nr()*
+char2nr({expr}[, {utf8}]) *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": >
+< When {utf8} is omitted or zero, the current 'encoding' is used.
+ Example for "utf-8": >
char2nr("・) returns 225
char2nr("・[0]) returns 195
-< A combining character is a separate character.
+< With {utf8} set to 1, always treat as utf-8 characters.
+ A combining character is a separate character.
|nr2char()| does the opposite.
cindent({lnum}) *cindent()*
@@ -4333,14 +4335,16 @@
below it, zero is returned.
See also |prevnonblank()|.
-nr2char({expr}) *nr2char()*
+nr2char({expr}[, {utf8}]) *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": >
+< When {utf8} is omitted or zero, the current 'encoding' is used.
+ Example for "utf-8": >
nr2char(300) returns I with bow character
-< Note that a NUL character in the file is specified with
+< With {utf8} set to 1, always return utf-8 characters.
+ Note that a NUL character in the file is specified with
nr2char(10), because NULs are represented with newline
characters. nr2char(0) is a real NUL and terminates the
string, thus results in an empty string.
diff -r 54d621a3b561 src/eval.c
--- a/src/eval.c Thu Jan 26 20:58:26 2012 +0100
+++ b/src/eval.c Fri Jan 27 09:44:06 2012 +0900
@@ -7747,7 +7747,7 @@
{"ceil", 1, 1, f_ceil},
#endif
{"changenr", 0, 0, f_changenr},
- {"char2nr", 1, 1, f_char2nr},
+ {"char2nr", 1, 2, f_char2nr},
{"cindent", 1, 1, f_cindent},
{"clearmatches", 0, 0, f_clearmatches},
{"col", 1, 1, f_col},
@@ -7893,7 +7893,7 @@
{"mzeval", 1, 1, f_mzeval},
#endif
{"nextnonblank", 1, 1, f_nextnonblank},
- {"nr2char", 1, 1, f_nr2char},
+ {"nr2char", 1, 2, f_nr2char},
{"or", 2, 2, f_or},
{"pathshorten", 1, 1, f_pathshorten},
#ifdef FEAT_FLOAT
@@ -9170,7 +9170,17 @@
{
#ifdef FEAT_MBYTE
if (has_mbyte)
- rettv->vval.v_number = (*mb_ptr2char)(get_tv_string(&argvars[0]));
+ {
+ int utf8 = 0;
+
+ if (argvars[1].v_type != VAR_UNKNOWN)
+ utf8 = get_tv_number_chk(&argvars[1], NULL);
+
+ if (utf8)
+ rettv->vval.v_number = (*utf_ptr2char)(get_tv_string(&argvars[0]));
+ else
+ rettv->vval.v_number = (*mb_ptr2char)(get_tv_string(&argvars[0]));
+ }
else
#endif
rettv->vval.v_number = get_tv_string(&argvars[0])[0];
@@ -14130,7 +14140,16 @@
#ifdef FEAT_MBYTE
if (has_mbyte)
- buf[(*mb_char2bytes)((int)get_tv_number(&argvars[0]), buf)] = NUL;
+ {
+ int utf8 = 0;
+
+ if (argvars[1].v_type != VAR_UNKNOWN)
+ utf8 = get_tv_number_chk(&argvars[1], NULL);
+ if (utf8)
+ buf[(*utf_char2bytes)((int)get_tv_number(&argvars[0]), buf)] = NUL;
+ else
+ buf[(*mb_char2bytes)((int)get_tv_number(&argvars[0]), buf)] = NUL;
+ }
else
#endif
{

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.