NameSimilarity.h header
#include <ew/app/NameSimilarity.h>
Namespace ew::app
SimilarName struct
struct ew::app::SimilarName
A name already in the project that is close enough to a proposed one to be confusable.
Members
QString ew::app::search::SimilarName::name
The existing name or alias.
QString ew::app::search::SimilarName::kind
What carries it – "entity", "entity alias", "document", ... – so the caller can judge.
int ew::app::search::SimilarName::distance = 0
Edit distance from the proposed name; 0 means an exact (case-insensitive) collision.
Functions
int ew::app::search::nameEditDistance(const QString &left, const QString &right)
The Levenshtein edit distance between left and right, compared case-insensitively. Exposed because the threshold a caller wants depends on name length, and because it is worth testing directly.
std::vector< SimilarName > ew::app::search::similarNames(const ew::core::project::Project &project, const ew::app::library::MountedLibraries &libraries, const QString &proposed, int maxDistance)
Existing names within maxDistance edits of proposed, across every titled object and every entity alias in project and the libraries it mounts, nearest first.
This is deliberately NOT a substring search. The failure it exists to catch is a near-miss that no text search can find: "Marda" and "Martha" share no substring long enough to match, so a writer coins the second while the first is already in the codex and only notices chapters later, when both are load-bearing. Checking before the name is used is the only cheap moment.
An exact case-insensitive match is reported with distance 0 rather than omitted – a duplicate name is the most confusable case of all, not a non-result.