snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
114
server/pkg/expr/path.go
Normal file
114
server/pkg/expr/path.go
Normal file
@@ -0,0 +1,114 @@
|
||||
package expr
|
||||
|
||||
type (
|
||||
exprPath struct {
|
||||
path string
|
||||
i int
|
||||
isLast bool
|
||||
|
||||
start, end int
|
||||
}
|
||||
|
||||
Pather interface {
|
||||
String() string
|
||||
More() bool
|
||||
IsLast() bool
|
||||
Get() string
|
||||
Rest() string
|
||||
Next() (err error)
|
||||
}
|
||||
)
|
||||
|
||||
// Path initializes a new exprPath helper to efficiently traverse the path
|
||||
func Path(p string) (out *exprPath) {
|
||||
return &exprPath{path: p}
|
||||
}
|
||||
|
||||
func (p *exprPath) String() string {
|
||||
return p.path
|
||||
}
|
||||
|
||||
func (p *exprPath) More() bool {
|
||||
return p.start < len(p.path)
|
||||
}
|
||||
|
||||
func (p *exprPath) IsLast() bool {
|
||||
return p.isLast
|
||||
}
|
||||
|
||||
func (p *exprPath) Get() string {
|
||||
return p.path[p.start:p.end]
|
||||
}
|
||||
|
||||
func (p *exprPath) Rest() string {
|
||||
var rest string
|
||||
if p.end+1 < len(p.path) {
|
||||
rest = p.path[p.end:]
|
||||
}
|
||||
|
||||
// @todo this is fugly but it'll do the trick for now
|
||||
// Clean it up please :)
|
||||
if len(rest) > 0 && (rest[0] == '.' || rest[0] == ']') {
|
||||
rest = rest[1:]
|
||||
}
|
||||
if len(rest) > 0 && (rest[0] == '.' || rest[0] == ']') {
|
||||
rest = rest[1:]
|
||||
}
|
||||
|
||||
return rest
|
||||
}
|
||||
|
||||
func (p *exprPath) Next() (err error) {
|
||||
if !p.More() {
|
||||
return nil
|
||||
}
|
||||
|
||||
if p.end > 0 {
|
||||
p.start = p.end + 1
|
||||
}
|
||||
|
||||
var ()
|
||||
|
||||
p.start, p.end, p.isLast, err = nxtRange(p.path, p.start)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
p.i++
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func nxtRange(path string, start int) (startOut, end int, isLast bool, err error) {
|
||||
startOut = start
|
||||
for i := start; i < len(path); i++ {
|
||||
switch path[i] {
|
||||
// This thing concludes the prev ident
|
||||
case '.', '[':
|
||||
if i == len(path)-1 {
|
||||
return startOut, -1, false, invalidPathErr
|
||||
}
|
||||
if i > 0 {
|
||||
if path[i-1] == ']' {
|
||||
startOut++
|
||||
continue
|
||||
}
|
||||
}
|
||||
return startOut, i, false, nil
|
||||
|
||||
case ']':
|
||||
// If we're at the end, that's that
|
||||
if i == len(path)-1 {
|
||||
return startOut, i, true, nil
|
||||
}
|
||||
|
||||
if path[i+1] != '.' && path[i+1] != '[' {
|
||||
return startOut, -1, false, invalidPathErr
|
||||
} else {
|
||||
return startOut, i, false, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return startOut, len(path), true, nil
|
||||
}
|
||||
Reference in New Issue
Block a user