SearchFruct

Convenient bundle of welterweight search utilities, without the hassle of IFTI problems. Create one of these using the search() function:

auto match = search ("foo");
auto content = "wumpus foo bar"

// search in the forward direction
auto index = match.forward (content);
assert (index is 7);

// search again - returns length when no match found
assert (match.forward(content, index+1) is content.length);

Searching operates both forward and backward, with an optional start offset (can be more convenient than slicing the content). There are methods to replace matches within given content, and others which return foreach() iterators for traversing content.

FindFruct is a simpler variant, which can operate efficiently on short matches and/or short content (employs brute-force strategy)

Members

Functions

count
size_t count(const(T)[] content)

Returns number of matches within the given content

forward
size_t forward(const(T)[] content, size_t ofs)

Search forward in the given content, starting at the optional index.

indices
Indices indices(const(T)[] content)

Returns a foreach() iterator which exposes the indices of all matches within the given content:

replace
T[] replace(const(T)[] content, const(T)[] sub)

Replace all matches with the given substitution. Use method tokens() instead to avoid heap activity.

replace
T[] replace(const(T)[] content, T chr)

Replace all matches with the given character. Use method tokens() instead to avoid heap activity.

reverse
size_t reverse(const(T)[] content, size_t ofs)

Search backward in the given content, starting at the optional index.

tokens
Substitute tokens(const(T)[] content, const(T)[] sub)

Returns a foreach() iterator which exposes text segments between all matches within the given content. Substitution text is also injected in place of each match, and null can be used to indicate removal instead:

within
bool within(const(T)[] content)

Returns true if there is a match within the given content

Properties

match
const(T)[] match [@property getter]

Return the match text

match
const(T)[] match [@property setter]

Reset the text to match

Static functions

opCall
SearchFruct opCall(const(T)[] what)

Construct the fruct

Meta