Skip to content

Commit 8077407

Browse files
committed
CHANGE: Make find/match not imply /tail
related to: red/red#4943
1 parent 547f357 commit 8077407

9 files changed

+30
-18
lines changed

src/boot/actions.reb

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ find: action [
208208
/last {Backwards from end of series}
209209
/reverse {Backwards from the current position}
210210
/tail {Returns the end of the series}
211-
/match {Performs comparison and returns the tail of the match}
211+
/match {Performs comparison and returns the head of the match (not imply /tail)}
212212
]
213213

214214
select: action [

src/core/s-find.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@
328328
for (n = 1; n < l2; n++) {
329329
if (b1[n] != b2[n]) break;
330330
}
331-
if (n == l2) return (b1 - BIN_HEAD(series) + (match ? l2 : 0));
331+
if (n == l2) return (b1 - BIN_HEAD(series));
332332
}
333333
b1++;
334334
}
@@ -342,7 +342,7 @@
342342
for (n = 1; n < l2; n++) {
343343
if (LO_CASE(b1[n]) != LO_CASE(b2[n])) break;
344344
}
345-
if (n == l2) return (b1 - BIN_HEAD(series) + (match ? l2 : 0));
345+
if (n == l2) return (b1 - BIN_HEAD(series));
346346
}
347347
b1++;
348348
}
@@ -536,7 +536,7 @@
536536
}
537537
if (n == len) {
538538
found:
539-
if (flags & (AM_FIND_TAIL | AM_FIND_MATCH))
539+
if (flags & AM_FIND_TAIL)
540540
return pos;
541541
return start ;
542542
}

src/core/t-block.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ static struct {
800800
if (ret >= (REBCNT)tail) goto is_none;
801801
if (args & AM_FIND_ONLY) len = 1;
802802
if (action == A_FIND) {
803-
if (args & (AM_FIND_TAIL | AM_FIND_MATCH)) ret += len;
803+
if (args & AM_FIND_TAIL) ret += len;
804804
VAL_INDEX(value) = ret;
805805
}
806806
else {

src/core/t-image.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -861,8 +861,8 @@ INLINE REBCNT ARGB_To_BGR(REBCNT i)
861861
n = (REBCNT)(p - (REBCNT *)VAL_IMAGE_HEAD(value));
862862
if (refs & AM_FIND_MATCH) { // match
863863
if (n != (REBINT)index) goto find_none;
864-
n++;
865-
} else if (refs & AM_FIND_TAIL) n++; // /tail
864+
}
865+
if (refs & AM_FIND_TAIL) n++; // /tail
866866
index = n;
867867
VAL_INDEX(value) = index;
868868
return value;

src/mezz/codec-json.reb

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ BOM: [
6565
]
6666

6767
BOM-UTF-16?: func [data [string! binary!]][
68-
any [find/match data BOM/UTF-16-BE find/match data BOM/UTF-16-LE]
68+
any [find/match/tail data BOM/UTF-16-BE find/match/tail data BOM/UTF-16-LE]
6969
]
7070

7171
BOM-UTF-32?: func [data [string! binary!]][
72-
any [find/match data BOM/UTF-32-BE find/match data BOM/UTF-32-LE]
72+
any [find/match/tail data BOM/UTF-32-BE find/match/tail data BOM/UTF-32-LE]
7373
]
7474

7575

src/mezz/mezz-files.reb

+2-2
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,10 @@ to-relative-file: func [
327327
either string? file [ ; Local file
328328
; Note: to-local-file drops trailing / in R2, not in R3
329329
; if tmp: find/match file to-local-file what-dir [file: next tmp]
330-
file: any [find/match file to-local-file what-dir file]
330+
file: any [find/match/tail file to-local-file what-dir file]
331331
if as-rebol [file: to-rebol-file file no-copy: true]
332332
] [
333-
file: any [find/match file what-dir file]
333+
file: any [find/match/tail file what-dir file]
334334
if as-local [file: to-local-file file no-copy: true]
335335
]
336336
unless no-copy [file: copy file]

src/mezz/mezz-help.reb

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ import module [
145145
not match
146146
either string? :pattern [
147147
either wild [
148-
tail? any [find/any/match str pattern pattern]
148+
tail? any [find/any/match/tail str pattern pattern]
149149
][
150150
find str pattern
151151
]

src/tests/units/image-test.r3

+2-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ if value? 'blur [
400400
--assert 2 = index? find/only img 66.66.66
401401
--assert 2 = index? find/only img 66.66.66.22
402402
--assert none? find img 66.66.66.22
403-
--assert 2 = index? find/match img 255.255.255
403+
--assert 1 = index? find/match img 255.255.255
404+
--assert 2 = index? find/match/tail img 255.255.255
404405

405406
--test-- "FIND integer on image (alpha)"
406407
img: make image! 2x2 img/2: 66.66.66.66

src/tests/units/series-test.r3

+16-5
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@ Rebol [
1818
--assert none? find/part [x] 'x 0
1919
--assert equal? [x] find/part [x] 'x 1
2020
--assert equal? [x] find/reverse tail [x] 'x
21-
--assert equal? [y] find/match [x y] 'x
21+
--assert equal? [x y] find/match [x y] 'x
22+
--assert equal? [y] find/match/tail [x y] 'x
2223
--assert equal? [x] find/last [x] 'x
2324
--assert equal? [x] find/last [x x x] 'x
2425

2526
--test-- "FIND string! integer!"
2627
;@@ https://github.com/Oldes/Rebol-issues/issues/237
2728
--assert "23" = find "123" 2
2829

30+
--test-- "FIND binary! binary!"
31+
--assert #{0001} = find/match #{0001} #{00}
32+
--assert #{01} = find/match/tail #{0001} #{00}
33+
--assert #{02} = find #{000102} #{02}
34+
--assert #{} = find/tail #{000102} #{02}
35+
2936
--test-- "FIND string! tag!"
3037
;@@ https://github.com/Oldes/Rebol-issues/issues/1160
3138
--assert "<a>" = find "<a>" <a>
@@ -58,8 +65,10 @@ Rebol [
5865
--assert "" = find/any/tail "abcd" "*d"
5966
--assert "" = find/any/tail "abcd" "c*"
6067
--assert "ef" = find/any/tail "abcdef" "b*d"
61-
--assert "" = find/any/match "abc" "a?c"
62-
--assert "" = find/any/match "abcdef" "a*e?"
68+
--assert "abc" = find/any/match "abc" "a?c"
69+
--assert "abcdef"= find/any/match "abcdef" "a*e?"
70+
--assert "" = find/any/match/tail "abc" "a?c"
71+
--assert "" = find/any/match/tail "abcdef" "a*e?"
6372
--assert "bcd" = find/any/reverse tail "abcdabcd" "?c"
6473
--assert "d" = find/any/reverse/tail tail "abcdabcd" "?c"
6574
--assert "d" = find/any/reverse/tail tail "abcdabcd" "bc"
@@ -77,8 +86,10 @@ Rebol [
7786
--assert "žcdef" = find/any "ažcdef" "ž*?*e"
7887
--assert "" = find/any/tail "ažcd" "*d"
7988
--assert "ef" = find/any/tail "ažcdef" "ž*d"
80-
--assert "" = find/any/match "ažc" "a?c"
81-
--assert "" = find/any/match "ažcdef" "a*e?"
89+
--assert "ažc" = find/any/match "ažc" "a?c"
90+
--assert "ažcdef"= find/any/match "ažcdef" "a*e?"
91+
--assert "" = find/any/match/tail "ažc" "a?c"
92+
--assert "" = find/any/match/tail "ažcdef" "a*e?"
8293
--assert "žcd" = find/any/reverse tail "ažcdažcd" "?c"
8394
--assert "d" = find/any/reverse/tail tail "ažcdažcd" "?c"
8495
--assert "d" = find/any/reverse/tail tail "ažcdažcd" "žc"

0 commit comments

Comments
 (0)