dotpath

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2024 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package fqn contains tools to efficiently parse and operate on fully qualified names of format a.b.c or .a.b.c

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Instance

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

Instance holds a dotpath string view.

func Parse

func Parse(source *string) Instance

Parse takes a string pointer, keeps it as a reference.

NOTE: This tool is meant to use pointers in order to avoid copying data, because of this no updates to the input string can happen after calling Parse for the lifetime of this object.

func ParseString

func ParseString(source string) Instance

ParseString is similar to Parse but it safely copies the string which is less efficient but is safe.

func (Instance) HasRef

func (i Instance) HasRef() bool

HasRef returns whether or not this instance has an underlying string reference, if the result is false calling other methods can lead to a panic.

func (Instance) Index

func (i Instance) Index(index int) string

Index returns path segment at index.

func (Instance) IsAbsolute

func (i Instance) IsAbsolute() bool

IsAbsolute indicates whether this path is an absolute path. Absolute paths start with '.'

func (Instance) MaxDepth

func (i Instance) MaxDepth() int

MaxDepth returns the maximum depth this path has.

Note that this depth is the largest depth index, not the count.

func (Instance) NumberOfSegments

func (i Instance) NumberOfSegments() int

NumberOfSegments returns the number of segments in the dot-separated qualified name.

func (Instance) Parts

func (i Instance) Parts() []string

Parts returns all segments, akin to strings.Split(input, ".") but it differs in implementation.

func (Instance) PartsAtDepth

func (i Instance) PartsAtDepth(d int) []string

PartsAtDepth returns parts at a specific depth. At depth d, the leftmost d segments are excluded.

For instance:

If the path is "a.b.c", the parts at depth 1 are ["b", "c"].

func (Instance) PathWithoutLeadingDot

func (i Instance) PathWithoutLeadingDot() string

PathWithoutLeadingDot returns the path with the leading dot trimmed.

func (Instance) String

func (i Instance) String() string

String returns the full underlying path.

func (Instance) StringAtDepth

func (i Instance) StringAtDepth(d int) string

StringAtDepth returns the string at a specific depth from the right side. For instance, a depth of 0 for "a.b.c" returns "c" and a depth of 2 returns "a.b.c".

func (Instance) TrimmedSuffix

func (i Instance) TrimmedSuffix(n int) string

TrimmedSuffix returns the path trimmed of n segments from the right. For instance, for n=0 and n=1 in path "a.b.c", trimmed result would be a.b.c and a.b

Jump to

Keyboard shortcuts

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