| 1 | namespace AgentForge.Abstractions; |
| 2 | |
| 3 | /// <summary> |
| 4 | /// Catalog group path (FORGE-ADR-0021 v0.7). Slashes in URLs use <c>~</c> like <see cref="ForgeRepoNames"/>. |
| 5 | /// </summary> |
| 6 | public static class ForgeRepoGroupPath |
| 7 | { |
| 8 | private const char PathSeparator = '/'; |
| 9 | private const char UrlSeparator = '~'; |
| 10 | |
| 11 | public static string NormalizeRoute(string? path) |
| 12 | { |
| 13 | if (string.IsNullOrWhiteSpace(path)) |
| 14 | return string.Empty; |
| 15 | var trimmed = path.Trim().Trim(PathSeparator); |
| 16 | if (trimmed.Contains('%', StringComparison.Ordinal)) |
| 17 | trimmed = Uri.UnescapeDataString(trimmed); |
| 18 | return trimmed.Replace(UrlSeparator, PathSeparator); |
| 19 | } |
| 20 | |
| 21 | public static string ToUrlPath(string path) => |
| 22 | NormalizeRoute(path).Replace(PathSeparator, UrlSeparator); |
| 23 | |
| 24 | public static IReadOnlyList<string> ParseSegments(string? path) |
| 25 | { |
| 26 | var normalized = NormalizeRoute(path); |
| 27 | if (string.IsNullOrEmpty(normalized)) |
| 28 | return []; |
| 29 | return normalized.Split(PathSeparator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); |
| 30 | } |
| 31 | |
| 32 | public static string JoinSegments(IReadOnlyList<string> segments) => |
| 33 | string.Join(PathSeparator, segments); |
| 34 | } |
| 35 | |
View only · write via MCP/CIDE