versionsort

package module
v0.0.0-...-5b3a40d Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2019 License: MIT Imports: 2 Imported by: 2

README

versionsort

LICENSE GoDoc

Usage

import "github.com/haya14busa/go-versionsort"

func ExampleVersionSort() {
	strs := []string{
		"v1.1",
		"v1.10",
		"v1.11",
		"v1.9",
		"v1.8",
	}
	versionsort.Sort(strs, false)
	for _, s := range strs {
		fmt.Println(s)
	}
	// Output:
	// v1.1
	// v1.8
	// v1.9
	// v1.10
	// v1.11
}

Documentation

Overview

Package versionsort provides sorting utilities in natural version order like sort -V.

References: - https://www.gnu.org/software/coreutils/manual/html_node/Details-about-version-sort.html - https://github.com/ekg/filevercmp

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Less

func Less(l, r string) bool

Less returns true l should sort before the r.

func Sort

func Sort(strs []string, desc bool)

Sort sorts give strings with natural version numbers in text like sort -V.

Example
strs := []string{
	"v1.1",
	"v1.10",
	"v1.11",
	"v1.9",
	"v1.8",
}
Sort(strs, false)
for _, s := range strs {
	fmt.Println(s)
}
Output:
v1.1
v1.8
v1.9
v1.10
v1.11
Example (Haya14busa)
strs := []string{
	"haya2busa",
	"haya1busa",
	"haya14busa",
	"haya13busa",
}
Sort(strs, false)
for _, s := range strs {
	fmt.Println(s)
}
Output:
haya1busa
haya2busa
haya13busa
haya14busa
Example (Reverse)
strs := []string{
	"v1.1",
	"v1.9",
	"v1.8",
	"v1.10",
	"v1.11",
}
Sort(strs, true)
for _, s := range strs {
	fmt.Println(s)
}
Output:
v1.11
v1.10
v1.9
v1.8
v1.1

Types

This section is empty.

Jump to

Keyboard shortcuts

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