Adding upstream version 0.0~git20250307.c2e6a77.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
be99035e76
commit
b6e042e2af
64 changed files with 10976 additions and 0 deletions
38
iota.go
Normal file
38
iota.go
Normal file
|
@ -0,0 +1,38 @@
|
|||
package tygoja
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func isProbablyIotaType(groupType string) bool {
|
||||
groupType = strings.Trim(groupType, "()")
|
||||
return groupType == "iota" || strings.HasPrefix(groupType, "iota +") || strings.HasSuffix(groupType, "+ iota")
|
||||
}
|
||||
|
||||
func basicIotaOffsetValueParse(groupType string) (int, error) {
|
||||
if !isProbablyIotaType(groupType) {
|
||||
panic("can't parse non-iota type")
|
||||
}
|
||||
|
||||
groupType = strings.Trim(groupType, "()")
|
||||
if groupType == "iota" {
|
||||
return 0, nil
|
||||
}
|
||||
parts := strings.Split(groupType, " + ")
|
||||
|
||||
var numPart string
|
||||
if parts[0] == "iota" {
|
||||
numPart = parts[1]
|
||||
} else {
|
||||
numPart = parts[0]
|
||||
}
|
||||
|
||||
addValue, err := strconv.ParseInt(numPart, 10, 64)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("Failed to guesstimate initial iota value for \"%s\": %w", groupType, err)
|
||||
}
|
||||
|
||||
return int(addValue), nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue