diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2013-05-08 19:21:00 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-05-08 19:21:00 +0000 |
commit | 6c7a16666dbba49b9ef41c28ff7cbddf3e250213 (patch) | |
tree | 120c8544a57738c87929364c3b884fe273f5c9c8 /clang/lib/AST/CommentCommandTraits.cpp | |
parent | 53caf563a9934088d39b008bd9b0de6adcc003c7 (diff) | |
download | bcm5719-llvm-6c7a16666dbba49b9ef41c28ff7cbddf3e250213.tar.gz bcm5719-llvm-6c7a16666dbba49b9ef41c28ff7cbddf3e250213.zip |
documentation parsing. Patch to do typo correction for
documentation commands. Patch was reviewed, along with
great suggestions for improvement, by Doug.
// rdar://12381408
llvm-svn: 181458
Diffstat (limited to 'clang/lib/AST/CommentCommandTraits.cpp')
-rw-r--r-- | clang/lib/AST/CommentCommandTraits.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/clang/lib/AST/CommentCommandTraits.cpp b/clang/lib/AST/CommentCommandTraits.cpp index e24d542c962..e4cc84afb78 100644 --- a/clang/lib/AST/CommentCommandTraits.cpp +++ b/clang/lib/AST/CommentCommandTraits.cpp @@ -43,6 +43,33 @@ const CommandInfo *CommandTraits::getCommandInfo(unsigned CommandID) const { return getRegisteredCommandInfo(CommandID); } +const CommandInfo * +CommandTraits::getTypoCorrectCommandInfo(StringRef Typo) const { + const unsigned MaxEditDistance = 1; + unsigned BestEditDistance = MaxEditDistance + 1; + SmallVector<const CommandInfo *, 2> BestCommand; + + int NumOfCommands = sizeof(Commands) / sizeof(CommandInfo); + for (int i = 0; i < NumOfCommands; i++) { + StringRef Name = Commands[i].Name; + unsigned MinPossibleEditDistance = abs((int)Name.size() - (int)Typo.size()); + if (MinPossibleEditDistance > 0 && + Typo.size() / MinPossibleEditDistance < 1) + continue; + unsigned EditDistance = Typo.edit_distance(Name, true, MaxEditDistance); + if (EditDistance > MaxEditDistance) + continue; + if (EditDistance == BestEditDistance) + BestCommand.push_back(&Commands[i]); + else if (EditDistance < BestEditDistance) { + BestCommand.clear(); + BestCommand.push_back(&Commands[i]); + BestEditDistance = EditDistance; + } + } + return (BestCommand.size() != 1) ? NULL : BestCommand[0]; +} + CommandInfo *CommandTraits::createCommandInfoWithName(StringRef CommandName) { char *Name = Allocator.Allocate<char>(CommandName.size() + 1); memcpy(Name, CommandName.data(), CommandName.size()); |