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

Match length and multibyte characters



Hello everybody,

while playing around with zsh expansions, I've stumbled across this
small annoyance that I think might be worth to ask the list about.

Let's suppose I have an array and I want to know the length of the
longest string contained. After going through zshexpn(1), the first
thing I came up with was:

% array=(a bbb cc)
% print ${${(O)array//(#m)*/${#MATCH}}[1]}
3

which is perfectly fine and seems to do the job. Later I found that
the same thing can be accomplished by this.

% print ${${(ON)array%%*}[1]}
3

However, the second version seems to break on multibyte characters
while the first one works just fine:

% array=(a ä a)
% print ${${(O)array//(#m)*/${#MATCH}}[1]} ${${(ON)array%%*}[1]}
1 2

Can maybe someone shed some light on whether the second version is
supposed to work with multibyte characters and, if, what has to be
done to make it count multibyte chars only once just like the first
version does?

regards

erik



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