Documentation
¶
Overview ¶
Package pathx contains tiny pure utilities for slash-separated logical paths — tree paths, projection paths, URL segments. It is NOT for OS filesystem paths; for those, use path/filepath from the standard library.
Why not stdlib path ¶
path.Base / path.Dir use unix-basename semantics: empty path becomes ".", "foo/" becomes "foo", "/" stays "/". pathx uses literal last-segment / first-segment semantics where empty or trailing-slash inputs produce empty output, matching how Scrinium represents tree paths. Mixing the two would be a silent footgun. Callers that want unix-basename should reach for path.Base directly.
All functions are pure: no I/O, no allocations beyond the returned slice / string. Safe for concurrent use.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsStrictUnder ¶
IsStrictUnder reports whether p is a strict descendant of prefix — equality is NOT a match. Use IsUnder to include equality.
IsStrictUnder("a/b/c", "a/b") == true
IsStrictUnder("a/b", "a/b") == false
IsStrictUnder("a/bc", "a/b") == false
func IsUnder ¶
IsUnder reports whether p equals prefix or is a descendant of prefix (i.e. p == prefix || p starts with prefix+"/"). Empty prefix matches everything except empty p.
IsUnder("a/b/c", "a/b") == true
IsUnder("a/b", "a/b") == true
IsUnder("a/bc", "a/b") == false
IsUnder("a", "") == true
IsUnder("", "") == false
func Join ¶
Join glues parent and child with a single "/" between them. Empty parent returns child; empty child returns parent. Does not normalise existing slashes in either argument.
Join("a/b", "c") == "a/b/c"
Join("", "c") == "c"
Join("a", "") == "a"
Join("", "") == ""
func LastSegment ¶
LastSegment returns everything after the last "/" in p, or p itself if p contains no slash. Empty input returns empty.
LastSegment("a/b/c") == "c"
LastSegment("a") == "a"
LastSegment("") == ""
LastSegment("a/b/") == ""
LastSegment("/") == ""
func Parent ¶
Parent returns everything before the last "/" in p, or empty if p contains no slash.
Parent("a/b/c") == "a/b"
Parent("a") == ""
Parent("/a") == ""
Parent("") == ""
func SplitFirst ¶
SplitFirst returns the first segment and the remainder of p. For paths with no slash the entire input is the first segment and rest is "".
SplitFirst("a/b/c") == ("a", "b/c")
SplitFirst("a") == ("a", "")
SplitFirst("") == ("", "")
SplitFirst("/a") == ("", "a")
Types ¶
This section is empty.