1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-28 05:00:59 +01:00

23562: add KSH_ZERO_SUBSCRIPT option and leave off by default

This commit is contained in:
Peter Stephenson 2007-06-18 13:25:03 +00:00
parent 5c44b0a472
commit abae4fe16e
17 changed files with 225 additions and 75 deletions

View file

@ -91,8 +91,13 @@
>3.5
>4
(( newarray[unsetvar]++ ))
(( newarray[unsetvar]++ ))
(( newarray[unsetvar] = 1 ))
2:error using unset variable as index
?(eval):1: assignment to invalid subscript range
integer setvar=1
(( newarray[setvar]++ ))
(( newarray[setvar]++ ))
print ${(t)newarray} ${#newarray} ${newarray[1]}
0:setting array elements in math context
>array 1 2

View file

@ -30,12 +30,12 @@
>..
echo .$foo[0].
0:Treat 0 like 1
>.a.
0:Treat 0 as empty
>..
echo .$foo[0,0].
0:Treat 0,0 like 1,1.
>.a.
0:Treat 0,0 as empty
>..
echo .$foo[0,1].
0:Another weird way to access the first element

View file

@ -182,3 +182,56 @@
echo X${${l##*}[-1]}X
0:Negative index applied to substition result from empty array
>XX
array=(one two three four)
print X$array[0]X
0:Element zero is empty if KSH_ZERO_SUBSCRIPT is off.
>XX
array[0]=fumble
1:Can't set element zero if KSH_ZERO_SUBSCRIPT is off.
?(eval):1: array: assignment to invalid subscript range
print X$array[(R)notfound]X
0:(R) returns empty if not found if KSH_ZERO_SUBSCRIPT is off.
>XX
setopt KSH_ZERO_SUBSCRIPT
print X$array[0]X
0:Element zero is element one if KSH_ZERO_SUBSCRIPT is on.
>XoneX
array[0]=fimble
print $array
0:Can set element zero if KSH_ZERO_SUBSCRIPT is on.
>fimble two three four
print X$array[(R)notfound]X
0:(R) yuckily returns the first element on failure withe KSH_ZERO_SUBSCRIPT
>XfimbleX
unsetopt KSH_ZERO_SUBSCRIPT
array[(R)notfound,(r)notfound]=(help help here come the seventies retreads)
print $array
0:[(R)notfound,(r)notfound] replaces the whole array
>help help here come the seventies retreads
string="Why, if it isn't Officer Dibble"
print "[${string[0]}][${string[1]}][${string[0,3]}]"
0:String subscripts with KSH_ZERO_SUBSCRIPT unset
>[][W][Why]
setopt KSH_ZERO_SUBSCRIPT
print "[${string[0]}][${string[1]}][${string[0,3]}]"
0:String subscripts with KSH_ZERO_SUBSCRIPT set
>[W][W][Why]
unsetopt KSH_ZERO_SUBSCRIPT
string[0,3]="Goodness"
print $string
0:Assignment to chunk of string ignores element 0
>Goodness, if it isn't Officer Dibble
string[0]=!
1:Can't set only element zero of string
?(eval):1: string: assignment to invalid subscript range

View file

@ -88,7 +88,7 @@
s=é
print A${s[-2]}A B${s[-1]}B C${s[0]}C D${s[1]}D E${s[2]}E
0:Out of range subscripts with multibyte characters
>AA BéB CéC DéD EE
>AA BéB CC DéD EE
print ${a[(i)é]} ${a[(I)é]} ${a[${a[(i)é]},${a[(I)é]}]}
0:Reverse indexing with multibyte characters

View file

@ -521,7 +521,7 @@
>one one[2]
>one two three
>one two three two
>one one two three
>one two three
fpath=(.)
echo >foo 'echo foo loaded; foo() { echo foo run; }'