utils

package
v0.0.0-...-8fd0174 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const Lverbose = 1 << 7

Verbose logging flag, only works with the utils.Logger verbose functions

View Source
const R_COURSE_CODE string = `[0-9v]{4}`

Course code, i.e. 2252. The first digit of a course code is the course level, the second digit is the # of credit hours.

View Source
const R_DATE_MDY string = `[A-z]+\s+[0-9]+,\s+[0-9]{4}`

Date in <MONTH DAY, YEAR> format, i.e. January 5, 2022

View Source
const R_GRADE string = `[ABCFabcf][+-]?`

Grade, i.e. C-

View Source
const R_SECTION_CODE string = `[0-9A-z]+`

Section code, i.e. 101

View Source
const R_SUBJECT string = `[A-Z]{2,4}`

Subject, i.e. HIST

View Source
const R_SUBJ_COURSE string = `[A-Z]{2,4}\s*[0-9V]{4}`

Subject + Course, uncaptured

View Source
const R_SUBJ_COURSE_CAP string = `([A-Z]{2,4})\s*([0-9V]{4})`

Subject + Course, captured

View Source
const R_TERM_CODE string = `[0-9]{2}[sufSUF]`

Term/Semester code, i.e. 22s

View Source
const R_TIME_AM_PM string = `[0-9]+:[0-9]+\s*(?:am|pm)`

Time in 12-hour AM/PM format, i.e. 5:22pm

View Source
const R_WEEKDAY string = `(?:Mon|Tues|Wednes|Thurs|Fri|Satur|Sun)day`

Day of week, i.e. Monday

View Source
const R_YEARS string = `(?:freshm[ae]n|sophomores?|juniors?|seniors?)`

Year statuses

Variables

This section is empty.

Functions

func GetAllFilesWithExtension

func GetAllFilesWithExtension(inDir string, extension string) []string

Recursively gets the filepath of every file with the given extension, using the given directory as the root.

func GetMapKeys

func GetMapKeys[M ~map[K]V, K comparable, V any](m M) []K

Gets all of the keys from a given map.

func GetMapValues

func GetMapValues[M ~map[K]V, K comparable, V any](m M) []V

Gets all of the values from a given map.

func Regexpf

func Regexpf(format string, vars ...interface{}) *regexp.Regexp

Creates a regexp with MustCompile() using a sprintf input.

func TrimWhitespace

func TrimWhitespace(text string) string

Removes standard whitespace characters (space, tab, newline, carriage return) from a given string.

func VPrint

func VPrint(text string)

Verbose-only variant of log.Print

func VPrintf

func VPrintf(format string, vars ...any)

Verbose-only variant of log.Printf

func VPrintln

func VPrintln(text string)

Verbose-only variant of log.Println

func WriteJSON

func WriteJSON(filepath string, data interface{}) error

Encodes and writes the given data as tab-indented JSON to the given filepath.

Types

type Logger

type Logger struct {
	log.Logger
}

Extension of log.Logger that supports a verbose logging flag; verbose printing functions start with 'V'

func NewLogger

func NewLogger(out io.Writer, prefix string, flag int) *Logger

func (*Logger) VPrint

func (logger *Logger) VPrint(text string)

Verbose-only variant of Logger.Print

func (*Logger) VPrintf

func (logger *Logger) VPrintf(format string, vars ...any)

Verbose-only variant of Logger.Printf

func (*Logger) VPrintln

func (logger *Logger) VPrintln(text string)

Verbose-only variant of Logger.Println

type SplitWriter

type SplitWriter struct {
	// contains filtered or unexported fields
}

Custom io.Writer for routing writing to multiple sub-writers

func NewSplitWriter

func NewSplitWriter(writers ...io.Writer) *SplitWriter

Constructor for utils.SplitWriter

func (*SplitWriter) Write

func (splitWriter *SplitWriter) Write(p []byte) (n int, err error)

Writes the specified bytes to every sub-writer of the SplitWriter

Jump to

Keyboard shortcuts

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