From 1d3fa3cd592694e14a975d7c75934e1c8bf11ed3 Mon Sep 17 00:00:00 2001 From: Alexandre Bourget Date: Sat, 30 Mar 2019 01:37:47 -0400 Subject: [PATCH] Added support for symbol and symbol_code to `eosc tools names` --- eosc/cmd/toolsNames.go | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/eosc/cmd/toolsNames.go b/eosc/cmd/toolsNames.go index 7f70f5cf..9fbdb4f6 100644 --- a/eosc/cmd/toolsNames.go +++ b/eosc/cmd/toolsNames.go @@ -5,6 +5,7 @@ import ( "encoding/hex" "fmt" "os" + "regexp" "strconv" "strings" @@ -37,7 +38,20 @@ This command auto-detects encoding and converts it to different encodings. } } - fromName, err := eos.ExtendedStringToName(input) + fromSymbol, err := eos.StringToSymbol(input) + if err == nil { + symbolUint, err := fromSymbol.ToName() + if err == nil { + showFrom["symbol"] = symbolUint + } + } + + fromSymbolCode, err := eos.StringToSymbolCode(input) + if err == nil { + showFrom["symbol_code"] = uint64(fromSymbolCode) + } + + fromName, err := eos.StringToName(input) if err == nil { showFrom["name"] = fromName } @@ -48,8 +62,8 @@ This command auto-detects encoding and converts it to different encodings. } someFound := false - rows := []string{"| from \\ to | hex | hex_be | name | uint64", "| --------- | --- | ------ | ---- | ------ |"} - for _, from := range []string{"hex", "hex_be", "name", "uint64"} { + rows := []string{"| from \\ to | hex | hex_be | name | uint64 | symbol | symbol_code", "| --------- | --- | ------ | ---- | ------ | ------ | ----------- |"} + for _, from := range []string{"hex", "hex_be", "name", "uint64", "symbol", "symbol_code"} { val, found := showFrom[from] if !found { continue @@ -57,7 +71,7 @@ This command auto-detects encoding and converts it to different encodings. someFound = true row := []string{from} - for _, to := range []string{"hex", "hex_be", "name", "uint64"} { + for _, to := range []string{"hex", "hex_be", "name", "uint64", "symbol", "symbol_code"} { cnt := make([]byte, 8) switch to { @@ -73,6 +87,12 @@ This command auto-detects encoding and converts it to different encodings. case "uint64": row = append(row, strconv.FormatUint(val, 10)) + + case "symbol": + row = append(row, symbOrDash(fmt.Sprintf("%d,%s", uint8(val&0xFF), eos.SymbolCode(val>>8).String()))) + + case "symbol_code": + row = append(row, symbOrDash(eos.SymbolCode(val).String())) } } rows = append(rows, "| "+strings.Join(row, " | ")+" |") @@ -89,6 +109,15 @@ This command auto-detects encoding and converts it to different encodings. }, } +var symbOrDashRE = regexp.MustCompile(`^[0-9A-Z,]+$`) + +func symbOrDash(input string) string { + if !symbOrDashRE.MatchString(input) { + return "-" + } + return input +} + func init() { toolsCmd.AddCommand(toolsNamesCmd) }