stack.go 661 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package terminfo
  2. type stack []interface{}
  3. func (s *stack) push(v interface{}) {
  4. *s = append(*s, v)
  5. }
  6. func (s *stack) pop() interface{} {
  7. if len(*s) == 0 {
  8. return nil
  9. }
  10. v := (*s)[len(*s)-1]
  11. *s = (*s)[:len(*s)-1]
  12. return v
  13. }
  14. func (s *stack) popInt() int {
  15. if i, ok := s.pop().(int); ok {
  16. return i
  17. }
  18. return 0
  19. }
  20. func (s *stack) popBool() bool {
  21. if b, ok := s.pop().(bool); ok {
  22. return b
  23. }
  24. return false
  25. }
  26. func (s *stack) popByte() byte {
  27. if b, ok := s.pop().(byte); ok {
  28. return b
  29. }
  30. return 0
  31. }
  32. func (s *stack) popString() string {
  33. if a, ok := s.pop().(string); ok {
  34. return a
  35. }
  36. return ""
  37. }
  38. func (s *stack) reset() {
  39. *s = (*s)[:0]
  40. }