clang 22.0.0git
SimpleTypoCorrection.h
Go to the documentation of this file.
1//===- SimpleTypoCorrection.h - Basic typo correction utility -*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the SimpleTypoCorrection class, which performs basic
10// typo correction using string similarity based on edit distance.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CLANG_BASIC_SIMPLETYPOCORRECTION_H
15#define LLVM_CLANG_BASIC_SIMPLETYPOCORRECTION_H
16
17#include "clang/Basic/LLVM.h"
18#include "llvm/ADT/StringRef.h"
19
20namespace clang {
21
22class IdentifierInfo;
23
25 StringRef BestCandidate;
26 StringRef Typo;
27
28 const unsigned MaxEditDistance;
29 unsigned BestEditDistance;
30 unsigned BestIndex;
31 unsigned NextIndex;
32
33public:
34 explicit SimpleTypoCorrection(StringRef Typo)
35 : BestCandidate(), Typo(Typo), MaxEditDistance((Typo.size() + 2) / 3),
36 BestEditDistance(MaxEditDistance + 1), BestIndex(0), NextIndex(0) {}
37
38 void add(const StringRef Candidate);
39 void add(const char *Candidate);
40 void add(const IdentifierInfo *Candidate);
41
42 std::optional<StringRef> getCorrection() const;
43 bool hasCorrection() const;
44 unsigned getCorrectionIndex() const;
45};
46} // namespace clang
47
48#endif // LLVM_CLANG_BASIC_SIMPLETYPOCORRECTION_H
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
One of these records is kept for each identifier that is lexed.
std::optional< StringRef > getCorrection() const
void add(const StringRef Candidate)
The JSON file list parser is used to communicate input to InstallAPI.