Skip to content

Commit 34df085

Browse files
committed
FIX: find/any returning incorrect result
resolves: Oldes/Rebol-issues#2522
1 parent 173758c commit 34df085

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/core/s-find.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,12 @@
482482

483483
for (; index >= head && index < tail; index += skip) {
484484
n = 1;
485-
start = pos = index;
485+
pos = index;
486486
if (c2 == c_some) {
487487
n = 0;
488488
goto some_loop;
489489
}
490+
start = pos;
490491
if (c2 == c_one) {
491492
c1 = c2;
492493
} else {
@@ -515,10 +516,12 @@
515516
while (1) {
516517
if (pos < head || pos >= tail) return NOT_FOUND;
517518
c1 = GET_ANY_CHAR(ser1, pos);
519+
// printf("? %c == %c\n", c1, c3);
518520
if (c1 == c3) break;
519521
if (uncase && c1 < UNICODE_CASES && c3 < UNICODE_CASES) {
520522
if (LO_CASE(c1) == LO_CASE(c3)) break;
521523
}
524+
index++;
522525
pos++;
523526
}
524527
} else if (c3 == c_one) {

src/tests/units/series-test.r3

+18
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ Rebol [
9494
--assert "bcd" = find/any/reverse tail "abcdabcd" "?c"
9595
--assert "d" = find/any/reverse/tail tail "abcdabcd" "?c"
9696
--assert "d" = find/any/reverse/tail tail "abcdabcd" "bc"
97+
--assert %abcabc = find/any %abcabc %*bc
98+
--assert %abxabc = find/any %abxabc %*bc
99+
--assert %abcabc = find/any %abcabc %ab*
100+
--assert %cxbc = find/any %abcxbc %c*bc
101+
--assert %cxbc = find/any %abcxbc %c?bc
102+
--assert none? find/any %abxabc %c*bc
103+
--assert none? find/any %abcxxbc %c?bc
104+
--assert %cxxbc = find/any %abcxxbc %c??bc
105+
--assert %cxxbcx = find/any %abcxxbcx %c??bc
106+
--assert %x = find/any/tail %abcxxbcx %c??bc
107+
--assert %abc = find/any/tail %abcabc %*bc
108+
--assert %"" = find/any/tail %abxabc %*bc
109+
--assert "abxcd" = find/any "abxcd" "ab*cd"
110+
--assert "abxxcd" = find/any "abxxcd" "ab*cd"
111+
--assert none? find/any "abxcx" "ab*cd"
112+
--assert "abxcx" = find/any "abxcx" "ab*c?"
113+
--assert "abxcxe" = find/any "abxcxe" "ab*c?e"
114+
97115

98116
--test-- "FIND/ANY on string (unicode)"
99117
--assert "ažcd" = find/any "ažcd" "ažc"

0 commit comments

Comments
 (0)