Karsten Hopp be6f54
diff -up vim73/runtime/doc/eval.txt.780 vim73/runtime/doc/eval.txt
Karsten Hopp be6f54
--- vim73/runtime/doc/eval.txt.780	2013-01-28 13:41:04.000000000 +0100
Karsten Hopp be6f54
+++ runtime/doc/eval.txt	2013-01-28 13:44:58.000000000 +0100
Karsten Hopp be6f54
@@ -1705,7 +1705,7 @@ call( {func}, {arglist} [, {dict}])
Karsten Hopp be6f54
 				any	call {func} with arguments {arglist}
Karsten Hopp be6f54
 ceil( {expr})			Float	round {expr} up
Karsten Hopp be6f54
 changenr()			Number	current change number
Karsten Hopp be6f54
-char2nr( {expr})		Number	ASCII value of first char in {expr}
Karsten Hopp be6f54
+char2nr( {expr}[, {utf8}])	Number	ASCII/UTF8 value of first char in {expr}
Karsten Hopp be6f54
 cindent( {lnum})		Number	C indent for line {lnum}
Karsten Hopp be6f54
 clearmatches()			none	clear all matches
Karsten Hopp be6f54
 col( {expr})			Number	column nr of cursor or mark
Karsten Hopp be6f54
@@ -1862,7 +1862,7 @@ mkdir( {name} [, {path} [, {prot}]])
Karsten Hopp be6f54
 mode( [expr])			String	current editing mode
Karsten Hopp be6f54
 mzeval( {expr})			any	evaluate |MzScheme| expression
Karsten Hopp be6f54
 nextnonblank( {lnum})		Number	line nr of non-blank line >= {lnum}
Karsten Hopp be6f54
-nr2char( {expr})		String	single char with ASCII value {expr}
Karsten Hopp be6f54
+nr2char( {expr}[, {utf8}])	String	single char with ASCII/UTF8 value {expr}
Karsten Hopp be6f54
 or( {expr}, {expr})		Number  bitwise OR
Karsten Hopp be6f54
 pathshorten( {expr})		String	shorten directory names in a path
Karsten Hopp be6f54
 pow( {x}, {y})			Float	{x} to the power of {y}
Karsten Hopp be6f54
@@ -2282,13 +2282,17 @@ changenr()						*changenr()*
Karsten Hopp be6f54
 		redo it is the number of the redone change.  After undo it is
Karsten Hopp be6f54
 		one less than the number of the undone change.
Karsten Hopp be6f54
 
Karsten Hopp be6f54
-char2nr({expr})						*char2nr()*
Karsten Hopp be6f54
+char2nr({expr}[, {utf8}])				**char2nr()*
Karsten Hopp be6f54
 		Return number value of the first char in {expr}.  Examples: >
Karsten Hopp be6f54
 			char2nr(" ")		returns 32
Karsten Hopp be6f54
 			char2nr("ABC")		returns 65
Karsten Hopp be6f54
-<		The current 'encoding' is used.  Example for "utf-8": >
Karsten Hopp be6f54
+<		When {utf8} is omitted or zero, the current 'encoding' is
Karsten Hopp be6f54
+used.
Karsten Hopp be6f54
+		Example for "utf-8": >
Karsten Hopp be6f54
 			char2nr("á")		returns 225
Karsten Hopp be6f54
 			char2nr("á"[0])		returns 195
Karsten Hopp be6f54
+		With {utf8} set to 1, always treat as utf-8 characters.
Karsten Hopp be6f54
+		A combining character is a separate character.
Karsten Hopp be6f54
 <		|nr2char()| does the opposite.
Karsten Hopp be6f54
 
Karsten Hopp be6f54
 cindent({lnum})						*cindent()*
Karsten Hopp be6f54
diff -up vim73/src/eval.c.780 vim73/src/eval.c
Karsten Hopp be6f54
--- vim73/src/eval.c.780	2013-01-28 13:41:04.000000000 +0100
Karsten Hopp be6f54
+++ src/eval.c	2013-01-28 13:41:04.000000000 +0100
Karsten Hopp be6f54
@@ -7854,7 +7854,7 @@ static struct fst
Karsten Hopp be6f54
     {"ceil",		1, 1, f_ceil},
Karsten Hopp be6f54
 #endif
Karsten Hopp be6f54
     {"changenr",	0, 0, f_changenr},
Karsten Hopp be6f54
-    {"char2nr",		1, 1, f_char2nr},
Karsten Hopp be6f54
+    {"char2nr",		1, 2, f_char2nr},
Karsten Hopp be6f54
     {"cindent",		1, 1, f_cindent},
Karsten Hopp be6f54
     {"clearmatches",	0, 0, f_clearmatches},
Karsten Hopp be6f54
     {"col",		1, 1, f_col},
Karsten Hopp be6f54
@@ -8003,7 +8003,7 @@ static struct fst
Karsten Hopp be6f54
     {"mzeval",		1, 1, f_mzeval},
Karsten Hopp be6f54
 #endif
Karsten Hopp be6f54
     {"nextnonblank",	1, 1, f_nextnonblank},
Karsten Hopp be6f54
-    {"nr2char",		1, 1, f_nr2char},
Karsten Hopp be6f54
+    {"nr2char",		1, 2, f_nr2char},
Karsten Hopp be6f54
     {"or",		2, 2, f_or},
Karsten Hopp be6f54
     {"pathshorten",	1, 1, f_pathshorten},
Karsten Hopp be6f54
 #ifdef FEAT_FLOAT
Karsten Hopp be6f54
@@ -9303,7 +9303,17 @@ f_char2nr(argvars, rettv)
Karsten Hopp be6f54
 {
Karsten Hopp be6f54
 #ifdef FEAT_MBYTE
Karsten Hopp be6f54
     if (has_mbyte)
Karsten Hopp be6f54
-	rettv->vval.v_number = (*mb_ptr2char)(get_tv_string(&argvars[0]));
Karsten Hopp be6f54
+    {
Karsten Hopp be6f54
+	int	utf8 = 0;
Karsten Hopp be6f54
+
Karsten Hopp be6f54
+	if (argvars[1].v_type != VAR_UNKNOWN)
Karsten Hopp be6f54
+	    utf8 = get_tv_number_chk(&argvars[1], NULL);
Karsten Hopp be6f54
+
Karsten Hopp be6f54
+	if (utf8)
Karsten Hopp be6f54
+	    rettv->vval.v_number = (*utf_ptr2char)(get_tv_string(&argvars[0]));
Karsten Hopp be6f54
+	else
Karsten Hopp be6f54
+	    rettv->vval.v_number = (*mb_ptr2char)(get_tv_string(&argvars[0]));
Karsten Hopp be6f54
+    }
Karsten Hopp be6f54
     else
Karsten Hopp be6f54
 #endif
Karsten Hopp be6f54
     rettv->vval.v_number = get_tv_string(&argvars[0])[0];
Karsten Hopp be6f54
@@ -14360,7 +14370,16 @@ f_nr2char(argvars, rettv)
Karsten Hopp be6f54
 
Karsten Hopp be6f54
 #ifdef FEAT_MBYTE
Karsten Hopp be6f54
     if (has_mbyte)
Karsten Hopp be6f54
-	buf[(*mb_char2bytes)((int)get_tv_number(&argvars[0]), buf)] = NUL;
Karsten Hopp be6f54
+    {
Karsten Hopp be6f54
+	int	utf8 = 0;
Karsten Hopp be6f54
+
Karsten Hopp be6f54
+	if (argvars[1].v_type != VAR_UNKNOWN)
Karsten Hopp be6f54
+	    utf8 = get_tv_number_chk(&argvars[1], NULL);
Karsten Hopp be6f54
+	if (utf8)
Karsten Hopp be6f54
+	    buf[(*utf_char2bytes)((int)get_tv_number(&argvars[0]), buf)] = NUL;
Karsten Hopp be6f54
+	else
Karsten Hopp be6f54
+	    buf[(*mb_char2bytes)((int)get_tv_number(&argvars[0]), buf)] = NUL;
Karsten Hopp be6f54
+    }
Karsten Hopp be6f54
     else
Karsten Hopp be6f54
 #endif
Karsten Hopp be6f54
     {
Karsten Hopp be6f54
diff -up vim73/src/version.c.780 vim73/src/version.c
Karsten Hopp be6f54
--- vim73/src/version.c.780	2013-01-28 13:41:04.000000000 +0100
Karsten Hopp be6f54
+++ src/version.c	2013-01-28 13:41:04.000000000 +0100
Karsten Hopp be6f54
@@ -726,6 +726,8 @@ static char *(features[]) =
Karsten Hopp be6f54
 static int included_patches[] =
Karsten Hopp be6f54
 {   /* Add new patch number below this line */
Karsten Hopp be6f54
 /**/
Karsten Hopp be6f54
+    780,
Karsten Hopp be6f54
+/**/
Karsten Hopp be6f54
     779,
Karsten Hopp be6f54
 /**/
Karsten Hopp be6f54
     778,