Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit f718e4b

Browse files
committed
[Bug 14846] com.livecode.list: Fix "offset after" and "offset before"
1 parent a8eb62b commit f718e4b

4 files changed

Lines changed: 15 additions & 24 deletions

File tree

libfoundation/src/foundation-proper-list.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ MCProperListLastOffsetOfListInRange (MCProperListRef self,
573573
* possible match, relative to the last element in the range
574574
* (i.e. t_roffset = 0 for the last element). */
575575
for (uindex_t t_roffset = p_needle->length - 1;
576-
t_roffset <= p_range.length;
576+
t_roffset < p_range.length;
577577
++t_roffset)
578578
{
579579
/* Offset of first element in the match, relative to start of

libscript/src/list.mlc

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,32 +1019,29 @@ Example:
10191019
variable tOffset as Number
10201020
put ["a", "b", "c", "d", "b", "c"]
10211021
put the offset of ["b","c"] after 1 in tVar into tOffset
1022-
--tOffset contains 1
1022+
--tOffset contains 2
10231023

10241024
put the last offset of ["b","c"] after 1 in tVar into tOffset
1025-
--tOffset contains 4
1025+
--tOffset contains 5
10261026

10271027
Description:
10281028

10291029
Use `the offset of… after` to find where a particular sub-list occurs
10301030
within a list. Starting from but not including the position <After>,
10311031
<Haystack> is scanned for an sequence of elements that are equal to
1032-
the elements of <Needle>, and the position relative to <After> of the
1033-
start of the sequence found is returned. If neither the "first
1034-
offset" nor "last offset" are specified, the position of the first
1035-
matching sub-list found is returned. If no sub-list of <Haystack>
1036-
starting after the position <After> is equal to <Needle>, the return
1037-
value is 0.
1032+
the elements of <Needle>, and the position of the start of the
1033+
sequence found is returned. If neither the "first offset" nor "last
1034+
offset" are specified, the position of the first matching sub-list
1035+
found is returned. If no sub-list of <Haystack> starting after the
1036+
position <After> is equal to <Needle>, the return value is 0.
10381037

10391038
Tags: Lists
10401039
*/
1041-
/* bug 14846
10421040
syntax ListOffsetAfter is prefix operator with precedence 1
10431041
"the" ( "first" <IsLast=false> | "last" <IsLast=true> | <IsLast=false> ) "offset" "of" <Needle: Expression> "after" <After: Expression> "in" <Haystack: Expression>
10441042
begin
10451043
MCListEvalOffsetOfListAfter(IsLast, Needle, After, Haystack, output)
10461044
end syntax
1047-
*/
10481045

10491046
/*
10501047
Summary: Find the first or last occurrence of <Needle> within the head of <Haystack>
@@ -1077,12 +1074,10 @@ is equal to <Needle>, the return value is 0. If neither "first" nor
10771074

10781075
Tags: Lists
10791076
*/
1080-
/* bug 14846
10811077
syntax ListOffsetBefore is prefix operator with precedence 1
10821078
"the" ( "first" <IsLast=false> | "last" <IsLast=true> | <IsLast=true> ) "offset" "of" <Needle: Expression> "before" <Before: Expression> "in" <Haystack: Expression>
10831079
begin
10841080
MCListEvalOffsetOfListBefore(IsLast, Needle, Before, Haystack, output)
10851081
end syntax
1086-
*/
10871082

10881083
end module

libscript/src/module-list.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ MCListEvalOffsetOfListInRange (bool p_is_last,
552552
p_range, t_offset);
553553

554554
if (t_found)
555-
r_output = t_offset + 1;
555+
r_output = t_offset + p_range.offset + 1;
556556
else
557557
r_output = 0;
558558
}

tests/lcb/stdlib/list.lcb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,6 @@ end handler
566566

567567
----------------------------------------------------------------
568568

569-
/* bug 14846
570569
handler TestOffsetAfter_InvalidPositive()
571570
return the offset of [true] after 2 in [true]
572571
end handler
@@ -589,8 +588,8 @@ public handler TestOffsetAfter()
589588
variable t
590589
put [true, false, true, true, false] into t
591590

592-
test "offset after (+ve)" when the offset of [true,false] after 1 in t is 3
593-
test "offset after (-ve)" when the offset of [true,false] after -5 in t is 3
591+
test "offset after (+ve)" when the offset of [true,false] after 1 in t is 4
592+
test "offset after (-ve)" when the offset of [true,false] after -5 in t is 4
594593
test "offset after (-ve, limit)" when the offset of [true,false] after -6 in t is 1
595594
test "offset after (+ve, missing)" when the offset of [false,true] after 2 in t is 0
596595
test "offset after (-ve, missing)" when the offset of [false,true] after -4 in t is 0
@@ -602,8 +601,8 @@ public handler TestFirstOffsetAfter()
602601
variable t
603602
put [true, false, true, true, false] into t
604603

605-
test "first offset after (+ve)" when the first offset of [true,false] after 1 in t is 3
606-
test "first offset after (-ve)" when the first offset of [true,false] after -5 in t is 3
604+
test "first offset after (+ve)" when the first offset of [true,false] after 1 in t is 4
605+
test "first offset after (-ve)" when the first offset of [true,false] after -5 in t is 4
607606
test "first offset after (-ve, limit)" when the first offset of [true,false] after -6 in t is 1
608607
test "first offset after (+ve, missing)" when the first offset of [false,true] after 2 in t is 0
609608
test "first offset after (-ve, missing)" when the first offset of [false,true] after -4 in t is 0
@@ -615,8 +614,8 @@ public handler TestLastOffsetAfter()
615614
variable t
616615
put [true, false, true, true, false] into t
617616

618-
test "last offset after (+ve)" when the last offset of [true] after 1 in t is 3
619-
test "last offset after (-ve)" when the last offset of [true] after -5 in t is 3
617+
test "last offset after (+ve)" when the last offset of [true] after 1 in t is 4
618+
test "last offset after (-ve)" when the last offset of [true] after -5 in t is 4
620619
test "last offset after (-ve, limit)" when the last offset of [true] after -6 in t is 4
621620
test "last offset after (+ve, missing)" when the last offset of [true] after 4 in t is 0
622621
test "last offset after (-ve, missing)" when the last offset of [true] after -2 in t is 0
@@ -639,11 +638,9 @@ public handler TestOffsetAfterZero()
639638
put the last offset of [true,false] in t into tNoAfter
640639
test "last offset after (+ve, 0)" when the last offset of [true,false] after 0 in t is tNoAfter
641640
end handler
642-
*/
643641

644642
----------------------------------------------------------------
645643

646-
/* bug 14846
647644
handler TestOffsetBefore_InvalidPositive()
648645
return the offset of [true] before 3 in [true]
649646
end handler
@@ -716,6 +713,5 @@ public handler TestOffsetBeforeZero()
716713
put the last offset of [true,false] in t into tNoBefore
717714
test "last offset before (+ve, 0)" when the last offset of [true,false] before 0 in t is tNoBefore
718715
end handler
719-
*/
720716

721717
end module

0 commit comments

Comments
 (0)