bexp

package module
v0.99.99 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2020 License: MIT Imports: 6 Imported by: 0

README

Bash Brace Expansion in go

Implementing: 3.5.1 Brace Expansion

license PkgGoDev tests Go Report Card Coverage Status benchmarks GitHub last commit

Usage

go get github.com/mkungla/bexp

Get string slice
package main

import (
	"github.com/mkungla/bexp"
	"fmt"
)

func main() {
	var v []string
	v = bexp.Parse("file-{a,b,c}.jpg")
	fmt.Println(v)
	// [file-a.jpg file-b.jpg file-c.jpg]

	v = bexp.Parse("-v{,,}")
	fmt.Println(v)
	// [-v -v -v]

	v = bexp.Parse("file{0..2}.jpg")
	fmt.Println(v)
	// [file0.jpg file1.jpg file2.jpg]

	v = bexp.Parse("file{2..0}.jpg")
	fmt.Println(v)
	// [file2.jpg file1.jpg file0.jpg]

	v = bexp.Parse("file{0..4..2}.jpg")
	fmt.Println(v)
	// [file0.jpg file2.jpg file4.jpg]

	v = bexp.Parse("file-{a..e..2}.jpg")
	fmt.Println(v)
	// [file-a.jpg file-c.jpg file-e.jpg]

	v = bexp.Parse("file{00..10..5}.jpg")
	fmt.Println(v)
	// [file00.jpg file05.jpg file10.jpg]

	v = bexp.Parse("{{A..C},{a..c}}")
	fmt.Println(v)
	// [A B C a b c]

	v = bexp.Parse("ppp{,config,oe{,conf}}")
	fmt.Println(v)
	// [ppp pppconfig pppoe pppoeconf]

	v = bexp.Parse("data/{P1/{10..19},P2/{20..29},P3/{30..39}}")
	fmt.Println(v)
	// [data/P1/10 data/P1/11 data/P1/12 data/P1/13 data/P1/14 data/P1/15 data/P1/16 data/P1/17 data/P1/18 data/P1/19 data/P2/20 data/P2/21 data/P2/22 data/P2/23 data/P2/24 data/P2/25 data/P2/26 data/P2/27 data/P2/28 data/P2/29 data/P3/30 data/P3/31 data/P3/32 data/P3/33 data/P3/34 data/P3/35 data/P3/36 data/P3/37 data/P3/38 data/P3/39]
}

Inspired by and other similar libraries

following package were inspiration to create this package, Some of the code is from these packages. The motivation of this package is to improve performance and reduce mem alloc compared to packages listed here. also to add some commonly used API's when working with brace expansion strings

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BalancedResult

type BalancedResult struct {
	Start int
	End   int
	Pre   string
	Body  string
	Post  string
}

func Balanced

func Balanced(a interface{}, b interface{}, str string) *BalancedResult

func Range

func Range(a []byte, b []byte, str string) *BalancedResult

type BraceExpansion

type BraceExpansion []string

func Parse

func Parse(str string) BraceExpansion
Example
package main

import (
	"fmt"

	"github.com/mkungla/bexp"
)

func main() {
	var v []string
	v = bexp.Parse("file-{a,b,c}.jpg")
	fmt.Println(v)

	v = bexp.Parse("-v{,,}")
	fmt.Println(v)

	v = bexp.Parse("file{0..2}.jpg")
	fmt.Println(v)

	v = bexp.Parse("file{2..0}.jpg")
	fmt.Println(v)

	v = bexp.Parse("file{0..4..2}.jpg")
	fmt.Println(v)

	v = bexp.Parse("file-{a..e..2}.jpg")
	fmt.Println(v)

	v = bexp.Parse("file{00..10..5}.jpg")
	fmt.Println(v)

	v = bexp.Parse("{{A..C},{a..c}}")
	fmt.Println(v)

	v = bexp.Parse("ppp{,config,oe{,conf}}")
	fmt.Println(v)

	v = bexp.Parse("data/{P1/{10..19},P2/{20..29},P3/{30..39}}")
	fmt.Println(v)

}
Output:

[file-a.jpg file-b.jpg file-c.jpg]
[-v -v -v]
[file0.jpg file1.jpg file2.jpg]
[file2.jpg file1.jpg file0.jpg]
[file0.jpg file2.jpg file4.jpg]
[file-a.jpg file-c.jpg file-e.jpg]
[file00.jpg file05.jpg file10.jpg]
[A B C a b c]
[ppp pppconfig pppoe pppoeconf]
[data/P1/10 data/P1/11 data/P1/12 data/P1/13 data/P1/14 data/P1/15 data/P1/16 data/P1/17 data/P1/18 data/P1/19 data/P2/20 data/P2/21 data/P2/22 data/P2/23 data/P2/24 data/P2/25 data/P2/26 data/P2/27 data/P2/28 data/P2/29 data/P3/30 data/P3/31 data/P3/32 data/P3/33 data/P3/34 data/P3/35 data/P3/36 data/P3/37 data/P3/38 data/P3/39]

func (BraceExpansion) String

func (b BraceExpansion) String() string

Jump to

Keyboard shortcuts

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