chickadee » srfi-135 » textual-index-right

(textual-index textual pred [start end]) → idx-or-falseprocedure
(textual-index-right textual pred [start end]) → idx-or-falseprocedure
(textual-skip textual pred [start end]) → idx-or-falseprocedure
(textual-skip-right textual pred [start end]) → idx-or-falseprocedure

textual-index searches through the given subtext or substring from the left, returning the index of the leftmost character satisfying the predicate pred. textual-index-right searches from the right, returning the index of the rightmost character satisfying the predicate pred. If no match is found, these procedures return #f.

The start and end arguments specify the beginning and end of the search; the valid indexes relevant to the search include start but exclude end. Beware of "fencepost" errors: when searching right-to-left, the first index considered is (- end 1), whereas when searching left-to-right, the first index considered is start. That is, the start/end indexes describe the same half-open interval [start,end) in these procedures that they do in all other procedures specified by this SRFI.

The skip functions are similar, but use the complement of the criterion: they search for the first char that doesn't satisfy pred. To skip over initial whitespace, for example, say

(subtextual text
            (or (textual-skip text char-whitespace?)
                (textual-length text))
            (textual-length text))

These functions can be trivially composed with textual-take and textual-drop to produce take-while, drop-while, span, and break procedures without loss of efficiency.