Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: handle multibyte chars in compset -p/-s
- X-seq: zsh-workers 41835
- From: Oliver Kiddle <okiddle@xxxxxxxxxxx>
- To: Zsh workers <zsh-workers@xxxxxxx>
- Subject: PATCH: handle multibyte chars in compset -p/-s
- Date: Mon, 09 Oct 2017 11:42:20 +0200
- Authentication-results: amavisd4.gkg.net (amavisd-new); dkim=pass (2048-bit key) header.d=yahoo.co.uk
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.co.uk; s=s2048; t=1507542143; bh=/VgoTvaZjs2amPr9uSS5uTpc04WV06yC9nfAIh8KIqQ=; h=From:References:To:Subject:Date:From:Subject; b=c1VOxrtoaRE2eGeUfNCeKku7U6RvtWO441EuWgxJhaz82v5ihkCXCSre/GyK8Galz1Jgl4gpNuxoPNIuAVf9nr/AJeykpzpY//N2zim+Iw60/g0LbtNHjBYqW5rkc7+fBfcNsSlcE21M+mLF0aK8OfQD3E8+kFHJMDqx40aKjOEXrwjfGMd/dY+z3RYzXOJjhwEggEyIdwx3mB7VfUheYDaq4IvBtYT457Dqp7UNjiKpEEiONGenKNbVk25E4ltV7VZ0vjv/BYKPabrIhzBGQXfNmsoOKVLlKjln5grzW7rTN1NPO6/s8DMBkKEe99vOFsowiiTESdC7A8PC2jE7qg==
- In-reply-to: <22320.1507334630@thecus.kiddle.eu>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <22320.1507334630@thecus.kiddle.eu>
On 7 Oct, I wrote:
> Incidentally, while pondering such a solution, I noticed that
> compset -p is removing bytes rather than characters to IPREFIX which
> would have been useful in this case but should be corrected.
Having further checked uses of compset -p, I'm satisfied that compset -p
and -s should be handling multibyte characters so this is a patch to do
that. Is mb_metacharlenconv and backwardmetafiedchar as used here the
best way to do that?
Oliver
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:
{
Messages sorted by:
Reverse Date,
Date,
Thread,
Author