dupname

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: CC0-1.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DupName

type DupName struct {
	// contains filtered or unexported fields
}

func NewDupName

func NewDupName[T any](
	newNamer func(string) Namer,
	entries []T,
	freeze bool,
	pickName func(T) string,
) *DupName

The entries parameter exists to ensure that the non-duplicative values contained in entries are not changed.

Example:

// If a directory contains "foo.txt" ...
path := "path/to/the/directory"
entries, _ := os.ReadDir(path)
pick: = func(x os.DirEntry) string { return x.Name() }

// freeze parameter is set to 'false', nameA is "foo.txt" and nameB is "foo(2).txt".
dupName := NewDupName(NewNumberedName, entries, false, pick)
nameA, _ := dupName.Rename("foo.txt")
nameB, _ := dupName.Rename("foo.txt")

// freeze parameter is set to 'true', nameC is "foo(2).txt" and nameD is "foo(3).txt".
dupName = NewDupName(NewNumberedName, entries, true, pick)
nameC, _ := dupName.Rename("foo.txt")
nameD, _ := dupName.Rename("foo.txt")

// In the above case, it would be more suitable to set freeze parameter to 'true'.

func (*DupName) MustRename

func (r *DupName) MustRename(name string) string

func (*DupName) Rename

func (r *DupName) Rename(name string) (string, error)

type Namer

type Namer interface {
	PackName(int64) string
}

func NewNumberedName

func NewNumberedName(name string) Namer

type NumberedName

type NumberedName struct {
	// contains filtered or unexported fields
}

NumberdName is an example of implementation of Namer. PackName() function will change the 'name' to numbered one.

Example:

NewNumberedName("foo.txt").PackName(1) // "foo(1).txt"

func (NumberedName) PackName

func (n NumberedName) PackName(num int64) string

Jump to

Keyboard shortcuts

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