Implement edit distance for StringRef

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@92309 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Douglas Gregor
2009-12-30 17:23:44 +00:00
parent 7fccf76048
commit 441c8b4ad1
2 changed files with 47 additions and 0 deletions

View File

@ -133,6 +133,22 @@ namespace llvm {
/// compare_lower - Compare two strings, ignoring case.
int compare_lower(StringRef RHS) const;
/// \brief Determine the edit distance between this string and another
/// string.
///
/// \param Other the string to compare this string against.
///
/// \param AllowReplacements whether to allow character
/// replacements (change one character into another) as a single
/// operation, rather than as two operations (an insertion and a
/// removal).
///
/// \returns the minimum number of character insertions, removals,
/// or (if \p AllowReplacements is \c true) replacements needed to
/// transform one of the given strings into the other. If zero,
/// the strings are identical.
unsigned edit_distance(StringRef Other, bool AllowReplacements = true);
/// str - Get the contents as an std::string.
std::string str() const { return std::string(Data, Length); }