Jump to content

String matching: Difference between revisions

m
→‎TXR Lisp: Drop @(do ...); rename script to cmatch2.tl
(→‎{{header|Fortran}}: added modern fortran version)
m (→‎TXR Lisp: Drop @(do ...); rename script to cmatch2.tl)
Line 2,757:
===TXR Lisp===
 
<lang txrtxrlisp>@(dotree-case *args*
((big small)
(tree-case *args*
((big small)cond
((< (length big) (condlength small))
(put-line `@big is shorter ((< (length big) (lengththan @small`))
(put-line(str= `@big is shorter than @small`))
(put-line `@big and @small ((str=are big smallequal`))
(put(match-linestr `@big and @small are equal`))
(put-line `@small is a ((match-strprefix of @big small`))
(put(match-linestr big `@small is a prefix of @big`)-1)
(put-line `@small is a ((match-strsuffix of @big small -1`))
(t (let ((pos (putsearch-linestr big `@small is a suffix of @big`)))
(tif (let ((pos (search-str big small)))
(put-line `@small occurs (ifin @big at position @pos`)
(put-line `@small occursdoes not occur in @big at position @pos`))))))
(otherwise
(put-line `@small does not occur in @big`))))))
(put-line `usage: @(ldiff *full-args* *args*) <bigstring> <smallstring>`))))</lang>
(otherwise
(put-line `usage: @(ldiff *full-args* *args*) <bigstring> <smallstring>`))))</lang>
{{out}}
<pre>$ txr cmatch2.txrtl x
usage: txr cmatch2.txrtl <bigstring> <smallstring>
$ txr cmatch2.txrtl x y z
usage: txr cmatch2.txrtl <bigstring> <smallstring>
$ txr cmatch2.txrtl catalog cat
cat is a prefix of catalog
$ txr cmatch2.txrtl catalog log
log is a suffix of catalog
$ txr cmatch2.txrtl catalog at
at occurs in catalog at position 1
$ txr cmatch2.txrtl catalog catalogue
catalog is shorter than catalogue
$ txr cmatch2.txrtl catalog catalog
catalog and catalog are equal
$ txr cmatch2.txrtl catalog dog
dog does not occur in catalog</pre>
 
543

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.