neco-editor-search
Text search engine for editor buffers. Finds and replaces patterns in UTF-8 text, resolving match positions to line/column via neco-textview::LineIndex.
How it works
SearchQuery holds the search parameters: a pattern string plus flags for regex mode, case sensitivity, and whole-word matching. The query compiles into a regex::Regex internally. Plain-text patterns are escaped so metacharacters match literally.
find_all returns every match in the buffer. find_next returns the first match at or after a byte offset, useful for incremental "find next" navigation. Both attach line and column numbers to each SearchMatch.
replace_all and replace_next perform substitution and return the new text. Regex back-references ($1, $2, ...) work in replacement strings when the query is in regex mode.
All functions return Result, propagating SearchError::InvalidRegex when the pattern fails to compile.
Usage
use ;
use LineIndex;
let text = "foo bar foo";
let li = new;
let query = SearchQuery ;
let matches = find_all.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
let = replace_all.unwrap;
assert_eq!;
assert_eq!;
API
| Item | Description |
|---|---|
SearchQuery |
Search parameters: pattern, is_regex, case_sensitive, whole_word |
SearchMatch |
A match with its byte range, line number, and column |
SearchMatch::range() |
Byte-offset TextRange of the match |
SearchMatch::line() |
0-based line number |
SearchMatch::column() |
0-based byte column within the line |
SearchError |
InvalidRegex(String) when the pattern fails to compile |
find_all(text, line_index, query) |
All matches in the buffer |
find_next(text, line_index, query, from_offset) |
First match at or after from_offset, or None |
replace_all(text, query, replacement) |
Replace every match; returns (new_text, count) |
replace_next(text, line_index, query, replacement, from_offset) |
Replace the first match at or after from_offset |
License
MIT