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 20 namespace clang { 21 22 class IdentifierInfo; 23 24 class SimpleTypoCorrection { 25 StringRef BestCandidate; 26 StringRef Typo; 27 28 const unsigned MaxEditDistance; 29 unsigned BestEditDistance; 30 unsigned BestIndex; 31 unsigned NextIndex; 32 33 public: SimpleTypoCorrection(StringRef Typo)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 49