Skip to content

Commit

Permalink
refactor: rename separator
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Feb 27, 2021
1 parent 0e04fc3 commit e8fbecf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions glob.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

const (
runeSeparator = '/'
stringSeparator = string(runeSeparator)
separatorRune = '/'
separatorString = string(separatorRune)
)

// FileSystem is meant to be used with WithFs.
Expand Down Expand Up @@ -70,7 +70,7 @@ func toNixPath(path string) string {
// Glob returns all files that match the given pattern in the current directory.
func Glob(pattern string, opts ...OptFunc) ([]string, error) {
return doGlob(
strings.TrimPrefix(pattern, "."+stringSeparator),
strings.TrimPrefix(pattern, "."+separatorString),
compileOptions(opts),
)
}
Expand All @@ -79,7 +79,7 @@ func doGlob(pattern string, options *globOptions) ([]string, error) { // nolint:
fs := options.fs
var matches []string

matcher, err := glob.Compile(pattern, runeSeparator)
matcher, err := glob.Compile(pattern, separatorRune)
if err != nil {
return matches, fmt.Errorf("compile glob pattern: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func staticText(node *ast.Node) (text string, ok bool) {
// staticPrefix returns the file path inside the pattern up
// to the first path element that contains a wildcard.
func staticPrefix(pattern string) (string, error) {
parts := strings.Split(pattern, stringSeparator)
parts := strings.Split(pattern, separatorString)

// nolint:prealloc
var prefixPath []string
Expand All @@ -79,9 +79,9 @@ func staticPrefix(pattern string) (string, error) {

prefixPath = append(prefixPath, staticPart)
}
prefix := strings.Join(prefixPath, stringSeparator)
if len(pattern) > 0 && rune(pattern[0]) == runeSeparator && !strings.HasPrefix(prefix, stringSeparator) {
prefix = stringSeparator + prefix
prefix := strings.Join(prefixPath, separatorString)
if len(pattern) > 0 && rune(pattern[0]) == separatorRune && !strings.HasPrefix(prefix, separatorString) {
prefix = separatorString + prefix
}

if prefix == "" {
Expand Down

0 comments on commit e8fbecf

Please sign in to comment.