version

package
v0.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 26, 2024 License: MIT Imports: 5 Imported by: 1

Documentation

Overview

Package version tokenizes a apk package version using the same algorithm as apk-tools uses.

A valid version can be described by the following EBNF specificion:

version     = digits , { "." , digits } , [ letter, digits ] , { suffix } , [ revision ] ;

digit       = "0" | "1" | "2" | "3"| "4" | "5" | "6" | "7" | "8" | "9" ;
digits      = { digit } ;
revision    = "-r", digit, digits ;

letter      = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m"
            | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" ;

suffix      = "_" , ( pre-suffix | post-suffix ) , digits ;

pre-suffix  = "alpha" | "beta" | "pre" | "rc" ;
post-suffix = "cvc" | "svn" | "git" | "hg" | "p" ;
Example
package main

import (
	"fmt"

	"gitlab.alpinelinux.org/alpine/go/version"
)

func main() {
	v := version.Version("1.2.3-r0")

	nv := &v
	t := version.Digit
	var pt version.Token

	var q int64
	for t != version.End {
		pt = t
		t, nv, q = nv.GetToken(t)
		if pt == version.Digit {
			fmt.Printf("%d\n", q)
		}
		if pt == version.RevisionDigit {
			fmt.Printf("r%d\n", q)
		}
	}

}
Output:

1
2
3
r0

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsValidWithoutRevision added in v0.10.0

func IsValidWithoutRevision(version string) bool

IsValidWithoutRevision validates the provided version without a revision component.

Example (Invalid)
fmt.Println(IsValidWithoutRevision("1.2.4_5"))
Output:

false
Example (Valid)
fmt.Println(IsValidWithoutRevision("1.2.4_git123"))
Output:

true

Types

type Token

type Token int
const (
	Invalid       Token = -1
	DigitOrZero   Token = 0
	Digit         Token = 1
	Letter        Token = 2
	Suffix        Token = 3
	SuffixDigit   Token = 4
	RevisionDigit Token = 5
	End           Token = 6
)

func (Token) String added in v0.10.0

func (i Token) String() string

type Version

type Version string

func (*Version) GetToken

func (v *Version) GetToken(t Token) (Token, *Version, int64)

GetToken performs the same function as NextToken, but also parses the version into an integral component.

func (*Version) NextToken

func (v *Version) NextToken(t Token) (Token, *Version)

NextToken advances the parsing state machine. On the first call, it should be called with t set to Digit.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL