String matching: Difference between revisions
→{{header|TXR}}: Reorder.
(→{{header|TXR}}: Reorder.) |
|||
Line 2,201:
=={{header|TXR}}==
===
<lang txr>@(do▼
(tree-case *args*▼
((big small)▼
(cond▼
((< (length big) (length small))▼
(put-line `@big is shorter than @small`))▼
((str= big small)▼
(put-line `@big and @small are equal`))▼
((match-str big small)▼
(put-line `@small is a prefix of @big`))▼
((match-str big small -1)▼
(put-line `@small is a suffix of @big`))▼
(t (let ((pos (search-str big small)))▼
(if pos▼
(put-line `@small occurs in @big at position @pos`)▼
(put-line `@small does not occur in @big`))))))▼
(otherwise▼
(put-line `usage: @(ldiff *full-args* *args*) <bigstring> <smallstring>`))))</lang>▼
{{out}}▼
<pre>$ txr cmatch2.txr x▼
usage: txr cmatch2.txr <bigstring> <smallstring>▼
$ txr cmatch2.txr x y z▼
usage: txr cmatch2.txr <bigstring> <smallstring>▼
$ txr cmatch2.txr catalog cat▼
cat is a prefix of catalog▼
$ txr cmatch2.txr catalog log▼
log is a suffix of catalog▼
$ txr cmatch2.txr catalog at▼
at occurs in catalog at position 1▼
$ txr cmatch2.txr catalog catalogue▼
catalog is shorter than catalogue▼
$ txr cmatch2.txr catalog catalog▼
catalog and catalog are equal▼
$ txr cmatch2.txr catalog dog▼
dog does not occur in catalog</pre>▼
===Pattern Language===
<lang txr>@line
Line 2,242 ⟶ 2,278:
0123
first line is a suffix of the second line</pre>
▲<lang txr>@(do
▲ (tree-case *args*
▲ ((big small)
▲ (cond
▲ ((< (length big) (length small))
▲ (put-line `@big is shorter than @small`))
▲ ((str= big small)
▲ (put-line `@big and @small are equal`))
▲ ((match-str big small)
▲ (put-line `@small is a prefix of @big`))
▲ ((match-str big small -1)
▲ (put-line `@small is a suffix of @big`))
▲ (t (let ((pos (search-str big small)))
▲ (if pos
▲ (put-line `@small occurs in @big at position @pos`)
▲ (put-line `@small does not occur in @big`))))))
▲ (otherwise
▲ (put-line `usage: @(ldiff *full-args* *args*) <bigstring> <smallstring>`))))</lang>
▲{{out}}
▲<pre>$ txr cmatch2.txr x
▲usage: txr cmatch2.txr <bigstring> <smallstring>
▲$ txr cmatch2.txr x y z
▲usage: txr cmatch2.txr <bigstring> <smallstring>
▲$ txr cmatch2.txr catalog cat
▲cat is a prefix of catalog
▲$ txr cmatch2.txr catalog log
▲log is a suffix of catalog
▲$ txr cmatch2.txr catalog at
▲at occurs in catalog at position 1
▲$ txr cmatch2.txr catalog catalogue
▲catalog is shorter than catalogue
▲$ txr cmatch2.txr catalog catalog
▲catalog and catalog are equal
▲$ txr cmatch2.txr catalog dog
▲dog does not occur in catalog</pre>
=={{header|XPL0}}==
|