summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOliver Kiddle <opk@zsh.org>2017-10-11 01:23:42 +0200
committerOliver Kiddle <opk@zsh.org>2017-10-11 01:23:42 +0200
commit233c0e89032950a031c7e559b4f71944d49e4664 (patch)
tree96ffd8564137baa98bc81eddaa888545b5537b00
parentaeed51fdfcdc10b6f866c9ff794c5baa99d1b39e (diff)
downloadzsh-233c0e89032950a031c7e559b4f71944d49e4664.tar.gz
zsh-233c0e89032950a031c7e559b4f71944d49e4664.zip
41835: handle multibyte characters with compset -p and -s
-rw-r--r--ChangeLog5
-rw-r--r--Src/Zle/complete.c48
2 files changed, 42 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index e141f23b5..e7d6e988a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2017-10-10 Oliver Kiddle <opk@zsh.org>
+
+ * 41835: Src/Zle/complete.c: handle multibyte characters with
+ compset -p and -s
+
2017-10-10 Peter Stephenson <p.stephenson@samsung.com>
* uposted, c.f. 41846: Completion/Unix/Command/_expand ->
diff --git a/Src/Zle/complete.c b/Src/Zle/complete.c
index 68bdf2332..16f48c958 100644
--- a/Src/Zle/complete.c
+++ b/Src/Zle/complete.c
@@ -934,19 +934,45 @@ do_comp_vars(int test, int na, char *sa, int nb, char *sb, int mod)
}
case CVT_PRENUM:
case CVT_SUFNUM:
- if (!na)
- return 1;
- if (na > 0 &&
- (int)strlen(test == CVT_PRENUM ? compprefix : compsuffix) >= na) {
- if (mod) {
- if (test == CVT_PRENUM)
- ignore_prefix(na);
- else
- ignore_suffix(na);
- return 1;
- }
+ if (na < 0)
return 0;
+ if (na > 0 && mod) {
+#ifdef MULTIBYTE_SUPPORT
+ if (isset(MULTIBYTE)) {
+ if (test == CVT_PRENUM) {
+ const char *ptr = compprefix;
+ int len = 1;
+ int sum = 0;
+ while (*ptr && na && len) {
+ wint_t wc;
+ len = mb_metacharlenconv(ptr, &wc);
+ ptr += len;
+ sum += len;
+ na--;
+ }
+ if (na)
+ return 0;
+ na = sum;
+ } else {
+ char *end = compsuffix + strlen(compsuffix);
+ char *ptr = end;
+ while (na-- && ptr > compsuffix)
+ ptr = backwardmetafiedchar(compsuffix, ptr, NULL);
+ if (na >= 0)
+ return 0;
+ na = end - ptr;
+ }
+ } else
+#endif
+ if ((int)strlen(test == CVT_PRENUM ? compprefix : compsuffix) >= na)
+ return 0;
+ if (test == CVT_PRENUM)
+ ignore_prefix(na);
+ else
+ ignore_suffix(na);
+ return 1;
}
+ return 1;
case CVT_PREPAT:
case CVT_SUFPAT:
{