mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
1b83dc2476
Mostly it's about Go 1.22+ syntax with ranging over integers, but it also prefers ranging over slices where possible (it makes code a little better to read). Notice that we have a number of dangerous loops where slices are mutated during loop execution, many of these can't be converted since we need proper length evalutation at every iteration. Signed-off-by: Roman Khimov <roman@nspcc.ru>
20 lines
384 B
Go
20 lines
384 B
Go
package opcode
|
|
|
|
import "errors"
|
|
|
|
var stringToOpcode = make(map[string]Opcode)
|
|
|
|
func init() {
|
|
for i := range 255 {
|
|
op := Opcode(i)
|
|
stringToOpcode[op.String()] = op
|
|
}
|
|
}
|
|
|
|
// FromString converts string representation to an opcode itself.
|
|
func FromString(s string) (Opcode, error) {
|
|
if op, ok := stringToOpcode[s]; ok {
|
|
return op, nil
|
|
}
|
|
return 0, errors.New("invalid opcode")
|
|
}
|