aboutsummaryrefslogtreecommitdiffhomepage
path: root/vendor/github.com/hashicorp/hcl2/hcl/json/didyoumean.go
diff options
context:
space:
mode:
authorappilon <apilon@hashicorp.com>2019-02-27 16:43:31 -0500
committerGitHub <noreply@github.com>2019-02-27 16:43:31 -0500
commit844b5a68d8af4791755b8f0ad293cc99f5959183 (patch)
tree255c250a5c9d4801c74092d33b7337d8c14438ff /vendor/github.com/hashicorp/hcl2/hcl/json/didyoumean.go
parent303b299eeb6b06e939e35905e4b34cb410dd9dc3 (diff)
parent15c0b25d011f37e7c20aeca9eaf461f78285b8d9 (diff)
downloadterraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.gz
terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.tar.zst
terraform-provider-statuscake-844b5a68d8af4791755b8f0ad293cc99f5959183.zip
Merge pull request #27 from terraform-providers/go-modules-2019-02-22
[MODULES] Switch to Go Modules
Diffstat (limited to 'vendor/github.com/hashicorp/hcl2/hcl/json/didyoumean.go')
-rw-r--r--vendor/github.com/hashicorp/hcl2/hcl/json/didyoumean.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/hcl2/hcl/json/didyoumean.go b/vendor/github.com/hashicorp/hcl2/hcl/json/didyoumean.go
new file mode 100644
index 0000000..fbdd8bf
--- /dev/null
+++ b/vendor/github.com/hashicorp/hcl2/hcl/json/didyoumean.go
@@ -0,0 +1,33 @@
1package json
2
3import (
4 "github.com/agext/levenshtein"
5)
6
7var keywords = []string{"false", "true", "null"}
8
9// keywordSuggestion tries to find a valid JSON keyword that is close to the
10// given string and returns it if found. If no keyword is close enough, returns
11// the empty string.
12func keywordSuggestion(given string) string {
13 return nameSuggestion(given, keywords)
14}
15
16// nameSuggestion tries to find a name from the given slice of suggested names
17// that is close to the given name and returns it if found. If no suggestion
18// is close enough, returns the empty string.
19//
20// The suggestions are tried in order, so earlier suggestions take precedence
21// if the given string is similar to two or more suggestions.
22//
23// This function is intended to be used with a relatively-small number of
24// suggestions. It's not optimized for hundreds or thousands of them.
25func nameSuggestion(given string, suggestions []string) string {
26 for _, suggestion := range suggestions {
27 dist := levenshtein.Distance(given, suggestion, nil)
28 if dist < 3 { // threshold determined experimentally
29 return suggestion
30 }
31 }
32 return ""
33}