...

Source file src/cuelang.org/go/pkg/path/path_nix.go

Documentation: cuelang.org/go/pkg/path

     1  // Copyright 2020 CUE Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Copyright 2010 The Go Authors. All rights reserved.
    16  // Use of this source code is governed by a BSD-style
    17  // license that can be found in the LICENSE file.
    18  
    19  package path
    20  
    21  import "strings"
    22  
    23  type unixInfo struct{}
    24  
    25  var _ osInfo = unixInfo{}
    26  
    27  const (
    28  	unixListSeparator = ':'
    29  	unixSeparator     = '/'
    30  )
    31  
    32  func (o unixInfo) IsPathSeparator(b byte) bool {
    33  	return b == unixSeparator
    34  }
    35  
    36  // IsAbs reports whether the path is absolute.
    37  func (o unixInfo) IsAbs(path string) bool {
    38  	return strings.HasPrefix(path, "/")
    39  }
    40  
    41  // volumeNameLen returns length of the leading volume name on Windows.
    42  // It returns 0 elsewhere.
    43  func (o unixInfo) volumeNameLen(path string) int {
    44  	return 0
    45  }
    46  
    47  // HasPrefix exists for historical compatibility and should not be used.
    48  //
    49  // Deprecated: HasPrefix does not respect path boundaries and
    50  // does not ignore case when required.
    51  func (o unixInfo) HasPrefix(p, prefix string) bool {
    52  	return strings.HasPrefix(p, prefix)
    53  }
    54  
    55  func (o unixInfo) splitList(path string) []string {
    56  	if path == "" {
    57  		return []string{}
    58  	}
    59  	return strings.Split(path, string(unixListSeparator))
    60  }
    61  
    62  func (o unixInfo) join(elem []string) string {
    63  	// If there's a bug here, fix the logic in ./path_plan9.go too.
    64  	for i, e := range elem {
    65  		if e != "" {
    66  			return clean(strings.Join(elem[i:], string(unixSeparator)), unix)
    67  		}
    68  	}
    69  	return ""
    70  }
    71  
    72  func (o unixInfo) sameWord(a, b string) bool {
    73  	return a == b
    74  }
    75  

View as plain text