Skip to content

Commit

Permalink
Improved ValidTrytes implementation - got rid of regexp (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
siziyman authored and luca-moser committed Sep 5, 2019
1 parent cf6c72d commit d40e388
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions trinary/trinary.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package trinary

import (
"math"
"regexp"
"strings"

. "github.com/iotaledger/iota.go/consts"
Expand Down Expand Up @@ -465,13 +464,16 @@ type Hash = Trytes
// Hashes is a slice of Hash.
type Hashes = []Hash

var trytesRegex = regexp.MustCompile("^[9A-Z]+$")

// ValidTrytes returns true if t is made of valid trytes.
func ValidTrytes(trytes Trytes) error {
if !trytesRegex.MatchString(string(trytes)) {
if trytes == "" {
return ErrInvalidTrytes
}
for _, runeVal := range trytes {
if (runeVal < 'A' || runeVal > 'Z') && runeVal != '9' {
return ErrInvalidTrytes
}
}
return nil
}

Expand Down

0 comments on commit d40e388

Please sign in to comment.