about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <p.w.stephenson@ntlworld.com>2015-12-06 16:39:57 +0000
committerPeter Stephenson <p.w.stephenson@ntlworld.com>2015-12-06 16:39:57 +0000
commit87670fb011b638e5bde744a33a047305d17d95c2 (patch)
tree19c135dbff8d825d8eb9fafe69314c29a4097e1c
parent5a76a5d34e75219198d012beed06047fd98c7cae (diff)
downloadzsh-87670fb011b638e5bde744a33a047305d17d95c2.tar.gz
zsh-87670fb011b638e5bde744a33a047305d17d95c2.tar.xz
zsh-87670fb011b638e5bde744a33a047305d17d95c2.zip
37326: comment only: multibyte string lenght/width counting
-rw-r--r--ChangeLog3
-rw-r--r--Src/utils.c11
2 files changed, 14 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index aab22b0c9..2c7b5ad94 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2015-12-06  Peter Stephenson  <p.w.stephenson@ntlworld.com>
 
+	* 37326: Src/utils.c: comment how counting for multibyte string
+	lengths and widths is supposed to work.
+
 	* 37314: Src/utils.c, Src/zsh.h: upgrade quotedzputs() to use
 	nicechar() where necessary.  Regularise nicechar() etc. to prodduce
 	$'...' compatible output.
diff --git a/Src/utils.c b/Src/utils.c
index d1313837d..45f8286df 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -5179,6 +5179,17 @@ mb_metastrlenend(char *ptr, int width, char *eptr)
 	ret = mbrtowc(&wc, &inchar, 1, &mb_shiftstate);
 
 	if (ret == MB_INCOMPLETE) {
+	    /*
+	     * "num_in_char" is only used for incomplete characters.  The
+	     * assumption is that we will output this ocatet as a single
+	     * character (of single width) if we don't get a complete
+	     * character; if we do get a complete character, num_in_char
+	     * becomes irrelevant and is set to zero.
+	     *
+	     * This is in contrast to "num" which counts the characters
+	     * or widths in complete characters.  The two are summed,
+	     * so we don't count characters twice.
+	     */
 	    num_in_char++;
 	} else {
 	    if (ret == MB_INVALID) {