dotpath

package
v0.0.0-...-4b9bf86 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2020 License: MIT Imports: 6 Imported by: 18

Documentation

Overview

Package dotpath is all about Pathinking - Path..think.ing - Path.ink.ing - Pa.think.ing - Pa.thin.king ...

Package dotpath is intended as a parser for user-provided strings separated by some single character delimiter (which is not a Dot) such as filepath information or other hierarchical identifiers and gives an extended meaning to multiple dots and trailing slashes:

... => 'use Subtree also' - recurse
..  => 'use Parent also', if .. is part of trailing dots and slashes
./  => 'this MUST be a directory', if a trailing slash is given

lexical.go: strictly lexical analysis of fullPath

lexical.go uses some dedicated functions exported by pathsplitter.go, and the packages "strings" and "do/string".

Typical use is upon e.g. flag.Args(), flags.StringVar(...)

Index

Constants

View Source
const (
	// Dot represents the period appearing in path names
	Dot = `.`
	// SingleDot - just another name for Dot
	SingleDot = Dot // just another name
	// DoubleDot represents two consecutive periods `..` appearing in path names
	DoubleDot = Dot + Dot
	// TripleDot represents three period `...` appearing in path names
	TripleDot = Dot + Dot + Dot
	// Empty represents any empty string
	Empty = ``
)

Combinations of Dots representing the period(s) appearing in path names

View Source
const (
	// GoPathSeparator is the pathseparator used (but not exported) by standard package `path`
	GoPathSeparator = `/`
	// OsPathSeparator is the path-list separator `os.PathSeparator`
	OsPathSeparator = string(os.PathSeparator)
)

Variables

This section is empty.

Functions

func DotPathS

func DotPathS(args ...string) (dirS []struct {
	DirPath string
	Recurse bool
})

DotPathS - get DirPathS (each with Recurse flag) from args. Uses dotpath functionalities; useful e.g. for commandline arguments.

func OneTripleAnyPairs

func OneTripleAnyPairs(text string) (segmentS []string)

OneTripleAnyPairs - a helper to get e.g. '........' as '... .. .. .' Invariant: len(text) == len(segmentS)

func PathDotTailor

func PathDotTailor(head, tail string) []string

PathDotTailor returns a slice of strings each representing a valid node / element / PathBase, or a triple-dot as indicator for a full tree of subdirectories.

Types

type DotPath

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

DotPath represents a lexically analysed filepath string.

Special attention is given to slashes; especially to trailing slash(es) as indicator for "I mean: directory! Not file.", and to sequences of multiple dots; in particular tripledots "..." as indicators for subtree recursion, and trailing doubledots as indicators for "waydown" accumulation along parents/anchestors.

Hint: Use New(path string) *DotPath for single entries, or Parse(pathNames ...string) for multiple entries.

Note: A DotPath is immutable, and thus concurrency safe.

func FilePathS

func FilePathS(pathLists ...string) (filePathS []*DotPath)

FilePathS returns a non-empty slice of NewFilePath

Note: each pathList is split via filepath.SplitList,
is expanded against the os environmant, and
is normalised via filepath.FromSlash

func New

func New(path, sep string) *DotPath

New returns a parsed *DotPath - separated by sep

Note: sep must have len == 1 and must not be dot

func NewFilePath

func NewFilePath(path string) *DotPath

NewFilePath returns a parsed *DotPath - separated by the current os.PathSeparator

func NewPath

func NewPath(path string) *DotPath

NewPath returns a parsed *DotPath - separated by go's PathSeparator Slash `/`

func PathS

func PathS(pathNames ...string) (pathS []DotPath)

PathS returns a non-empty slice of NewPath

Note: each pathName is not split any further -filepath.SplitList is not applied-, but
is normalised via filepath.ToSlash

func (*DotPath) HasVolumeName

func (dp *DotPath) HasVolumeName() bool

HasVolumeName - returns true if some filepath.VolumeName was found

Note: only relevant, if separator == OsPathSeparator, e.g. NewFilePath

func (*DotPath) LooksLikeIsAbs

func (dp *DotPath) LooksLikeIsAbs() bool

LooksLikeIsAbs - returns true if some leading Slash was found

func (*DotPath) LooksLikeIsDir

func (dp *DotPath) LooksLikeIsDir() bool

LooksLikeIsDir - returns true if some trailing Slash was found

func (*DotPath) Path

func (dp *DotPath) Path() string

Path - returns the path - less any triple ... dots and any (eventual) trailing slash (including volumename, if any).

func (*DotPath) PathBase

func (dp *DotPath) PathBase() string

PathBase - returns the path - less any triple ... dots and trailing up .. double dots, (including volumename and trailing delimiter, if any).

func (*DotPath) PathBaseS

func (dp *DotPath) PathBaseS() (pathBaseS []string)

PathBaseS returns a slice of strings each representing a node / element / PathBase. The order is last-first / bottom up / reversed. All slashes are gone. VolumeName is ignored.

func (*DotPath) PathName

func (dp *DotPath) PathName() string

PathName - returns the full analysed path - incl. any triple ... dots

Note: intentionally, path.Cleaning is is not applied as
some tripledot might disappear due to being followed by some doubledot.

func (*DotPath) PathS

func (dp *DotPath) PathS() (pathS []string)

PathS conveniently returns any WaydownPath and the Base.

Note: If there is no way down mentioned (and thus: Path and Base are same),
the returned list just holds this single element: the Path

func (*DotPath) PathText

func (dp *DotPath) PathText() string

PathText - returns the path - less any triple ... dots, (including volumename and trailing delimiter, if any).

func (*DotPath) Print

func (dp *DotPath) Print()

Print prints a commented tab-terminated list

func (*DotPath) RecursePathS

func (dp *DotPath) RecursePathS() (pathS []string)

RecursePathS returns any (partial) path which ends in a Down ...

func (*DotPath) Separator

func (dp *DotPath) Separator() string

Separator - returns the single character separator string

func (*DotPath) String

func (dp *DotPath) String() string

String - returns the original input - skipping nothing

func (*DotPath) VolumeName

func (dp *DotPath) VolumeName() string

VolumeName - returns the VolumeName, if any

Note: only relevant, if separator == OsPathSeparator, e.g. NewFilePath

func (*DotPath) WaydownPathS

func (dp *DotPath) WaydownPathS() (pathS []string)

WaydownPathS returns any (partial) path which is followed by some trailing GoUp ..

Note: such pathS should be considered before PathBase(), and are
only relevant if PathText() != PathBase(); Path() would be the first WaydownPath

Jump to

Keyboard shortcuts

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