Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions cpfcnpj.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"regexp"
"strconv"
"unicode"
)

// "Cadastro" will be used internally to define both CPF and CNPJ.
Expand Down Expand Up @@ -85,7 +84,7 @@ func calcCadastroDigit(doc string, position int) string {
func cleanCadastro(doc *string) {
buf := bytes.NewBufferString("")
for _, r := range *doc {
if unicode.IsDigit(r) || unicode.IsLetter(r) {
if isDigit(r) || ('A' <= r && r <= 'Z') {
buf.WriteRune(r)
}
}
Expand Down
3 changes: 1 addition & 2 deletions rg.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"errors"
"regexp"
"unicode"
)

var (
Expand Down Expand Up @@ -60,7 +59,7 @@ func calcRGDigit(doc string) int {
func cleanRG(doc *string) {
buf := bytes.NewBufferString("")
for _, r := range *doc {
if unicode.IsDigit(r) || r == 'X' || r == 'x' {
if isDigit(r) || r == 'X' || r == 'x' {
buf.WriteRune(r)
}
}
Expand Down
11 changes: 8 additions & 3 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ package brdoc

import (
"bytes"
"unicode"
)

// allDigit checks if every rune in a given string is a digit.
func allDigit(doc string) bool {
for _, r := range doc {
if !unicode.IsDigit(r) {
if !isDigit(r) {
return false
}
}
Expand All @@ -25,7 +24,7 @@ func toInt(r rune) int {
func cleanNonDigits(doc *string) {
buf := bytes.NewBufferString("")
for _, r := range *doc {
if unicode.IsDigit(r) {
if isDigit(r) {
buf.WriteRune(r)
}
}
Expand Down Expand Up @@ -57,3 +56,9 @@ func isFrom(uf UF, ufs []UF) bool {
}
return false
}

// isDigit is a simpler version of unicode.IsDigit: verifies whether a rune is
// a single digit number.
func isDigit(r rune) bool {
return '0' <= r && r <= '9'
}