diff options
| author | Florian Hartwig <florian.j.hartwig@gmail.com> | 2015-11-27 17:52:29 +0100 |
|---|---|---|
| committer | Florian Hartwig <florian.j.hartwig@gmail.com> | 2015-11-27 17:52:29 +0100 |
| commit | 4bb7cf11dcb7b4d106456b9c34c2e30638615f47 (patch) | |
| tree | d320dc1ef0bcee20a04f840de932f01ae079fb4e /src/libsyntax/util | |
| parent | 9ba657cad5f0fdeebfc3637f2cbc31af24e944f7 (diff) | |
| download | rust-4bb7cf11dcb7b4d106456b9c34c2e30638615f47.tar.gz rust-4bb7cf11dcb7b4d106456b9c34c2e30638615f47.zip | |
Introduce max_suggestion_distance function to avoid duplicating the heuristic
Diffstat (limited to 'src/libsyntax/util')
| -rw-r--r-- | src/libsyntax/util/lev_distance.rs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libsyntax/util/lev_distance.rs b/src/libsyntax/util/lev_distance.rs index 28f8510ce3f..9bf96311122 100644 --- a/src/libsyntax/util/lev_distance.rs +++ b/src/libsyntax/util/lev_distance.rs @@ -41,6 +41,14 @@ pub fn lev_distance(me: &str, t: &str) -> usize { dcol[t_last + 1] } +pub fn max_suggestion_distance(name: &str) -> usize { + use std::cmp::max; + // As a loose rule to avoid obviously incorrect suggestions, clamp the + // maximum edit distance we will accept for a suggestion to one third of + // the typo'd name's length. + max(name.len(), 3) / 3 +} + #[test] fn test_lev_distance() { use std::char::{ from_u32, MAX }; |
