Path

package
v0.0.0-...-59761c8 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package path provides methods and a type for working with slash-separated paths with selectors.

Package Path provides methods and a type for working with slash-separated path strings.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ToDirectory

type ToDirectory String.Readable

ToDirectory semantically represents a path to what is expected to be a directory/folder on the filesystem.

func AsDirectory

func AsDirectory[T String.Any](path T) ToDirectory

AsDirectory returns the given path as a directory.

func (ToDirectory) MarshalText

func (s ToDirectory) MarshalText() ([]byte, error)

func (ToDirectory) String

func (s ToDirectory) String() string

func (*ToDirectory) UnmarshalText

func (s *ToDirectory) UnmarshalText(text []byte) error

type ToFile

type ToFile String.Readable

ToFile represents a path to a file within a filesystem.

A path is composed of slash-separated (/) names and period-separated (.) extensions. ".." and "." are special names. They refer to the parent and the current element respectively.

The following examples are paths relative to the current element:

"A"     			  // Points to the direct child A.
"A/B"   			  // Points to A's child B.
"."     			  // Points to the current element.
".."    			  // Points to the parent element.
"../C"  			  // Points to the sibling element C.
"../.." 		      // Points to the grandparent element.
"/root"     		  // Points to the root element.

func AsFile

func AsFile[T String.Any](path T) ToFile

AsFile returns the given path as a directory.

func (ToFile) Directory

func (s ToFile) Directory() ToDirectory

Directory returns the directory if the string is a valid file path.

func (ToFile) FileExtension

func (s ToFile) FileExtension() String.Readable

FileExtension returns the file extension without the leading period (.) if the string is a valid file name or path. Otherwise, returns an empty string.

func (ToFile) FileName

func (s ToFile) FileName() string

FileName returns the file name, including the extension, if the string is a valid file path,

func (ToFile) IsAbsolute

func (s ToFile) IsAbsolute() bool

IsAbsolute returns true if the path's starting point is explicitly defined. Unlike a relative path, an absolute path is represented by a leading slash character (/). This method is the opposite of ToFile.IsRelative.

This includes all paths starting with "res://", "user://", "C:\", "/", etc.

func (ToFile) IsRelative

func (s ToFile) IsRelative() bool

IsRelative returns true if the string is a path, and its starting point is dependent on context. The path could begin from the current directory, or the current Node (if the string is derived from a NodePath), and may sometimes be prefixed with "./". This method is the opposite of ToFile.IsAbsolute.

func (ToFile) MarshalText

func (s ToFile) MarshalText() ([]byte, error)

func (ToFile) Parent

func (s ToFile) Parent() ToDirectory

Parent returns the parent directory if the directory is valid.

func (ToFile) String

func (s ToFile) String() string

func (*ToFile) UnmarshalText

func (s *ToFile) UnmarshalText(text []byte) error

func (ToFile) WithoutExtension

func (s ToFile) WithoutExtension() ToFile

WithoutExtension returns the path before the last period character (.) in the path.

type ToNode

type ToNode String.Readable

ToNode represents a path to a generic node within a tree.

A path is composed of slash-separated (/) names and colon-separated (:) selectors. ".." and "." are special names. They refer to the parent and the current element respectively.

The following examples are paths relative to the current element:

"A"     			  // Points to the direct child A.
"A/B"   			  // Points to A's child B.
"."     			  // Points to the current element.
".."    			  // Points to the parent element.
"../C"  			  // Points to the sibling element C.
"../.." 		      // Points to the grandparent element.
"/root"     		  // Points to the root element.
":Position"           // Points to this items's position.
":Position:X"         // Points to this items's position in the x axis.
"Camera3D:Rotation:Y" // Points to the child Camera3D and its y rotation.
"/root:Size:X"        // Points to the root Window and its width.

func AsNode

func AsNode[T String.Any](path T) ToNode

AsNode returns the given path as a node path.

func (ToNode) Element

func (s ToNode) Element(i int) String.Readable

Element returns the element indicated by idx, starting from 0.

func (ToNode) Hash

func (s ToNode) Hash() uint32

Hash returns the 32-bit hash value representing the paths contents.

Note: paths with equal hash values are not guaranteed to be the same, as a result of hash collisions. Paths with different hash values are guaranteed to be different.

func (ToNode) IsAbsolute

func (s ToNode) IsAbsolute() bool

IsAbsolute returns true if the path's starting point is explicitly defined. Unlike a relative path, an absolute path is represented by a leading slash character (/). This method is the opposite of [ToNode.IsRelative].

This includes all paths starting with "res://", "user://", "C:\", "/", etc.

func (ToNode) IsEmpty

func (s ToNode) IsEmpty() bool

IsEmpty returns true if the paths's length is 0 ("").

func (ToNode) MarshalText

func (s ToNode) MarshalText() ([]byte, error)

func (ToNode) Name

func (s ToNode) Name(i int) String.Readable

Name returns the sub-selector indicated by idx, starting from 0.

func (ToNode) NumElement

func (s ToNode) NumElement() int

NumElement returns the number of elements in the path.

func (ToNode) NumName

func (s ToNode) NumName() int

NumName returns the number of sub-selectors in the path.

func (ToNode) PrefixedWithSelector

func (s ToNode) PrefixedWithSelector() ToNode

PrefixedWithSelector returns a copy of this path with a period character (.) prefixed, transforming it to a pure selector with no items (relative to the current item).

func (ToNode) Selector

func (s ToNode) Selector() String.Readable

Selector returns the selector in the path.

func (ToNode) StartingFrom

func (s ToNode) StartingFrom(start int) ToNode

StartingFrom returns a slice of the path from the given start index to the end of the path.

func (ToNode) String

func (s ToNode) String() string

func (*ToNode) UnmarshalText

func (s *ToNode) UnmarshalText(text []byte) error

func (ToNode) WithoutSelector

func (s ToNode) WithoutSelector() ToNode

WithoutSelector returns the path up until the first selector.

type ToResource

type ToResource = ToFile

Jump to

Keyboard shortcuts

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