File: iota.go

package info (click to toggle)
golang-github-pocketbase-tygoja 0.0~git20250812.97ffe05-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,164 kB
  • sloc: javascript: 5; makefile: 4
file content (38 lines) | stat: -rw-r--r-- 838 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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
}