Files
monkey/internal/object/str.go
Chuck Smith 12d43c9835
Some checks failed
Publish Image / publish (push) Waiting to run
Test / build (push) Waiting to run
Build / build (push) Has been cancelled
Refactor Type to be an int
2024-03-29 11:01:15 -04:00

49 lines
684 B
Go

package object
import (
"fmt"
"unicode/utf8"
)
type String struct {
Value string
}
func (s *String) Len() int {
return utf8.RuneCountInString(s.Value)
}
func (s *String) Bool() bool {
return s.Value != ""
}
func (s *String) Type() Type {
return StringType
}
func (s *String) Inspect() string {
return fmt.Sprintf("%#v", s.Value)
}
func (s *String) Clone() Object {
return &String{Value: s.Value}
}
func (s *String) String() string {
return s.Value
}
func (s *String) Compare(other Object) int {
if obj, ok := other.(*String); ok {
switch {
case s.Value < obj.Value:
return -1
case s.Value > obj.Value:
return 1
default:
return 0
}
}
return 1
}