vdlutil

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 17, 2023 License: BSD-3-Clause Imports: 9 Imported by: 33

Documentation

Overview

Package vdlutil implements utilities used by many VDL components. It should have a small set of dependencies.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Vlog is a logger that discards output by default, and only outputs real
	// logs when SetVerbose is called.
	Vlog = log.New(io.Discard, logPrefix, logFlags)
)

Functions

func FirstRuneToExportCase

func FirstRuneToExportCase(s string, export bool) string

FirstRuneToExportCase returns s with its first rune in uppercase if export is true, otherwise in lowercase.

func FirstRuneToLower

func FirstRuneToLower(s string) string

FirstRuneToLower returns s with its first rune in lowercase.

func FirstRuneToUpper

func FirstRuneToUpper(s string) string

FirstRuneToUpper returns s with its first rune in uppercase.

func SetVerbose

func SetVerbose()

SetVerbose tells the vdl package (and subpackages) to enable verbose logging.

func ToConstCase

func ToConstCase(s string) string

toConstCase converts ThisString to THIS_STRING. For adding '_', we follow the following algorithm. For any sequence of three characters, c[n-1], c[n], c[n+1], we add an underscore before c[n] if:

  1. c[n-1] is a digit and c[n] is a letter, or
  2. c[n-1] is a letter and c[n] is a digit, or
  3. c[n-1] is lowercase, and c[n] is uppercase, or
  4. c[n-1] is uppercase, c[n] is uppercase, and c[n+1] is lowercase.

Types

type Errors

type Errors struct {
	MaxErrors int
	// contains filtered or unexported fields
}

Errors holds a buffer of encountered errors. The point is to try displaying all errors to the user rather than just the first. We cutoff at MaxErrors to ensure if something's really messed up we won't spew errors forever. Set MaxErrors=-1 to effectively continue despite any number of errors. The zero Errors struct stops at the first error encountered.

func NewErrors

func NewErrors(max int) *Errors

NewErrors returns a new Errors object, holding up to max errors.

func (*Errors) Error

func (e *Errors) Error(msg string) bool

Error adds the error described by msg to the buffer. Returns true iff we're still under the MaxErrors cutoff.

func (*Errors) Errorf

func (e *Errors) Errorf(format string, v ...interface{}) bool

Errorf is like Error, and takes the same args as fmt.Printf.

func (*Errors) IsEmpty

func (e *Errors) IsEmpty() bool

IsEmpty returns true iff there weren't any errors.

func (*Errors) IsFull

func (e *Errors) IsFull() bool

IsFull returns true iff we hit the MaxErrors cutoff.

func (*Errors) NumErrors

func (e *Errors) NumErrors() int

NumErrors returns the number of errors we've seen.

func (*Errors) Reset

func (e *Errors) Reset()

Reset clears the internal state so you start with no buffered errors. MaxErrors remains the same; if you want to change it you should create a new Errors struct.

func (*Errors) String

func (e *Errors) String() string

String returns the buffered errors as a single human-readable string.

func (*Errors) ToError

func (e *Errors) ToError() error

ToError returns the buffered errors as a single error, or nil if there weren't any errors.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL