-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathBlock.go
More file actions
44 lines (36 loc) · 699 Bytes
/
Block.go
File metadata and controls
44 lines (36 loc) · 699 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package cssminify
import (
"io/ioutil"
)
type Block struct {
selector []byte
pairs []Pair
}
func Blocks(file string) []Block {
var (
letter byte
)
content := []byte(readFile(file))
state := new(State)
for letter, content = stripLetter(content); letter != 0; letter, content = stripLetter(content) {
state.parse(letter)
}
return state.blocks
}
func stripLetter(content []byte) (byte, []byte) {
var letter byte
if len(content) != 0 {
letter = content[0]
content = content[1:]
} else {
content = []byte{}
}
return letter, content
}
func readFile(root string) string {
content, err := ioutil.ReadFile(root)
if err != nil {
panic(err)
}
return string(content)
}