StyleAnalyzer.h header

#include <ew/app/style/StyleAnalyzer.h>

Namespace ew::app::style

StyleAnalyzer class

class ew::app::style::StyleAnalyzer

Runs a set of style rules over text and returns their combined diagnostics. The analyzer owns its rules, so a "style profile" is just the set of rules it holds; defaultProfile() builds one preloaded with the standard rule set.

Members

ew::app::style::StyleAnalyzer::StyleAnalyzer()

Constructs an empty analyzer holding no rules.

ew::app::style::StyleAnalyzer::~StyleAnalyzer()

Destroys the analyzer and the rules it owns.

ew::app::style::StyleAnalyzer::StyleAnalyzer(const StyleAnalyzer &)=delete

Not copyable.

ew::app::style::StyleAnalyzer::StyleAnalyzer(StyleAnalyzer &&) noexcept

Move-constructible.

StyleAnalyzer & ew::app::style::StyleAnalyzer::operator=(const StyleAnalyzer &)=delete

Not copyable.

StyleAnalyzer & ew::app::style::StyleAnalyzer::operator=(StyleAnalyzer &&) noexcept

Move-assignable.

void ew::app::style::StyleAnalyzer::addRule(std::unique_ptr< StyleRule > rule)

Adds rule to the set this analyzer runs; a null rule is ignored.

std::size_t ew::app::style::StyleAnalyzer::ruleCount() const

Returns the number of rules currently held.

std::vector< ew::app::diagnostics::Diagnostic > ew::app::style::StyleAnalyzer::analyze(QStringView text, ew::core::foundation::ContentId subject={}) const

Runs every rule over text and returns the findings, ordered by offset (ties broken by the shorter span first), so callers can present them in reading order.

subject is the object the text belongs to – the document being edited. It is what the finding is reported against and part of what its fingerprint is taken over, so silencing a repetition in one chapter does not silence the same words in another.

static StyleAnalyzer ew::app::style::StyleAnalyzer::defaultProfile()

Builds an analyzer preloaded with the standard rule set.

The standard rules are universal craft advice – repeated words, crutch words, passive voice – and know nothing about any particular project. A project that has authored a house style wants profileFor() instead.

static StyleAnalyzer ew::app::style::StyleAnalyzer::profileFor(std::vector< ew::core::style::TerminologyEntry > terminology)

Builds an analyzer holding the standard rule set plus terminology as a house-style rule, which is what a project's own prose should be measured against.

The house style adds to the standard rules rather than replacing them: naming your terms is not a reason to stop being told about repeated words.

An empty terminology adds no rule at all rather than an empty one, so a project with no house style pays nothing for the feature.

Functions

ew::app::diagnostics::Diagnostic ew::app::style::toDiagnostic(const StyleFinding &finding, QStringView text, ew::core::foundation::ContentId subject={})

finding, as found in text and belonging to subject, as the product's own record.

Exposed rather than kept private because a caller with one finding in hand – the inline highlighter deciding whether a span is suppressed – needs the same fingerprint the panel computed, and computing it a second way is how two surfaces come to disagree about whether something is silenced.