62 lines
1.1 KiB
Go
62 lines
1.1 KiB
Go
package query
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
type QueryResult []*IndexedElement
|
|
|
|
type Element struct {
|
|
Name string
|
|
NextContainer *Container
|
|
}
|
|
|
|
func (e *Element) String() string {
|
|
var containerStr = ""
|
|
|
|
if e.NextContainer != nil {
|
|
containerStr = fmt.Sprintf(".%s", e.NextContainer)
|
|
}
|
|
return fmt.Sprintf("%s%s", e.Name, containerStr)
|
|
}
|
|
|
|
type Container struct {
|
|
Name string
|
|
NextElement *Element
|
|
}
|
|
|
|
func (c *Container) String() string {
|
|
var elementStr = ""
|
|
|
|
if c.NextElement != nil {
|
|
elementStr = fmt.Sprintf(":%s", c.NextElement)
|
|
}
|
|
return fmt.Sprintf("%s%s", c.Name, elementStr)
|
|
}
|
|
|
|
type Query struct {
|
|
Container Container
|
|
}
|
|
|
|
func (q *Query) String() string {
|
|
return q.Container.String()
|
|
}
|
|
|
|
func (q *Query) IsFullyQualified() bool {
|
|
var container *Container = &q.Container
|
|
|
|
for container != nil {
|
|
if container.NextElement == nil {
|
|
// Current container has no next element, so the query ended on a container.
|
|
// Thus, it is not fully qualified.
|
|
return false
|
|
} else {
|
|
container = container.NextElement.NextContainer
|
|
}
|
|
}
|
|
|
|
// Next container is nil, so the query ended on an element.
|
|
// Thus, it is fully qualified.
|
|
return true
|
|
}
|