Skip to content

Commit

Permalink
reduce cyclomatics
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseCoretta committed Aug 4, 2023
1 parent 5382e47 commit 9268923
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
6 changes: 5 additions & 1 deletion asn.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,13 @@ func (a ASN1Notation) AncestorOf(asn any) bool {
return false
}

return a.matchASN1(A)
}

func (a ASN1Notation) matchASN1(asn *ASN1Notation) bool {
for i := 0; i < a.Len(); i++ {
x, _ := a.Index(i)
y, ok := A.Index(i)
y, ok := asn.Index(i)
if !ok {
return false
}
Expand Down
4 changes: 2 additions & 2 deletions doc.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/*
Package objectid implements ASN.1 Object Identifier types and methods.
Features
# Features
• Unsigned 128-bit numberForm support (i.e.: such as the registrations found below {joint-iso-itu-t(2) uuid(25)})
• Flexible index support, allowing interrogation through negative indices without the risk of panic
• Convenient Leaf, Parent and Root index alias methods, wherever allowed
Uint128 Support
# Uint128 Support
Unsigned 128-bit integer support for individual NumberForm values is made possible due to the private incorporation of Luke Champine's awesome Uint128 type, which manifests here through instances of the package-provided NumberForm type.
Expand Down
6 changes: 5 additions & 1 deletion dot.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,13 @@ func (d DotNotation) AncestorOf(dot any) bool {
return false
}

return d.matchDotNot(D)
}

func (d DotNotation) matchDotNot(dot *DotNotation) bool {
for i := 0; i < d.Len(); i++ {
x, _ := d.Index(i)
y, ok := D.Index(i)
y, ok := dot.Index(i)
if !ok {
return false
}
Expand Down
36 changes: 22 additions & 14 deletions nf.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,8 @@ Any input that represents a negative number guarantees a false return.
*/
func (a NumberForm) Gt(n any) bool {
switch tv := n.(type) {
case NumberForm:
return a.hi > tv.hi || (a.hi == tv.hi && a.lo > tv.lo)
case string:
if nf, err := NewNumberForm(tv); err == nil {
return a.hi > nf.hi || (a.hi == nf.hi && a.lo > nf.lo)
}
case NumberForm, string:
return a.gtLt(tv, false)
case uint64:
return a.lo > tv && a.hi == uint64(0)
case int:
Expand All @@ -94,14 +90,8 @@ Any input that represents a negative number guarantees a false return.
*/
func (a NumberForm) Lt(n any) bool {
switch tv := n.(type) {
case NumberForm:
return a.hi < tv.hi || (a.hi == tv.hi && a.lo < tv.lo)
case string:
if nf, err := NewNumberForm(tv); err == nil {
return a.hi < nf.hi || (a.hi == nf.hi && a.lo < nf.lo)
} else {
printf("%s", err.Error())
}
case NumberForm, string:
return a.gtLt(tv, true)
case uint64:
return a.lo < tv && a.hi == uint64(0)
case int:
Expand All @@ -112,6 +102,24 @@ func (a NumberForm) Lt(n any) bool {
return false
}

func (a NumberForm) gtLt(x any, lt bool) bool {
var nf NumberForm

switch tv := x.(type) {
case string:
nf, _ = NewNumberForm(tv)
case NumberForm:
nf = tv
default:
return false
}

if lt {
return a.hi < nf.hi || (a.hi == nf.hi && a.lo < nf.lo)
}
return a.hi > nf.hi || (a.hi == nf.hi && a.lo > nf.lo)
}

/*
Valid returns a boolean valud indicative of proper instantiation.
*/
Expand Down

0 comments on commit 9268923

Please sign in to comment.