ProjectFindReplace.h header
#include <ew/app/ProjectFindReplace.h>
Namespace ew::app
FindMatch struct
struct ew::app::FindMatch
One match of a query within a piece of text.
Members
int ew::app::FindMatch::start = 0
The match's character offset in the searched text.
int ew::app::FindMatch::length = 0
The match length in characters (always positive; zero-width matches are not reported).
QString ew::app::FindMatch::context
The text of the line (between newlines) containing the match, for display in a results list.
int ew::app::FindMatch::matchInContext = 0
The match's character offset within context, so the panel can highlight it.
FindQuery struct
struct ew::app::FindQuery
A find/replace query and its matching options, shared by the in-editor Find/Replace bar and the project-wide Find in Project panel so both interpret a search the same way.
Members
QString ew::app::FindQuery::text
The search text: a literal string, or a regular-expression pattern when regex is set.
bool ew::app::FindQuery::caseSensitive = false
Match upper/lower case exactly. When false the search is case-insensitive.
bool ew::app::FindQuery::wholeWord = false
Match whole words only (the pattern is wrapped in word boundaries). Ignored when regex is set – a regular expression expresses word boundaries itself with \b.
bool ew::app::FindQuery::regex = false
Interpret text as a regular expression rather than a literal string.
ReplaceOutcome struct
struct ew::app::ReplaceOutcome
The result of a replace-all over one piece of text.
Members
QString ew::app::ReplaceOutcome::text
The text after every match was replaced.
int ew::app::ReplaceOutcome::count = 0
How many matches were replaced.
Functions
QString ew::app::collapseInlineMarkers(const QString &text)
Replaces each inline editor marker in text – an embed ![[target]] (or ![[target#section]]) and a footnote reference [^id] – with a single space. The rich-text editor renders each such marker as ONE object character, so collapsing them before findMatches keeps a project search's match count and order in step with the editor: navigating to the Nth result re-finds the Nth match in the editor, where the marker is one object, so a search term inside a marker must not be counted as a separate, unnavigable match (which would shift every later result's position). Intended for a rich (HTML) body, whose markers the editor objectifies; a plain body keeps its markers as literal text in the editor and should be searched as-is.
QRegularExpression ew::app::compileQuery(const FindQuery &query)
Compiles query into a QRegularExpression. A literal query is escaped so its metacharacters are matched literally; a whole-word literal query is wrapped in \b...\b; a case-insensitive query sets QRegularExpression::CaseInsensitiveOption. A regex query is used verbatim (its validity is the caller's to check via QRegularExpression::isValid()). An empty FindQuery::text yields a regex whose pattern is empty, which the find/replace functions treat as "no query" (no matches).
std::vector< ew::core::ContentId > ew::app::documentsInScope(const ew::core::Project &project, ew::core::ContentId root)
Returns the ids of the project documents to search, in manuscript reading order (top-level documents by sort order, each followed by its descendants). With a null root every document in project is returned; otherwise only root and its descendants in the manuscript tree – the "scoped" search over one chapter/part and everything under it. Only ew::core::Document objects are included (entities and other content are not text-body documents); mounted libraries are not searched, as a project-wide replace only rewrites the project's own manuscript.
QString ew::app::expandBackreferences(const QString &replacement, const QRegularExpressionMatch &match)
Expands \1, \2, ... \9 in replacement to the corresponding captured groups of match (an empty string for a group that did not participate); every other character – including a backslash before any non-1-9 character, and a trailing backslash – is copied verbatim, matching Qt's QString::replace(QRegularExpression, QString) syntax. Because it reads the captures of a match made against the full text, it expands backreferences correctly even for patterns whose success depends on surrounding context (lookahead/lookbehind, anchors) – unlike re-running the pattern on the isolated matched substring, which loses that context.
std::vector< FindMatch > ew::app::findMatches(const QString &text, const QRegularExpression ®ex)
Returns every match of regex in text, in order, each with the line of text containing it for display. Zero-width matches (e.g. from x*) are skipped – there is nothing to select or show – and an invalid or empty-pattern regex yields no matches. The scan always terminates.
ReplaceOutcome ew::app::replaceMatches(const QString &text, const QRegularExpression ®ex, const QString &replacement)
Replaces every match of regex in text with replacement and returns the new text and the number of replacements. In replacement, \1, \2, ... expand to the pattern's capture groups (see expandBackreferences), evaluated against each full-text match so lookaround and anchored patterns replace correctly. Zero-width matches are skipped (consistent with findMatches). An invalid or empty-pattern regex leaves the text unchanged with a zero count. The operation always terminates.