diff options
author | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
---|---|---|
committer | Alex Pilon <apilon@hashicorp.com> | 2019-02-22 18:24:37 -0500 |
commit | 15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (patch) | |
tree | 255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/hashicorp/hcl2/hcl/didyoumean.go | |
parent | 07971ca38143c5faf951d152fba370ddcbe26ad5 (diff) | |
download | terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.gz terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.tar.zst terraform-provider-statuscake-15c0b25d011f37e7c20aeca9eaf461f78285b8d9.zip |
deps: github.com/hashicorp/terraform@sdk-v0.11-with-go-modules
Updated via: go get github.com/hashicorp/terraform@sdk-v0.11-with-go-modules and go mod tidy
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcl/didyoumean.go')
-rw-r--r-- | vendor/github.com/hashicorp/hcl2/hcl/didyoumean.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/didyoumean.go b/vendor/github.com/hashicorp/hcl2/hcl/didyoumean.go new file mode 100644 index 0000000..c128334 --- /dev/null +++ b/vendor/github.com/hashicorp/hcl2/hcl/didyoumean.go | |||
@@ -0,0 +1,24 @@ | |||
1 | package hcl | ||
2 | |||
3 | import ( | ||
4 | "github.com/agext/levenshtein" | ||
5 | ) | ||
6 | |||
7 | // nameSuggestion tries to find a name from the given slice of suggested names | ||
8 | // that is close to the given name and returns it if found. If no suggestion | ||
9 | // is close enough, returns the empty string. | ||
10 | // | ||
11 | // The suggestions are tried in order, so earlier suggestions take precedence | ||
12 | // if the given string is similar to two or more suggestions. | ||
13 | // | ||
14 | // This function is intended to be used with a relatively-small number of | ||
15 | // suggestions. It's not optimized for hundreds or thousands of them. | ||
16 | func nameSuggestion(given string, suggestions []string) string { | ||
17 | for _, suggestion := range suggestions { | ||
18 | dist := levenshtein.Distance(given, suggestion, nil) | ||
19 | if dist < 3 { // threshold determined experimentally | ||
20 | return suggestion | ||
21 | } | ||
22 | } | ||
23 | return "" | ||
24 | } | ||