diff options
Diffstat (limited to 'pkg/utils')
-rw-r--r-- | pkg/utils/string_stack.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/pkg/utils/string_stack.go b/pkg/utils/string_stack.go new file mode 100644 index 000000000..c2d18c70c --- /dev/null +++ b/pkg/utils/string_stack.go @@ -0,0 +1,27 @@ +package utils + +type StringStack struct { + stack []string +} + +func (self *StringStack) Push(s string) { + self.stack = append(self.stack, s) +} + +func (self *StringStack) Pop() string { + if len(self.stack) == 0 { + return "" + } + n := len(self.stack) - 1 + last := self.stack[n] + self.stack = self.stack[:n] + return last +} + +func (self *StringStack) IsEmpty() bool { + return len(self.stack) == 0 +} + +func (self *StringStack) Clear() { + self.stack = []string{} +} |