fspath

package
v0.0.0-...-989fa2c Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2023 License: Apache-2.0, MIT Imports: 3 Imported by: 0

Documentation

Overview

Package fspath provides efficient tools for working with file paths in Linux-compatible filesystem implementations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Builder

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

Builder is similar to strings.Builder, but is used to produce pathnames given path components in reverse order (from leaf to root). This is useful in the common case where a filesystem is represented by a tree of named nodes, and the path to a given node must be produced by walking upward from that node to a given root.

func (*Builder) AppendString

func (b *Builder) AppendString(str string)

AppendString appends the given string to b's buffer.

func (*Builder) Len

func (b *Builder) Len() int

Len returns the number of accumulated bytes.

func (*Builder) PrependByte

func (b *Builder) PrependByte(c byte)

PrependByte prepends the given byte to b's buffer.

func (*Builder) PrependComponent

func (b *Builder) PrependComponent(pc string)

PrependComponent prepends the given path component to b's buffer. A path separator is automatically inserted if appropriate.

func (*Builder) PrependString

func (b *Builder) PrependString(str string)

PrependString prepends the given string to b's buffer.

func (*Builder) Reset

func (b *Builder) Reset()

Reset resets the Builder to be empty.

func (*Builder) String

func (b *Builder) String() string

String returns the accumulated string. No other methods should be called after String.

type Iterator

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

An Iterator represents either a path component in a Path or a terminal iterator indicating that the end of the path has been reached.

Iterator is immutable and copyable by value. The zero value of Iterator is valid, and represents a terminal iterator.

func (Iterator) Next

func (it Iterator) Next() Iterator

Next returns an iterator to the path component after it. If it is the last component in the path, Next returns a terminal iterator.

Preconditions: it.Ok().

func (Iterator) NextOk

func (it Iterator) NextOk() bool

NextOk is equivalent to it.Next().Ok(), but is faster.

Preconditions: it.Ok().

func (Iterator) Ok

func (it Iterator) Ok() bool

Ok returns true if it is not terminal.

func (Iterator) String

func (it Iterator) String() string

String returns the path component represented by it.

Preconditions: it.Ok().

type Path

type Path struct {
	// Begin is an iterator to the first path component in the relative part of
	// the path.
	//
	// Path doesn't store information about path components after the first
	// since this would require allocation.
	Begin Iterator

	// If true, the path is absolute, such that lookup should begin at the
	// filesystem root. If false, the path is relative, such that where lookup
	// begins is unspecified.
	Absolute bool

	// If true, the pathname contains trailing path separators, so the last
	// path component must exist and resolve to a directory.
	Dir bool
}

Path contains the information contained in a pathname string.

Path is copyable by value. The zero value for Path is equivalent to fspath.Parse(""), i.e. the empty path.

func Parse

func Parse(pathname string) Path

Parse parses a pathname as described by path_resolution(7), except that empty pathnames will be parsed successfully to a Path for which Path.Absolute == Path.Dir == Path.HasComponents() == false. (This is necessary to support AT_EMPTY_PATH.)

func (Path) HasComponents

func (p Path) HasComponents() bool

HasComponents returns true if p contains a non-zero number of path components.

func (Path) String

func (p Path) String() string

String returns a pathname string equivalent to p. Note that the returned string is not necessarily equal to the string p was parsed from; in particular, redundant path separators will not be present.

Jump to

Keyboard shortcuts

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