diff options
author | 2017-11-13 11:54:46 -0800 | |
---|---|---|
committer | 2017-11-13 19:54:46 +0000 | |
commit | 9018451dd30caf40f4c7e5e6e5d614c31b2f42e6 (patch) | |
tree | 33ad0bc4deb94fdd89e325b9c89b069a5af479d1 /vendor/github.com/go-openapi/swag/util.go | |
parent | 7c7a233b8392c0bcdb1b6a6df2ef7c8185cb11cd (diff) | |
download | coredns-9018451dd30caf40f4c7e5e6e5d614c31b2f42e6.tar.gz coredns-9018451dd30caf40f4c7e5e6e5d614c31b2f42e6.tar.zst coredns-9018451dd30caf40f4c7e5e6e5d614c31b2f42e6.zip |
Update Gopkg.toml to remove the constraint on zipkin-go-opentracing (#1231)
* Update vendor directory for latest changes.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
* Update Gopkg.toml to remove the constraint on zipkin-go-opentracing
As the issue on zipkin-go-opentracing has been fixed. See #1193
for details.
Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
Diffstat (limited to 'vendor/github.com/go-openapi/swag/util.go')
-rw-r--r-- | vendor/github.com/go-openapi/swag/util.go | 42 |
1 files changed, 40 insertions, 2 deletions
diff --git a/vendor/github.com/go-openapi/swag/util.go b/vendor/github.com/go-openapi/swag/util.go index 40751aab4..0efb41735 100644 --- a/vendor/github.com/go-openapi/swag/util.go +++ b/vendor/github.com/go-openapi/swag/util.go @@ -40,6 +40,7 @@ var commonInitialisms = map[string]bool{ "IP": true, "JSON": true, "LHS": true, + "OAI": true, "QPS": true, "RAM": true, "RHS": true, @@ -163,8 +164,8 @@ func split(str string) (words []string) { // Split when uppercase is found (needed for Snake) str = rex1.ReplaceAllString(str, " $1") - // check if consecutive single char things make up an initialism + // check if consecutive single char things make up an initialism for _, k := range initialisms { str = strings.Replace(str, rex1.ReplaceAllString(k, " $1"), " "+k, -1) } @@ -189,10 +190,47 @@ func lower(str string) string { return strings.ToLower(trim(str)) } +// Camelize an uppercased word +func Camelize(word string) (camelized string) { + for pos, ru := range word { + if pos > 0 { + camelized += string(unicode.ToLower(ru)) + } else { + camelized += string(unicode.ToUpper(ru)) + } + } + return +} + // ToFileName lowercases and underscores a go type name func ToFileName(name string) string { var out []string - for _, w := range split(name) { + cml := trim(name) + + // Camelize any capital word preceding a reserved keyword ("initialism") + // thus, upper-cased words preceding a common initialism will get separated + // e.g: ELBHTTPLoadBalancer becomes elb_http_load_balancer + rexPrevious := regexp.MustCompile(`(?P<word>\p{Lu}{2,})(?:HTTP|OAI)`) + cml = rexPrevious.ReplaceAllStringFunc(cml, func(match string) (replaceInMatch string) { + for _, m := range rexPrevious.FindAllStringSubmatch(match, -1) { // [ match submatch ] + if m[1] != "" { + replaceInMatch = strings.Replace(m[0], m[1], Camelize(m[1]), -1) + } + } + return + }) + + // Pre-camelize reserved keywords ("initialisms") to avoid unnecessary hyphenization + for _, k := range initialisms { + cml = strings.Replace(cml, k, Camelize(k), -1) + } + + // Camelize other capital words to avoid unnecessary hyphenization + rexCase := regexp.MustCompile(`(\p{Lu}{2,})`) + cml = rexCase.ReplaceAllStringFunc(cml, Camelize) + + // Final split with hyphens + for _, w := range split(cml) { out = append(out, lower(w)) } return strings.Join(out, "_") |