RosettaCodeData/Task/String-matching/Quackery/string-matching.quackery

24 lines
678 B
Plaintext

[ tuck size split drop = ] is starts ( [ [ --> b )
[ tuck size negate split nip = ] is ends ( [ [ --> b )
[ 2dup = iff true
else
[ over [] = iff false done
2dup starts iff true done
dip behead nip again ]
dip 2drop ] is contains ( [ [ --> b )
[ iff
[ say "true" ]
else
[ say "false" ] ] is echobool ( b --> )
$ "abcdefgh" $ "abc" starts echobool cr
$ "abcdefgh" $ "xyz" starts echobool cr
$ "abcdefgh" $ "fgh" ends echobool cr
$ "abcdefgh" $ "xyz" ends echobool cr
$ "abcdefgh" $ "cde" contains echobool cr
$ "abcdefgh" $ "xyz" contains echobool cr