aboutsummaryrefslogtreecommitdiffstats
path: root/accounts/abi/bind/bind.go
diff options
context:
space:
mode:
authorMark <markya0616@gmail.com>2018-03-07 20:34:53 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-03-07 20:34:53 +0800
commitcddb529d701fdb4f1f02fb4c96b5b604617693fe (patch)
treec16bf3a28d69a3133d2d7c33117bda28e681d238 /accounts/abi/bind/bind.go
parent63687f04e441c97cbb39d6b0ebea346b154d2e73 (diff)
downloadgo-tangerine-cddb529d701fdb4f1f02fb4c96b5b604617693fe.tar
go-tangerine-cddb529d701fdb4f1f02fb4c96b5b604617693fe.tar.gz
go-tangerine-cddb529d701fdb4f1f02fb4c96b5b604617693fe.tar.bz2
go-tangerine-cddb529d701fdb4f1f02fb4c96b5b604617693fe.tar.lz
go-tangerine-cddb529d701fdb4f1f02fb4c96b5b604617693fe.tar.xz
go-tangerine-cddb529d701fdb4f1f02fb4c96b5b604617693fe.tar.zst
go-tangerine-cddb529d701fdb4f1f02fb4c96b5b604617693fe.zip
accounts/abi: normalize method name to a camel-case string (#15976)
Diffstat (limited to 'accounts/abi/bind/bind.go')
-rw-r--r--accounts/abi/bind/bind.go39
1 files changed, 34 insertions, 5 deletions
diff --git a/accounts/abi/bind/bind.go b/accounts/abi/bind/bind.go
index 7fdd2c624..411177057 100644
--- a/accounts/abi/bind/bind.go
+++ b/accounts/abi/bind/bind.go
@@ -385,8 +385,7 @@ var methodNormalizer = map[Lang]func(string) string{
LangJava: decapitalise,
}
-// capitalise makes the first character of a string upper case, also removing any
-// prefixing underscores from the variable names.
+// capitalise makes a camel-case string which starts with an upper case character.
func capitalise(input string) string {
for len(input) > 0 && input[0] == '_' {
input = input[1:]
@@ -394,12 +393,42 @@ func capitalise(input string) string {
if len(input) == 0 {
return ""
}
- return strings.ToUpper(input[:1]) + input[1:]
+ return toCamelCase(strings.ToUpper(input[:1]) + input[1:])
}
-// decapitalise makes the first character of a string lower case.
+// decapitalise makes a camel-case string which starts with a lower case character.
func decapitalise(input string) string {
- return strings.ToLower(input[:1]) + input[1:]
+ for len(input) > 0 && input[0] == '_' {
+ input = input[1:]
+ }
+ if len(input) == 0 {
+ return ""
+ }
+ return toCamelCase(strings.ToLower(input[:1]) + input[1:])
+}
+
+// toCamelCase converts an under-score string to a camel-case string
+func toCamelCase(input string) string {
+ toupper := false
+
+ result := ""
+ for k, v := range input {
+ switch {
+ case k == 0:
+ result = strings.ToUpper(string(input[0]))
+
+ case toupper:
+ result += strings.ToUpper(string(v))
+ toupper = false
+
+ case v == '_':
+ toupper = true
+
+ default:
+ result += string(v)
+ }
+ }
+ return result
}
// structured checks whether a list of ABI data types has enough information to