Next: Eager comprehensions, Previous: Insertions and deletions, Up: rope API [Contents][Index]
Searches for the string pattern in rope and returns the
first index that matches or #f. Characters are compared with
c= (default: char=?). The Knutth-Pratt-Morris algorithm
(see SRFI-13).
The algorithm uses O(m) memory and O(p + m) time, where
m is the length of the pattern and p is the length
of the rope.
(define r (string->random-rope "I have never known any distress\ that an hour's reading did not relieve.")) ;; Search for an exact match. (rope-contains r "distress") ⇒ 23 ;; Search case-independently. (rope-contains r "HOUR'S" char-ci=?) ⇒ 40 ;; A search that fails. (rope-contains r "Montesquieu") ⇒ #f
Example 2.10: Searching text in a rope.