File: stack.go

package info (click to toggle)
golang-github-xo-terminfo 0.0~git20210125.ca9a967-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 256 kB
  • sloc: sh: 50; makefile: 6
file content (48 lines) | stat: -rw-r--r-- 661 bytes parent folder | download | duplicates (3)
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
45
46
47
48
package terminfo

type stack []interface{}

func (s *stack) push(v interface{}) {
	*s = append(*s, v)
}

func (s *stack) pop() interface{} {
	if len(*s) == 0 {
		return nil
	}
	v := (*s)[len(*s)-1]
	*s = (*s)[:len(*s)-1]
	return v
}

func (s *stack) popInt() int {
	if i, ok := s.pop().(int); ok {
		return i
	}
	return 0
}

func (s *stack) popBool() bool {
	if b, ok := s.pop().(bool); ok {
		return b
	}
	return false
}

func (s *stack) popByte() byte {
	if b, ok := s.pop().(byte); ok {
		return b
	}
	return 0
}

func (s *stack) popString() string {
	if a, ok := s.pop().(string); ok {
		return a
	}
	return ""
}

func (s *stack) reset() {
	*s = (*s)[:0]
}