Skip to content

Commit

Permalink
feat: Possibilita usar a funcao tamanho() com tipos de seq
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfeitosa committed Dec 27, 2023
1 parent 563008e commit 2f0098d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ptst/texto.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ptst
import (
"fmt"
"strings"
"unicode/utf8"
)

type Texto string
Expand Down Expand Up @@ -88,6 +89,10 @@ func (t Texto) O__multiplica__(outro Objeto) (Objeto, error) {
}
}

func (t Texto) O__tamanho__() (Objeto, error) {
return Inteiro(utf8.RuneCountInString(string(t))), nil
}

// func (t Texto) O__subtrai__(outro Objeto) (Objeto, error) {}

// func (t Texto) O__divide__(outro Objeto) (Objeto, error) {}
Expand All @@ -113,6 +118,7 @@ var _ I__multiplica__ = (*Texto)(nil)
// var _ I__subtrai__ = (*Texto)(nil)
// var _ I__divide__ = (*Texto)(nil)
// var _ I_Mapa = (*Texto)(nil)
var _ I__tamanho__ = (*Texto)(nil)

func init() {
TipoTexto.Mapa["junta"] = NewMetodoOuPanic("junta", func(inst Objeto, iter Objeto) (Objeto, error) {
Expand Down
7 changes: 6 additions & 1 deletion ptst/tupla.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@ func (t Tupla) O__texto__() (Objeto, error) {
return t.GRepr("(", ")")
}

func (t Tupla) O__tamanho__() (Objeto, error) {
return Inteiro(len(t)), nil
}

var _ I__iter__ = Tupla(nil)
var _ I__texto__ = Tupla(nil)
var _ I__texto__ = Tupla(nil)
var _ I__tamanho__ = Tupla(nil)

0 comments on commit 2f0098d

Please sign in to comment.