Leonardus
Analogous LeoScript Operator search

STACK

$ S_{str}\ S_{seek}\ --\ S_{post}\ S_{match}\ S_{pre}\ B_{true} $
$ S_{str}\ S_{seek}\ --\ S_{str}\ B_{false} $

DESCRIPTION

Red book operator looks for the first occurrence of the string $ S_{seek} $ within $ S_{str} $ and
returns the results of this search on the operand stack.
The topmost result is a boolean literal that indicates whether the search succeeded.

If search finds a subsequence of $ S_{str} $ whose elements are equal to the elements of $ S_{seek} $,
it splits $ S_{str} $ into three segments:

  • $ S_{pre} $: the portion of string preceding the match,
  • $ S_{match} $: the portion of $ S_{str} $ that matches $ S_{seek} $ and
  • $ S_{post} $: the remainder of $ S_{str} $.

It then pushes the string objects $ S_{post} $, $ S_{match} $, and $ S_{pre} $ on the operand stack,
followed by the boolean literal true.

If search does not find a match, it pushes the original $ S_{str} $ followed by false.

ORIGIN

Core code registered in systemdict.