/css/selectors/selectors.go
https://code.google.com/p/gosvg/ · Go · 85 lines · 64 code · 21 blank · 0 comment · 4 complexity · 78bbefeb3bc43d29b60c9959c33082c0 MD5 · raw file
- package selectors
- import ()
- type selector interface {
- String() string
- }
- type SimpleSelector struct {
- type_val string
- extra_val string
- sealed bool
- }
- func (s *SimpleSelector) String() string {
- if s.extra_val == "" {
- return s.type_val
- }
- if s.type_val == "*" {
- return s.extra_val
- }
-
- return s.type_val + s.extra_val
- }
- func (s *SimpleSelector) Sealed() bool {
- return s.sealed
- }
- func Universal() *SimpleSelector {
- return &SimpleSelector{type_val:"*"}
- }
- func Type(s string) *SimpleSelector {
- return &SimpleSelector{type_val:s}
- }
- func Attribute(s string) *SimpleSelector {
- return &SimpleSelector{type_val:"*", extra_val:"[" + s + "]"}
- }
- func AttributeSpaceList(s, b string) *SimpleSelector {
- return Attribute(s + "~=\"" + b + "\"")
- }
- func AttributeEquals(s, b string) *SimpleSelector {
- return Attribute(s + "=\"" + b + "\"")
- }
- func AttributeBegins(s, b string) *SimpleSelector {
- return Attribute(s + "^=\"" + b + "\"")
- }
- func AttributeEnds(s, b string) *SimpleSelector {
- return Attribute(s + "$=\"" + b + "\"")
- }
- func AttributeSubstring(s, b string) *SimpleSelector {
- return Attribute(s + "*=\"" + b + "\"")
- }
- func AttributeHyphenList(s, b string) *SimpleSelector {
- return Attribute(s + "|=\"" + b + "\"")
- }
- func PseudoClass(s string) *SimpleSelector {
- return &SimpleSelector{type_val:"*", extra_val: ":" + s}
- }
- func PseudoElement(s string) *SimpleSelector {
- return &SimpleSelector{type_val:"*", extra_val: "::" + s}
- }
- func Id(id string) *SimpleSelector {
- return &SimpleSelector{type_val:"", extra_val: "#" + id}
- }
- func Not(s *SimpleSelector) *SimpleSelector {
- s.sealed = true
- return &SimpleSelector{}
- }
- type GroupSelector struct {
- }