Debian Codegraph @

iota.go

raw symbols SCIP
1 package tygoja
2
3 import (
4 "fmt"
5 "strconv"
6 "strings"
7 )
8
9 func isProbablyIotaType(groupType string) bool {
10 groupType = strings.Trim(groupType, "()")
11 return groupType == "iota" || strings.HasPrefix(groupType, "iota +") || strings.HasSuffix(groupType, "+ iota")
12 }
13
14 func basicIotaOffsetValueParse(groupType string) (int, error) {
15 if !isProbablyIotaType(groupType) {
16 panic("can't parse non-iota type")
17 }
18
19 groupType = strings.Trim(groupType, "()")
20 if groupType == "iota" {
21 return 0, nil
22 }
23 parts := strings.Split(groupType, " + ")
24
25 var numPart string
26 if parts[0] == "iota" {
27 numPart = parts[1]
28 } else {
29 numPart = parts[0]
30 }
31
32 addValue, err := strconv.ParseInt(numPart, 10, 64)
33 if err != nil {
34 return 0, fmt.Errorf("Failed to guesstimate initial iota value for \"%s\": %w", groupType, err)
35 }
36
37 return int(addValue), nil
38 }