pathtools

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: Apache-2.0 Imports: 3 Imported by: 11

Documentation

Overview

Package pathtools provides utilities for manipulating paths. Most paths within Gazelle are slash-separated paths, relative to the repository root directory. The repository root directory is represented by the empty string. Paths in this format may be used directly as package names in labels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasPrefix

func HasPrefix(p, prefix string) bool

HasPrefix returns whether the slash-separated path p has the given prefix. Unlike strings.HasPrefix, this function respects component boundaries, so "/home/foo" is not a prefix is "/home/foobar/baz". If the prefix is empty, this function always returns true.

func Index added in v0.19.0

func Index(p, sub string) int

Index returns the starting index of the string sub within the non-absolute slash-separated path p. sub must start and end at component boundaries within p.

func RelBaseName

func RelBaseName(rel, prefix, root string) string

RelBaseName returns the base name for rel, a slash-separated path relative to the repository root. If rel is empty, RelBaseName returns the base name of prefix. If prefix is empty, RelBaseName returns the base name of root, the absolute file path of the repository root directory. If that's empty to, then RelBaseName returns "root".

func TrimPrefix

func TrimPrefix(p, prefix string) string

TrimPrefix returns p without the provided prefix. If p doesn't start with prefix, it returns p unchanged. Unlike strings.HasPrefix, this function respects component boundaries (assuming slash-separated paths), so TrimPrefix("foo/bar", "foo") returns "baz".

Types

This section is empty.

Jump to

Keyboard shortcuts

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