TextCorrection.h header

#include <ew/app/TextCorrection.h>

Namespace ew::app

Functions

QString ew::app::autocorrectWord(const QString &word)

The autocorrected form of a just-completed word, or word unchanged when no rule applies. Fixes a TWo-initial-capitals slip ("THe" -> "The") and a small table of very common typos ("teh" -> "the", "adn" -> "and", ...), matched case-insensitively and re-cased to match the input (so "Teh" -> "The"). Punctuation the word carries is not considered – pass the bare word.

bool ew::app::quoteOpensAfter(QChar preceding)

Whether a straight quote typed after preceding should become an opening curly quote (as opposed to a closing one). It opens at the start of the text (a null preceding), after whitespace, or after an opening bracket or dash; otherwise it closes (after a letter, digit, or closing punctuation). This is the standard "smart quotes" heuristic.

QChar ew::app::smartQuote(QChar quote, QChar preceding)

The curly form of a straight quote quote (' or ") given the preceding character: the opening curly quote when quoteOpensAfter(preceding), else the closing one. A character that is not a straight quote is returned unchanged.

QString ew::app::smartenPunctuation(const QString &text)

Applies smart punctuation across a whole text: straight quotes become context-aware curly quotes, -- becomes an em dash, and ... becomes a single ellipsis character. Pure and order-independent enough to run over a selection ("Apply Smart Punctuation"); word-level autocorrect (autocorrectWord) is applied separately as the writer completes each word.