cutOutTerminatedPath cuts out the resource path terminated with the provided marker (path segment suffix). e.g. subPath: "/space1/space2/+/authToken", marker: "/+" => "/space1/space2" e.g. subPath: "/space1/space2.git", marker: ".git" => "/space1/space2" e.g. subPath: "/space1/space2.git/", marker:
(subPath string, marker string)
| 270 | // case 2: xxxxxxxxxxxxxxxxxxxxxxxxM/ (M is at the end and it should have a / after it) |
| 271 | // case 3: xxxxxxxxxxxxxxxxxxxxxxxxxM (M is at the end). |
| 272 | func cutOutTerminatedPath(subPath string, marker string) (string, bool) { |
| 273 | // base case of marker being empty |
| 274 | if marker == "" { |
| 275 | return subPath, true |
| 276 | } |
| 277 | endsWithSlash := strings.HasSuffix(marker, "/") |
| 278 | if !endsWithSlash { |
| 279 | marker += "/" |
| 280 | } |
| 281 | |
| 282 | // case 1 and case 2 |
| 283 | if path, _, found := strings.Cut(subPath, marker); found { |
| 284 | return path, true |
| 285 | } |
| 286 | |
| 287 | if endsWithSlash { |
| 288 | return "", false |
| 289 | } |
| 290 | |
| 291 | trimmedMarker := strings.TrimSuffix(marker, "/") |
| 292 | if strings.HasSuffix(subPath, trimmedMarker) { |
| 293 | subPath = subPath[:len(subPath)-len(trimmedMarker)] |
| 294 | return subPath, true |
| 295 | } |
| 296 | |
| 297 | return "", false |
| 298 | } |
no outgoing calls
searching dependent graphs…