aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/cli/internal/doublestar/utils.go
diff options
context:
space:
mode:
author简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:55 +0800
committer简律纯 <hsiangnianian@outlook.com>2023-04-28 01:36:55 +0800
commitfc8c5fdce62fb229202659408798a7b6c98f6e8b (patch)
tree7554f80e50de4af6fd255afa7c21bcdd58a7af34 /cli/internal/doublestar/utils.go
parentdd84b9d64fb98746a230cd24233ff50a562c39c9 (diff)
downloadHydroRoll-fc8c5fdce62fb229202659408798a7b6c98f6e8b.tar.gz
HydroRoll-fc8c5fdce62fb229202659408798a7b6c98f6e8b.zip
Diffstat (limited to 'cli/internal/doublestar/utils.go')
-rw-r--r--cli/internal/doublestar/utils.go71
1 files changed, 0 insertions, 71 deletions
diff --git a/cli/internal/doublestar/utils.go b/cli/internal/doublestar/utils.go
deleted file mode 100644
index 7236cd0..0000000
--- a/cli/internal/doublestar/utils.go
+++ /dev/null
@@ -1,71 +0,0 @@
-// Package doublestar is adapted from https://github.com/bmatcuk/doublestar
-// Copyright Bob Matcuk. All Rights Reserved.
-// SPDX-License-Identifier: MIT
-package doublestar
-
-// SplitPattern is a utility function. Given a pattern, SplitPattern will
-// return two strings: the first string is everything up to the last slash
-// (`/`) that appears _before_ any unescaped "meta" characters (ie, `*?[{`).
-// The second string is everything after that slash. For example, given the
-// pattern:
-//
-// ../../path/to/meta*/**
-// ^----------- split here
-//
-// SplitPattern returns "../../path/to" and "meta*/**". This is useful for
-// initializing os.DirFS() to call Glob() because Glob() will silently fail if
-// your pattern includes `/./` or `/../`. For example:
-//
-// base, pattern := SplitPattern("../../path/to/meta*/**")
-// fsys := os.DirFS(base)
-// matches, err := Glob(fsys, pattern)
-//
-// If SplitPattern cannot find somewhere to split the pattern (for example,
-// `meta*/**`), it will return "." and the unaltered pattern (`meta*/**` in
-// this example).
-//
-// Of course, it is your responsibility to decide if the returned base path is
-// "safe" in the context of your application. Perhaps you could use Match() to
-// validate against a list of approved base directories?
-func SplitPattern(p string) (string, string) {
- base := "."
- pattern := p
-
- splitIdx := -1
- for i := 0; i < len(p); i++ {
- c := p[i]
- if c == '\\' {
- i++
- } else if c == '/' {
- splitIdx = i
- } else if c == '*' || c == '?' || c == '[' || c == '{' {
- break
- }
- }
-
- if splitIdx >= 0 {
- return p[:splitIdx], p[splitIdx+1:]
- }
-
- return base, pattern
-}
-
-// Finds the next comma, but ignores any commas that appear inside nested `{}`.
-// Assumes that each opening bracket has a corresponding closing bracket.
-func indexNextAlt(s string, allowEscaping bool) int {
- alts := 1
- l := len(s)
- for i := 0; i < l; i++ {
- if allowEscaping && s[i] == '\\' {
- // skip next byte
- i++
- } else if s[i] == '{' {
- alts++
- } else if s[i] == '}' {
- alts--
- } else if s[i] == ',' && alts == 1 {
- return i
- }
- }
- return -1
-}