Skip to content

Commit

Permalink
FIX: find/any returning incorrect result
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Oct 14, 2022
1 parent 173758c commit 34df085
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/core/s-find.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,12 @@

for (; index >= head && index < tail; index += skip) {
n = 1;
start = pos = index;
pos = index;
if (c2 == c_some) {
n = 0;
goto some_loop;
}
start = pos;
if (c2 == c_one) {
c1 = c2;
} else {
Expand Down Expand Up @@ -515,10 +516,12 @@
while (1) {
if (pos < head || pos >= tail) return NOT_FOUND;
c1 = GET_ANY_CHAR(ser1, pos);
// printf("? %c == %c\n", c1, c3);
if (c1 == c3) break;
if (uncase && c1 < UNICODE_CASES && c3 < UNICODE_CASES) {
if (LO_CASE(c1) == LO_CASE(c3)) break;
}
index++;
pos++;
}
} else if (c3 == c_one) {
Expand Down
18 changes: 18 additions & 0 deletions src/tests/units/series-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,24 @@ Rebol [
--assert "bcd" = find/any/reverse tail "abcdabcd" "?c"
--assert "d" = find/any/reverse/tail tail "abcdabcd" "?c"
--assert "d" = find/any/reverse/tail tail "abcdabcd" "bc"
--assert %abcabc = find/any %abcabc %*bc
--assert %abxabc = find/any %abxabc %*bc
--assert %abcabc = find/any %abcabc %ab*
--assert %cxbc = find/any %abcxbc %c*bc
--assert %cxbc = find/any %abcxbc %c?bc
--assert none? find/any %abxabc %c*bc
--assert none? find/any %abcxxbc %c?bc
--assert %cxxbc = find/any %abcxxbc %c??bc
--assert %cxxbcx = find/any %abcxxbcx %c??bc
--assert %x = find/any/tail %abcxxbcx %c??bc
--assert %abc = find/any/tail %abcabc %*bc
--assert %"" = find/any/tail %abxabc %*bc
--assert "abxcd" = find/any "abxcd" "ab*cd"
--assert "abxxcd" = find/any "abxxcd" "ab*cd"
--assert none? find/any "abxcx" "ab*cd"
--assert "abxcx" = find/any "abxcx" "ab*c?"
--assert "abxcxe" = find/any "abxcxe" "ab*c?e"


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

0 comments on commit 34df085

Please # to comment.