Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: unset arbitrary associative array element



2018-08-11 16:55:33 +0200, Sebastian Gniazdowski:
> On Sat, 11 Aug 2018 at 13:22, Stephane Chazelas
> <stephane.chazelas@xxxxxxxxx> wrote:
> > Is there any other way, other than recreating the full array
> > with something like:
> >
> > hash=("${(@kv)hash[(I)^$key]}") # untested
> 
> I once reported some unset-key impossibilities, and Bart and Peter
> added a (b) flag. Maybe it helps here too. Could someone recall what
> this flag does?
[...]

Thanks Sebastian,

  unset "hash[${(b)key}]"

does work for keys with "]" or "\" and for characters that
contain bytes 0x5c/5d, but not for the empty key.

Sounds like that problem can be fixed by allowing

  unset 'hash[]'

like in ksh93. It would also be useful to allow

  hash[]=value

as well (k=; hash[$k]=value and hash+=('' value) do work).

As for the characters with byte 0x5c in their content, that's a
more general problem.

If you want to test, try for instance:

  LC_ALL=zh_HK.big5hkscs luit

And within luit:

  hash[α]=foo
  # and so on

α in BIG5 or BIG5-HKSCS is encoded as 0xa3 0x5c, 0x5c also being
the encoding of \. ${(b)key} for key='α' expands to α\ (0xa3
0x5c 0x5c).

That trailing 0x5c in the encoding of α is taken as a backslash
in many contexts in zsh.

Beside BIG5 and BIG5-HKSCS, GBK and GB18030 charsets also have
characters that contain 0x5c.

It may not be worth fixing if Chinese/Thai people have all
switched to UTF-8 by now.

-- 
Stephane



Messages sorted by: Reverse Date, Date, Thread, Author