pathtools: add Prefixes helper function (#2152)
**What type of PR is this?**
> Feature
**What package or component does this PR mostly affect?**
> pathtools
**What does this PR do? Why is it needed?**
In the fix for #2132, I'll need to iterate over the prefixes of a given
slash-separated path. Rather than duplicate the logic from Walk2,
let's extract it into pathtools.
Prefixes returns an iterator over prefixes to avoid needing to allocate
a slice. The code should be much simpler after we adopt Go 1.23 and can
use range-over-iterator loops.
**Which issues(s) does this PR fix?**
Fixes #2132
**Other notes for review**
5 files changed