| 1 | // Copyright 2023 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package pathutilscip-go gomod cuelang.org/go . `cuelang.org/go/internal/golangorgx/gopls/util/pathutil`/ |
| 6 | |
| 7 | import ( |
| 8 | "path/filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/" |
| 9 | "stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/" |
| 10 | ) |
| 11 | |
| 12 | // InDir checks whether path is in the file tree rooted at dir. |
| 13 | // It checks only the lexical form of the file names. |
| 14 | // It does not consider symbolic links. |
| 15 | // |
| 16 | // Copied from go/src/cmd/go/internal/search/search.go. |
| 17 | func InDirscip-go gomod cuelang.org/go . `cuelang.org/go/internal/golangorgx/gopls/util/pathutil`/InDir().(dir, path string) bool { |
| 18 | pv := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.24.0 strings/ToUpper().(filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.VolumeNamescip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/VolumeName().(path)) |
| 19 | dv := stringsscip-go gomod github.com/golang/go/src go1.24.0 strings/.ToUpperscip-go gomod github.com/golang/go/src go1.24.0 strings/ToUpper().(filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.VolumeNamescip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/VolumeName().(dir)) |
| 20 | path = path[len(pv):] |
| 21 | dir = dir[len(dv):] |
| 22 | switch { |
| 23 | default: |
| 24 | return false |
| 25 | case pv != dv: |
| 26 | return false |
| 27 | case len(path) == len(dir): |
| 28 | if path == dir { |
| 29 | return true |
| 30 | } |
| 31 | return false |
| 32 | case dir == "": |
| 33 | return path != "" |
| 34 | case len(path) > len(dir): |
| 35 | if dir[len(dir)-1] == filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Separatorscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Separator. { |
| 36 | if path[:len(dir)] == dir { |
| 37 | return path[len(dir):] != "" |
| 38 | } |
| 39 | return false |
| 40 | } |
| 41 | if path[len(dir)] == filepathscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/.Separatorscip-go gomod github.com/golang/go/src go1.24.0 `path/filepath`/Separator. && path[:len(dir)] == dir { |
| 42 | if len(path) == len(dir)+1 { |
| 43 | return true |
| 44 | } |
| 45 | return path[len(dir)+1:] != "" |
| 46 | } |
| 47 | return false |
| 48 | } |
| 49 | } |