File: specificity.go

package info (click to toggle)
golang-github-andybalholm-cascadia 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 536 kB
  • sloc: makefile: 3
file content (26 lines) | stat: -rw-r--r-- 545 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package cascadia

// Specificity is the CSS specificity as defined in
// https://www.w3.org/TR/selectors/#specificity-rules
// with the convention Specificity = [A,B,C].
type Specificity [3]int

// returns `true` if s < other (strictly), false otherwise
func (s Specificity) Less(other Specificity) bool {
	for i := range s {
		if s[i] < other[i] {
			return true
		}
		if s[i] > other[i] {
			return false
		}
	}
	return false
}

func (s Specificity) Add(other Specificity) Specificity {
	for i, sp := range other {
		s[i] += sp
	}
	return s
}