# You are allowed to redistribute it and sell it, alone or is a part of
# another product.
-# This module is about string search and matching.
-# It includes some good features
+# Basic string search, match and replace.
package string_search
import string
-# Patterns are string motifs.
+# Patterns are abstract string motifs (include `String' and `Char').
interface Pattern
# Search `self' into `s' from a certain position.
# Return the position of the first character of the matching section.
end
end
-# BM_Pattern are precompiled string motif for the Boyer-Moore Fast String Searching Algorithm
-# (cf. A Fast String Searching Algorithm, with R.S. Boyer.
-# Communications of the Association for Computing Machinery, 20(10), 1977, pp. 762-772.)
-# see also http://www.cs.utexas.edu/users/moore/best-ideas/string-searching/index.html
+# BM_Pattern are pre-compiled string motif for the Boyer-Moore algorithm.
+# (cf. A Fast String Searching Algorithm, with R.S. Boyer. Communications
+# of the Association for Computing Machinery, 20(10), 1977, pp. 762-772.)
+# http://www.cs.utexas.edu/users/moore/best-ideas/string-searching/index.html
class BM_Pattern
super Pattern
# a # -> [4, 7]
fun search_all(p: Pattern): Array[Match] do return p.search_all_in(self)
- # Split self using p is separator.
+ # Split `self` using `p` as separator.
# "hello world".split('o') # -> ["hell", " w", "rld"]
- fun split_with(p: Pattern): Array[String]
+ fun split(p: Pattern): Array[String]
do
var matches = p.split_in(self)
var res = new Array[String].with_capacity(matches.length)
return res
end
- # Split self using '\n' is separator.
- # "hello\nworld".split # -> ["hello","world"]
- fun split: Array[String] do return split_with('\n')
+ # @deprecated alias for `split`
+ fun split_with(p: Pattern): Array[String] do return self.split(p)
# Replace all occurences of a pattern with a string
#