about summary refs log tree commit diff
path: root/Src/utils.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2007-01-08 22:05:54 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2007-01-08 22:05:54 +0000
commit94bdf92a06df1aaa1881b14dd7244900222f0551 (patch)
treea3814dabc90b991a5f66c03c6d445e6608aa37d5 /Src/utils.c
parentaab842a0c6c16805120f8390574844478dcb8bbc (diff)
downloadzsh-94bdf92a06df1aaa1881b14dd7244900222f0551.tar.gz
zsh-94bdf92a06df1aaa1881b14dd7244900222f0551.tar.xz
zsh-94bdf92a06df1aaa1881b14dd7244900222f0551.zip
23097: splitting of $'...' strings in completion
Diffstat (limited to 'Src/utils.c')
-rw-r--r--Src/utils.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/Src/utils.c b/Src/utils.c
index d4bf6c2eb..6faf196a9 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -3925,7 +3925,6 @@ mb_niceformat(const char *s, FILE *stream, char **outstrp, int heap)
     ptr = unmetafy(ums, &umlen);
 
     memset(&mbs, 0, sizeof mbs);
-    mb_metacharinit();
     while (umlen > 0) {
 	size_t cnt = eol ? MB_INVALID : mbrtowc(&c, ptr, umlen, &mbs);
 
@@ -4577,10 +4576,27 @@ ucs4toutf8(char *dest, unsigned int wval)
 /*
  * Decode a key string, turning it into the literal characters.
  * The value returned is a newly allocated string from the heap.
- * The length is (usually) returned in *len.
+ *
+ * The length is returned in *len.  This is usually the length of
+ * the final unmetafied string.  The exception is the case of
+ * a complete GETKEY_DOLLAR_QUOTE conversion where *len is the
+ * length of the input string which has been used (up to and including
+ * the terminating single quote); as the final string is metafied and
+ * NULL-terminated its length is not required.  If both GETKEY_DOLLAR_QUOTE
+ * and GETKEY_UPDATE_OFFSET are present in "how", the string is not
+ * expected to be terminated (this is used in completion to parse
+ * a partial $'...'-quoted string) and the length passed back is
+ * that of the converted string.  Note in both cases that this is a length
+ * in bytes (i.e. the same as given by a raw pointer difference), not
+ * characters, which may occupy multiple bytes.
+ *
  * how is a set of bits from the GETKEY_ values defined in zsh.h;
  * not all combinations of bits are useful.  Callers will typically
  * use one of the GETKEYS_ values which define sets of bits.
+ * Note, for example that:
+ * - GETKEY_SINGLE_CHAR must not be combined with GETKEY_DOLLAR_QUOTE.
+ * - GETKEY_UPDATE_OFFSET is only allowed if GETKEY_DOLLAR_QUOTE is
+ *   also present.
  *
  * The return value is unmetafied unless GETKEY_DOLLAR_QUOTE is
  * in use.
@@ -4946,9 +4962,9 @@ getkeystring(char *s, int *len, int how, int *misc)
     if (how & GETKEY_DOLLAR_QUOTE)
 	*tdest = '\0';
     if (how & GETKEY_SINGLE_CHAR)
-      *misc = 0;
+	*misc = 0;
     else
-      *len = t - buf;
+	*len = ((how & GETKEY_DOLLAR_QUOTE) ? tdest : t) - buf;
     return buf;
 }