revert stringstack.go changes

This commit is contained in:
wish
2023-12-03 17:50:01 +11:00
parent da022d913b
commit 4ce65e47e6
2 changed files with 24 additions and 4 deletions

View File

@@ -6,7 +6,8 @@ import (
// StringStack is a basic LIFO "stack" for storing strings.
type StringStack struct {
stack []string
Locked bool
stack []string
}
// New creates a new instance of StringStack
@@ -19,6 +20,20 @@ func (s *StringStack) Set(v string) {
s.stack = []string{v}
}
// Lock freezes the StringStack
func (s *StringStack) Lock() {
if !s.Locked {
s.Locked = true
}
}
// Unlock unfreezes the StringStack
func (s *StringStack) Unlock() {
if s.Locked {
s.Locked = false
}
}
// Push pushes a string onto the stack.
func (s *StringStack) Push(v string) {
s.stack = append(s.stack, v)
@@ -26,11 +41,12 @@ func (s *StringStack) Push(v string) {
// Pop pops a string from the stack.
func (s *StringStack) Pop() (string, error) {
var x string
if len(s.stack) == 0 {
return "", errors.New("no items on stack")
return x, errors.New("no items on stack")
}
x := s.stack[len(s.stack)-1]
x = s.stack[len(s.stack)-1]
s.stack = s.stack[:len(s.stack)-1]
return x, nil