Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from JesseCoretta/v1-dev
Browse files Browse the repository at this point in the history
v1.0.0 release prep
  • Loading branch information
JesseCoretta committed Oct 8, 2023
2 parents ee3bef3 + c19b07d commit d581824
Show file tree
Hide file tree
Showing 11 changed files with 2,998 additions and 1,965 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# go-stackage

[![Go Report Card](https://goreportcard.com/badge/github.com/JesseCoretta/go-stackage)](https://goreportcard.com/report/github.com/JesseCoretta/go-stackage) [![codecov](https://codecov.io/gh/JesseCoretta/go-stackage/graph/badge.svg?token=RLW4DHLKQP)](https://codecov.io/gh/JesseCoretta/go-stackage) [![Go Reference](https://pkg.go.dev/badge/github.com/JesseCoretta/go-stackage.svg)](https://pkg.go.dev/github.com/JesseCoretta/go-stackage) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/JesseCoretta/go-stackage/blob/main/LICENSE) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/JesseCoretta/go-stackage/issues) [![Experimental](https://img.shields.io/badge/experimental-blue?logoColor=blue&label=%F0%9F%A7%AA%20%F0%9F%94%AC&labelColor=blue&color=gray)](https://github.com/JesseCoretta/JesseCoretta/blob/main/EXPERIMENTAL.md) [![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/jessecoretta/go-aci/go.yml?event=push)](https://github.com/JesseCoretta/go-stackage/actions/workflows/go.yml) [![Libraries.io dependency status for GitHub repo](https://img.shields.io/librariesio/github/JesseCoretta/go-stackage)](https://github/JesseCoretta/go-stackage)
[![Go Report Card](https://goreportcard.com/badge/github.com/JesseCoretta/go-stackage)](https://goreportcard.com/report/github.com/JesseCoretta/go-stackage) [![codecov](https://codecov.io/gh/JesseCoretta/go-stackage/branch/v1-dev/graph/badge.svg?token=RLW4DHLKQP)](https://codecov.io/gh/JesseCoretta/go-stackage/tree/v1-dev/) [![Go Reference](https://pkg.go.dev/badge/github.com/JesseCoretta/go-stackage.svg)](https://pkg.go.dev/github.com/JesseCoretta/go-stackage) [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/JesseCoretta/go-stackage/blob/main/LICENSE) [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/JesseCoretta/go-stackage/issues) [![Experimental](https://img.shields.io/badge/experimental-blue?logoColor=blue&label=%F0%9F%A7%AA%20%F0%9F%94%AC&labelColor=blue&color=gray)](https://github.com/JesseCoretta/JesseCoretta/blob/main/EXPERIMENTAL.md) [![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/jessecoretta/go-aci/go.yml?event=push)](https://github.com/JesseCoretta/go-stackage/actions/workflows/go.yml)
[![Author](https://img.shields.io/badge/author-Jesse_Coretta-darkred?label=%F0%9F%94%BA&labelColor=indigo&color=maroon)](https://www.linkedin.com/in/jessecoretta/) [![Help Animals](https://img.shields.io/badge/donations-yellow?label=%F0%9F%98%BA&labelColor=Yellow)](https://github.com/JesseCoretta/JesseCoretta/blob/main/DONATIONS.md)

Package stackage implements a flexible Stack type with useful features.
112 changes: 31 additions & 81 deletions cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ Len returns the integer length of the receiver, defining the number of
key/value pairs present.
*/
func (r Auxiliary) Len() int {
if r == nil {
return 0
}
return len(r)
}

Expand All @@ -94,12 +91,8 @@ explicitly set to false prior to return.
Case is significant in the matching process.
*/
func (r Auxiliary) Get(key string) (value any, ok bool) {
if r == nil {
return
}

if value, ok = r[key]; value == nil {
ok = false
if r != nil {
value, ok = r[key]
}

return
Expand All @@ -112,11 +105,9 @@ also the Unset method.
If the receiver is not initialized, a new allocation is made.
*/
func (r Auxiliary) Set(key string, value any) Auxiliary {
if r == nil {
return r
if r != nil {
r[key] = value
}

r[key] = value
return r
}

Expand Down Expand Up @@ -196,11 +187,6 @@ func (r stack) stackType() stackType {
return sc.stackType()
}

func (r stack) stackKind() string {
sc, _ := r.config()
return sc.kind()
}

func (r nodeConfig) isError() bool {
return r.err != nil
}
Expand Down Expand Up @@ -261,13 +247,11 @@ if the cfold bit is enabled.
*/
func (r *nodeConfig) kind() (kind string) {
kind = `null`
if r.isZero() {
return
}

switch r.typ {
case and, or, not, list, cond, basic:
kind = foldValue(r.positive(cfold), r.typ.String())
if !r.isZero() {
switch r.typ {
case and, or, not, list, cond, basic:
kind = foldValue(r.positive(cfold), r.typ.String())
}
}

return
Expand All @@ -278,29 +262,26 @@ valid returns an error if the receiver is considered to be
invalid or nil.
*/
func (r *nodeConfig) valid() (err error) {
if r.isZero() {
err = errorf("%T instance is nil; aborting", r)
return
}
if r.typ == 0x0 {
err = errorf("%T instance is nil; aborting", r)
if !r.isZero() {
err = errorf("%T instance defines no stack \"kind\", or %T is invalid", r, r)
return
if r.typ != 0x0 {
err = nil
}
}

err = r.getErr()
return
}

/*
positive returns a Boolean value indicative of whether the specified
cfgFlag input value is "on" within the receiver's opt field.
*/
func (r nodeConfig) positive(x cfgFlag) bool {
if err := r.valid(); err != nil {
return false
func (r nodeConfig) positive(x cfgFlag) (is bool) {
if err := r.valid(); err == nil {
is = r.opt.positive(x)
}

return r.opt.positive(x)
return
}

/*
Expand All @@ -316,11 +297,9 @@ setOpt sets the specified cfgFlag to "on" within the receiver's
opt field.
*/
func (r *nodeConfig) setOpt(x cfgFlag) (err error) {
if err = r.valid(); err != nil {
return
if err = r.valid(); err == nil {
r.opt.shift(x)
}

r.opt.shift(x)
return
}

Expand Down Expand Up @@ -383,8 +362,6 @@ input length (x).
*/
func (r *nodeConfig) setStringSliceEncap(x []string) {
switch len(x) {
case 0:
return
case 1:
r.setStringSliceEncapOne(x)
default:
Expand Down Expand Up @@ -414,19 +391,10 @@ setStringSliceEncapOne is a private method called by setStringSliceEncap
for the purpose of assigning a pair of characters for L and R encapsulation.
*/
func (r *nodeConfig) setStringSliceEncapTwo(x []string) {
if len(x[0])|len(x[1]) == 0 {
return
}

var found bool
for i := 0; i < 2; i++ {
for u := 0; u < len(r.enc); u++ {
if found = strInSlice(x[i], r.enc[u]); found {
break
}
}
if found {
break
for i := 0; i < 2 && !found; i++ {
for u := 0; u < len(r.enc) && !found; u++ {
found = strInSlice(x[i], r.enc[u])
}
}

Expand Down Expand Up @@ -469,12 +437,10 @@ setMutex enables the receiver's mutual exclusion
locking capabilities.
*/
func (r *nodeConfig) setMutex() {
if err := r.valid(); err != nil {
return
}

if r.mtx == nil {
r.mtx = &sync.Mutex{}
if err := r.valid(); err == nil {
if r.mtx == nil {
r.mtx = &sync.Mutex{}
}
}
}

Expand All @@ -483,11 +449,9 @@ unsetOpt sets the specified cfgFlag to "off" within the receiver's
opt field.
*/
func (r *nodeConfig) unsetOpt(x cfgFlag) (err error) {
if err = r.valid(); err != nil {
return
if err = r.valid(); err == nil {
r.opt.unshift(x)
}

r.opt.unshift(x)
return
}

Expand All @@ -505,11 +469,9 @@ to its current value in terms of the input value. In other words, if the
state is "on" for a flag, it will be toggled to "off" and vice versa.
*/
func (r *nodeConfig) toggleOpt(x cfgFlag) (err error) {
if err = r.valid(); err != nil {
return
if err = r.valid(); err == nil {
r.opt.toggle(x)
}

r.opt.toggle(x)
return
}

Expand All @@ -535,18 +497,6 @@ func (r *stack) mutex() (*sync.Mutex, bool) {
return sc.mtx, sc.mtx != nil
}

func (r *nodeConfig) canWriteMessage() bool {
if err := r.valid(); err != nil {
return false
}

if r.log == nil {
r.log = newLogSystem(devNull)
}

return r.log.log != devNull
}

func init() {
cfgFlagMap = map[cfgFlag]string{
parens: `parenthetical`,
Expand Down

0 comments on commit d581824

Please sign in to comment.