diff options
author | Peter Stephenson <pws@users.sourceforge.net> | 2006-06-28 13:12:55 +0000 |
---|---|---|
committer | Peter Stephenson <pws@users.sourceforge.net> | 2006-06-28 13:12:55 +0000 |
commit | 6157c14d0602c698aa9ebfac9a2135ef095a76b4 (patch) | |
tree | cae7cb80281a1426c06734889fd8f0b83292c6ca /Src/utils.c | |
parent | f95a6a913c885932827e9c0219221f7de7ccdd79 (diff) | |
download | zsh-6157c14d0602c698aa9ebfac9a2135ef095a76b4.tar.gz zsh-6157c14d0602c698aa9ebfac9a2135ef095a76b4.tar.xz zsh-6157c14d0602c698aa9ebfac9a2135ef095a76b4.zip |
22525: lengths and cases of multibyte strings in parameters and history
Diffstat (limited to 'Src/utils.c')
-rw-r--r-- | Src/utils.c | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/Src/utils.c b/Src/utils.c index 4b2f07f19..32f6ae336 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -3687,7 +3687,7 @@ static mbstate_t mb_shiftstate; /* * Initialise multibyte state: called before a sequence of - * mb_metacharlen(). + * mb_metacharlenconv(). */ /**/ @@ -3703,18 +3703,24 @@ mb_metacharinit(void) * but character is not valid (e.g. possibly incomplete at end of string). * Returned value is guaranteed not to reach beyond the end of the * string (assuming correct metafication). + * + * If wcp is not NULL, the converted wide character is stored there. + * If no conversion could be done WEOF is used. */ /**/ int -mb_metacharlen(char *s) +mb_metacharlenconv(char *s, wint_t *wcp) { char inchar, *ptr; size_t ret; wchar_t wc; - if (!isset(MULTIBYTE)) + if (!isset(MULTIBYTE)) { + if (wcp) + *wcp = WEOF; return 1 + (*s == Meta); + } ret = MB_INVALID; for (ptr = s; *ptr; ) { @@ -3729,14 +3735,18 @@ mb_metacharlen(char *s) break; if (ret == MB_INCOMPLETE) continue; + if (wcp) + *wcp = wc; return ptr - s; } + if (wcp) + *wcp = WEOF; /* No valid multibyte sequence */ memset(&mb_shiftstate, 0, sizeof(mb_shiftstate)); - if (ptr > s) + if (ptr > s) { return 1 + (*s == Meta); /* Treat as single byte character */ - else + } else return 0; /* Probably shouldn't happen */ } |